RAG API
Please refer to the Quick Start Guide to obtain your API key.
Replace $YOUR_API_KEY
with the actual API key you generated in the previous step.
Our platform enforces data isolation based on API keys. Even under the same user account, data accessed through different API keys (tokens) is completely independent and not shared between them.
Document Management Interface
Method | Route | Function Description | API Interface |
---|---|---|---|
POST | /documents/upload |
Processes document upload requests, including file saving, text chunking, and data persistence | https://api-platform.ope.ai/documents/upload |
GET | /documents/documents |
Gets a list of all documents, including document ID, filename, upload time, number of chunks, etc., with query results sorted by upload time in descending order | https://api-platform.ope.ai/documents/documents |
DELETE | /documents/documents |
Deletes specified documents and related resources, including: physical file deletion, Milvus vector data deletion, database record deletion, BM25 index deletion | https://api-platform.ope.ai/documents/documents |
GET | /documents/document_chunks |
Gets a list of all chunks for a specified document | https://api-platform.ope.ai/documents/document_chunks |
GET | /documents/download_document |
Downloads a specified document file | https://api-platform.ope.ai/documents/download_document |
Database Management Interface
Method | Route | Function Description | API Interface |
---|---|---|---|
POST | /database/collections |
Creates a user space collection. This interface is used to create a new Milvus Collection for the specified user to store vector data; returns error if creation fails or cannot connect to Milvus | https://api-platform.ope.ai/database/collections |
DELETE | /database/collections |
Deletes a user space collection. This interface is used to delete the specified user's Milvus Collection and all vector data stored within it | https://api-platform.ope.ai/database/collections |
Search Interface
Method | Route | Function Description | API Interface |
---|---|---|---|
POST | /search/chat_message |
RAG-based conversational search, processes RAG search requests Receives user questions and relevant parameters, uses RAG (Retrieval-Augmented Generation) method to generate answers. The entire process includes: - Document retrieval: Retrieving relevant documents from the knowledge base - Context integration: Combining retrieved documents with the question - Answer generation: Using a large language model to generate responses - Streaming response: Real-time return of generated content |
https://api-platform.ope.ai/search/chat_message |
Session Management Interface
Method | Route | Function Description | API Interface |
---|---|---|---|
POST | /session_manage/delete |
Deletes a specified user session, i.e., this interface is used to manually specify a user's specific session and all related chat history | https://api-platform.ope.ai/session_manage/delete |
API Request Examples
/documents/upload
POST Upload Document
curl --location --request POST 'https://api-platform.ope.ai/documents/upload' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Accept: */*' \
--header 'Host: api-platform.ope.ai' \
--header 'Connection: keep-alive' \
--header 'Content-Type: multipart/form-data; boundary=------------------------897026663741264421313454' \
--form 'files=@"/Users/ten/Documents/test.txt"' \ # Supported file types: .txt, .pdf, .csv, .md, .docx
--form 'model="opeai/bge-m3"' # Embedding model name
--form 'chunk_size=500' # Document chunking token length
--form 'chunk_overlap=50' # Document chunking overlap length
--form 'separators=!' # Document chunking separator, defaults to \n\n if not specified
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Accept': '*/*',
}
files = {
'files': open('/Users/ten/Documents/test.txt', 'rb'), # Supported file types: .txt, .pdf, .csv, .md, .docx
'model': (None, 'opeai/bge-m3'), # Embedding model name
'chunk_size': (None, '500'), # Document chunking token length
'chunk_overlap': (None, '50'), # Document chunking overlap length
'separators': (None, '!'), # Document chunking separator, defaults to \n\n if not specified
}
response = requests.post('https://api-platform.ope.ai/documents/upload', headers=headers, files=files)
for line in response.iter_lines():
if line:
decoded = line.decode('utf-8')
print(decoded)
/documents/document_chunks
GET Retrieve Chunk List of a Specific Document
curl --location --request GET 'https://api-platform.ope.ai/documents/document_chunks?doc_id=14ba616e-2214-412e-8d3e-9164970de543' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Accept: */*' \
--header 'Host': 'api-platform.ope.ai' \
--header 'Connection: keep-alive'
# doc_id is returned from /documents/documents
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
params = {
'doc_id': '14ba616e-2214-412e-8d3e-9164970de543', # doc_id is returned from /documents/documents
}
response = requests.get('https://api-platform.ope.ai/documents/document_chunks', params=params, headers=headers)
print(response.json())
/documents/download_document
GET Download Document
curl --location --request GET 'https://api-platform.ope.ai/documents/download_document?doc_file_path=storage/docs/158/14ba616e-2214-412e-8d3e-9164970de543_test.txt&filename=test.txt' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Accept: */*' \
--header 'Host: api-platform.ope.ai' \
--header 'Connection: keep-alive'
# filename is the name used to save the file locally
# doc_file_path is returned from /documents/documents
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
params = {
'doc_file_path': 'storage/docs/158/14ba616e-2214-412e-8d3e-9164970de543_test.txt', # doc_file_path is returned from /documents/documents
'filename': 'test.txt' # filename is the name used to save the file locally
}
response = requests.get(
'https://api-platform.ope.ai/documents/download_document',
headers=headers,
params=params
)
with open(params['filename'], 'wb') as f:
f.write(response.content)
/database/collections
POST Create Knowledge Base for the User
curl --location --request POST 'https://api-platform.ope.ai/database/collections' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api-platform.ope.ai' \
--header 'Connection: keep-alive' \
--data-raw ''
# Use this first to create the user's knowledge base
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
response = requests.post('https://api-platform.ope.ai/database/collections', headers=headers)
print(response.json())
# Use this first to create the user's knowledge base
DELETE Delete User Knowledge Base
curl --location --request DELETE 'https://api-platform.ope.ai/database/collections' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api-platform.ope.ai' \
--header 'Connection: keep-alive' \
--data-raw ''
# Deletes the user's knowledge base
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
response = requests.delete('https://api-platform.ope.ai/database/collections', headers=headers)
print(response.json())
# Deletes the user's knowledge base
/search/chat_message
POST Process RAG Search Request
curl --location --request POST 'https://api-platform.ope.ai/search/chat_message' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api-platform.ope.ai' \
--header 'Connection: keep-alive' \
--data-raw '{
"embedding_model_name": "opeai/bge-m3", # Embedding model
"llm_model_name": "opeai/deepseek-v3", # Large language model
"question": "什么是RAG?", # User question
"session_id": "session_1", # Session ID; leave empty to create a new session. The API will return a new session ID. Use this ID in subsequent requests to maintain history.
"top_k": 5, # Number of most relevant documents to return from the knowledge base
"stream": false # Defaults to true
}'
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
payload = {
'embedding_model_name': 'opeai/bge-m3', # Embedding model
'llm_model_name': 'opeai/deepseek-v3', # Large language model
'question': '什么是RAG?', # User question
'session_id': 'session_1', # Session ID; leave empty to create a new session. The API will return a new session ID. Use this ID in subsequent requests to maintain history.
'top_k': 5, # Number of most relevant documents to return from the knowledge base
'stream': False, # Defaults to true
}
response = requests.post('https://api-platform.ope.ai/search/chat_message', headers=headers, json=payload)
print(response.json())
/session_manage/delete
DELETE Delete Session by Tenant
curl --location --request POST 'https://api-platform.ope.ai/session_manage/delete' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api-platform.ope.ai' \
--header 'Connection: keep-alive' \
--data-raw '{
"session_id": "session_1" # Session ID returned by chat_message
}'
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
payload = {
'session_id': 'session_1', # Session ID returned by chat_message
}
response = requests.post('https://api-platform.ope.ai/session_manage/delete', headers=headers, json=payload)
print(response.json())
/documents/documents
DELETE Delete Specific Document
curl --location --request DELETE 'https://api-platform.ope.ai/documents/documents' \
--header 'Authorization: Bearer $YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api-platform.ope.ai' \
--header 'Connection: keep-alive' \
--data-raw '{
"doc_id": "123" # Can be obtained from documents/documents
}'
# Delete user document
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
payload = {
'doc_id': '123', # Can be obtained from documents/documents
}
response = requests.delete('https://api-platform.ope.ai/documents/documents', headers=headers, json=payload)
print(response.json())
# Delete user document
GET List All Documents
import requests
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Accept-Language': 'zh-cn',
'Accept': '*/*',
'Host': 'api-platform.ope.ai',
'Connection': 'keep-alive',
}
response = requests.get('https://api-platform.ope.ai/documents/documents', headers=headers)
print(response.json())
# Get document list
API Request Errors
Common errors that may occur during API calls:
404 Not Found
The API path is incorrect or does not exist.
Solution: Verify the endpoint URL. If correct but the issue persists, contact the platform administrator.
422 Parameter Error
The client request does not meet API requirements (e.g., missing fields, format issues, typo in field names).
Solution: Check the request body structure and ensure all required fields are present and correctly formatted.
500 Internal Server Error
The server encountered an unexpected condition (e.g., system crash, DB or vector engine connection failure).
Solution: Try again later. If the problem occurs repeatedly, contact the platform administrator.