AI Chat
Integrate chat functionality with Hasab AI APIs
Chat Endpoints
1. Chat Completion
Endpoint: POST /v1/chat
Description: Send a chat message and get AI response.
Request Body:
{
"message": "Hello, how are you?",
"model": "hasab-1-lite",
"temperature": 0.7,
"max_tokens": 2048,
"stream": false,
"tools": null
}Validation
| Parameter | Type | Required | Description |
|---|---|---|---|
message | String | Yes | The text message to send to the AI. |
model | String | No | Model to use: "hasab-1-lite" or "hasab-1-main". |
temperature | Number | No | Sampling temperature (0-2). |
max_tokens | Number | No | Maximum number of tokens to generate (1-1024). |
stream | Boolean | No | Whether to stream partial responses. |
tools | Array | No | Array of tool definitions. |
image | File (multipart/form-data) | No | Optional image file to include with the message. |
Response (Non-streaming):
{
"message": {
"role": "assistant",
"content": "I'm doing well, thank you!"
},
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}Response (Streaming): Server-sent events with partial responses.
2. Get Chat History
Endpoint: GET /v1/chat/history
Description: Retrieve user's chat conversation history.
Response:
{
"history": [
{
"id": 1,
"title": "General Chat",
"created_at": "2025-10-27T00:00:00Z",
"messages": [
{
"role": "user",
"content": "Hello",
"created_at": "2025-10-27T00:00:00Z"
},
{
"role": "assistant",
"content": "Hi there!",
"created_at": "2025-10-27T00:00:01Z"
}
]
}
]
}3. Clear Chat History
Endpoint: POST /v1/chat/clear
Description: Delete all chat history for the user.
Response:
{
"message": "Chat history cleared",
"deleted_records": 25
}4. Get Chat Title
Endpoint: GET /v1/chat/title
Description: Get the title of the current conversation.
Response:
{
"title": "General Chat"
}5. Update Chat Title
Endpoint: POST /v1/chat/title
Description: Update the title of the current conversation.
Request Body:
{
"title": "New Conversation Title"
}Validation:
| Parameter | Type | Required | Description |
|---|---|---|---|
title | String | Yes | Title of the item (max 255 characters). |
Response:
{
"message": "Chat title updated successfully"
}