Skip to main content
The Chat Service provides comprehensive endpoints for creating and managing conversational AI interactions. It supports multi-turn dialogues with LLM models and AI agents, file uploads, knowledge base integration, real-time streaming, and audio transcription.

Chat System Overview

Authentication

All endpoints require a valid Bearer token in the Authorization header and appropriate RBAC permissions. Required Permissions:
  • chats:read - Read chat sessions and messages
  • chats:write - Create chats and send messages
  • chats:delete - Delete chat sessions

Base URL

Chat Session Management

Create Chat Session

Create a new chat session for organizing conversations.
Endpoint: POST /api/chat Query Parameters: Request Body:

Get Chat Session

Retrieve a single chat session with all its messages and file uploads.
Endpoint: GET /api/chat Query Parameters:

List Chat Sessions

Retrieve all chat sessions for the authenticated user.
Endpoint: GET /api/chat/list Query Parameters:

Update Chat Session

Update an existing chat session’s title, status, or settings.
Endpoint: PUT /api/chat Query Parameters: Request Body:

Delete Chat Session

Delete a single chat session and all its messages.
Endpoint: DELETE /api/chat/delete_session Query Parameters:

Bulk Delete Chat Sessions

Delete multiple chat sessions in a single request.
Endpoint: POST /api/chat/bulk_delete_sessions Request Body:

Message Operations

Send Message

Send a message in a chat session and receive a streaming AI response. This is the primary endpoint for conversational interactions.
Endpoint: POST /api/chat/send_message Query Parameters: Request Body: Response Format: Server-Sent Events (SSE) stream with the following data formats: Features:
  • Auto-Chat Creation: Creates new chat if chat_id not provided
  • Auto-Title Generation: Generates meaningful title for new chats
  • Knowledge Base Search: Searches specified KBs and enhances prompt
  • File Content Extraction: Extracts text from uploaded files
  • Billing Integration: Tracks token usage and credits
  • WebSocket Broadcasting: Broadcasts title updates
  • Firebase Sync: Syncs chat updates to Firebase
  • Model Feature Detection: Automatically handles text/image/video generation
  • Error Recovery: Gracefully handles LLM provider errors

File Upload Operations

Upload File

Upload a file to be attached to chat messages.
Endpoint: POST /api/chat/upload_file Query Parameters: Request Body: Multipart form data with file field. Response: Supported File Types:
  • Documents: PDF, TXT, DOCX, XLSX, CSV, MD
  • Images: JPG, PNG, GIF, WebP, SVG
  • Audio: MP3, WAV, M4A, OGG, FLAC
  • Video: MP4, WebM, MOV, AVI
Storage:
  • Files stored in GCP Cloud Storage
  • Organized by: {org_id}/{chat_id}/{filename}
  • Presigned URLs expire in 7 days
  • Content extraction for compatible formats

Audio Operations

Transcribe Audio

Convert audio files or raw audio data to text.
Endpoint: POST /api/chat/transcribe Query Parameters: Request Body: Multipart form data with file field, OR raw bytes with content_type parameter. Supported Languages:
  • en-US - English (US)
  • en-GB - English (UK)
  • es-ES - Spanish
  • fr-FR - French
  • de-DE - German
  • it-IT - Italian
  • pt-BR - Portuguese (Brazil)
  • ja-JP - Japanese
  • ko-KR - Korean
  • zh-CN - Chinese (Simplified)
Supported Audio Formats:
  • MP3
  • WAV
  • M4A
  • OGG
  • FLAC
  • WebM

Prompt Operations

Generate Prompts

Generate AI-powered prompts based on input text with streaming response.
Endpoint: POST /api/chat/prompt Request Body: Response: Server-Sent Events stream with format:

Knowledge Base Operations

Get Available Knowledge Bases

Retrieve knowledge bases available for chat integration.
Endpoint: GET /api/chat/available_knowledge_bases Query Parameters:

Error Responses

Error Response Format:
Common Error Messages:

Implementation Notes

Streaming Response Handling

All streaming endpoints use Server-Sent Events (SSE) format:

Billing Integration

Every chat interaction is billed:
  1. HOLD created at message start (qty=1)
  2. Tokens counted during generation
  3. DEBIT finalized with actual token usage
  4. Usage metadata updated in chat session
Token Calculation:

File Content Extraction

Files are automatically processed:
  • Text files: Content extracted and appended to prompt
  • Images: Passed to vision-capable models
  • Documents: Text extraction for PDF, DOCX, etc.
  • DeepSeek models: Special handling for file content

Knowledge Base Integration

KB search happens automatically:
  1. Semantic search on user query
  2. Top N chunks retrieved (configurable, default: 10)
  3. Context injected into prompt
  4. LLM generates KB-aware response
Search Parameters:
  • limit: Number of chunks (default: 10)
  • score_threshold: Minimum similarity (default: 0.1)

Auto-Title Generation

For new chats:
  1. Wait for first AI response
  2. Generate title using LLM
  3. Update database
  4. Broadcast via WebSocket
  5. Sync to Firebase

Model Feature Detection

System automatically detects model capabilities:
  • Text models: Standard chat
  • Image models: Image generation with progress
  • Video models: Video generation with GCP upload
  • Vision models: Image analysis

Agent Integration

When using agents:
  1. Agent must be active
  2. Request sent to agent runtime
  3. Response streamed back
  4. Token usage tracked from Agno session

Rate Limiting

Rate limits enforced via feature flags:
  • daily_chat_limit: Daily message limit
  • file_upload: File upload quota
  • chat_uploads: Chat-specific upload quota

Next Steps

Explore related APIs and features: Ready to start building? Check out our Chat Concepts guide or Getting Started tutorial.