Authentication
Get a token with POST /api/v1/auth/login. Send it as Authorization: Bearer <token>. Read API conventions.
Endpoints
| Method | Path | Purpose | Role |
|---|---|---|---|
| POST | /api/v1/auth/login | Sign in with a username and password. Returns a token. | Any |
| POST | /api/v1/auth/register | Create an account. Works only when your administrator allows self-registration. | Any |
| POST | /api/v1/chat/completions | Send a message and stream the answer | Any |
| GET | /api/v1/chat/models | List the models you can select | Any |
| GET | /api/v1/chat/conversations | List your conversations | Any |
| GET | /api/v1/chat/conversations/search | Search your conversations | Any |
| GET | /api/v1/chat/conversations/stats | Conversation statistics | Any |
| PATCH | /api/v1/chat/conversations/{conversation_id} | Rename a conversation | Any |
| DELETE | /api/v1/chat/conversations/{conversation_id} | Delete a conversation | Any |
| GET | /api/v1/chat/conversations/{conversation_id}/export | Export a conversation | Any |
| POST | /api/v1/knowledge-bases | Create a knowledge base | admin, manager |
| GET | /api/v1/knowledge-bases | List knowledge bases | Any |
| POST | /api/v1/documents/upload | Upload a document to a knowledge base | admin, manager |
| GET | /api/v1/documents | List documents | Any |
| GET | /api/v1/documents/stats | Document statistics | Any |
| DELETE | /api/v1/documents/{document_id} | Delete a document | admin, manager |
| POST | /api/v1/rag/ingest | Add text chunks to a knowledge base | admin, manager |
| POST | /api/v1/rag/query | Search a knowledge base and return the best passages | Any |
| GET | /api/v1/health | Health check | None |
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"
}'
| Field | Type | Required | Meaning |
|---|---|---|---|
message | string | Yes | The question. Up to 100,000 characters. |
conversation_id | string | No | Continue this conversation. Leave it out to start a new one. |
knowledge_base_id | string | No | Answer from this knowledge base |
model | string | No | One 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}'
| Field | Type | Required | Meaning |
|---|---|---|---|
query | string | Yes | The search text |
knowledge_base_id | string | Yes | The knowledge base to search |
top_k | integer | No | Number of passages to return, 1 to 100. The default is 5. |
min_score | number | No | Leave out passages with a lower score, 0 to 1 |
Errors
| Status | Cause |
|---|---|
| 400 | The model name is not one that Chat allows, or no knowledge base was given to a search |
| 403 | Your role cannot upload or delete documents, or self-registration is off |
| 404 | The conversation, knowledge base or document does not exist in your tenant |