logo image

Hasab

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

ParameterTypeRequiredDescription
messageStringYesThe text message to send to the AI.
modelStringNoModel to use: "hasab-1-lite" or "hasab-1-main".
temperatureNumberNoSampling temperature (0-2).
max_tokensNumberNoMaximum number of tokens to generate (1-1024).
streamBooleanNoWhether to stream partial responses.
toolsArrayNoArray of tool definitions.
imageFile (multipart/form-data)NoOptional 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:

ParameterTypeRequiredDescription
titleStringYesTitle of the item (max 255 characters).

Response:

{
  "message": "Chat title updated successfully"
}