Skip to main content
A
Docs

Chat API reference

Endpoints, request and response examples, the streaming format and errors of the Chat API: conversations, knowledge bases and search.

Authentication

Get a token with POST /api/v1/auth/login. Send it as Authorization: Bearer <token>. Read API conventions.

Endpoints

MethodPathPurposeRole
POST/api/v1/auth/loginSign in with a username and password. Returns a token.Any
POST/api/v1/auth/registerCreate an account. Works only when your administrator allows self-registration.Any
POST/api/v1/chat/completionsSend a message and stream the answerAny
GET/api/v1/chat/modelsList the models you can selectAny
GET/api/v1/chat/conversationsList your conversationsAny
GET/api/v1/chat/conversations/searchSearch your conversationsAny
GET/api/v1/chat/conversations/statsConversation statisticsAny
PATCH/api/v1/chat/conversations/{conversation_id}Rename a conversationAny
DELETE/api/v1/chat/conversations/{conversation_id}Delete a conversationAny
GET/api/v1/chat/conversations/{conversation_id}/exportExport a conversationAny
POST/api/v1/knowledge-basesCreate a knowledge baseadmin, manager
GET/api/v1/knowledge-basesList knowledge basesAny
POST/api/v1/documents/uploadUpload a document to a knowledge baseadmin, manager
GET/api/v1/documentsList documentsAny
GET/api/v1/documents/statsDocument statisticsAny
DELETE/api/v1/documents/{document_id}Delete a documentadmin, manager
POST/api/v1/rag/ingestAdd text chunks to a knowledge baseadmin, manager
POST/api/v1/rag/querySearch a knowledge base and return the best passagesAny
GET/api/v1/healthHealth checkNone

Send a message

curl -N https://chat.example.gov/api/v1/chat/completions \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "ما هي شروط تجديد الرخصة التجارية؟",
    "knowledge_base_id": "kb_licensing"
  }'
FieldTypeRequiredMeaning
messagestringYesThe question. Up to 100,000 characters.
conversation_idstringNoContinue this conversation. Leave it out to start a new one.
knowledge_base_idstringNoAnswer from this knowledge base
modelstringNoOne of the names from GET /api/v1/chat/models

Response stream

The response is a stream of server-sent events. Each event carries part of the answer:

data: {"token": "يجب", "conversation_id": "3f2c..."}

data: {"token": " تقديم", "conversation_id": "3f2c..."}

data: {"done": true, "conversation_id": "3f2c..."}

Join the token values to get the answer. Keep the conversation_id to continue the conversation.

Search a knowledge base

curl https://chat.example.gov/api/v1/rag/query \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "licence renewal fees", "knowledge_base_id": "kb_licensing", "top_k": 5}'
FieldTypeRequiredMeaning
querystringYesThe search text
knowledge_base_idstringYesThe knowledge base to search
top_kintegerNoNumber of passages to return, 1 to 100. The default is 5.
min_scorenumberNoLeave out passages with a lower score, 0 to 1

Errors

StatusCause
400The model name is not one that Chat allows, or no knowledge base was given to a search
403Your role cannot upload or delete documents, or self-registration is off
404The conversation, knowledge base or document does not exist in your tenant