Overview
The Text Chat API enables developers to integrate TalkifAI text agents into websites, mobile apps, and other applications using REST + Server-Sent Events (SSE) streaming. Base URL:https://api.talkifai.dev/v1/chat
Authentication:
- Session Creation:
X-API-KeyorX-Studio-Tokenheader - All Other Requests:
Authorization: Bearer {session_token}(JWT)
Endpoints
Create Session
POST /sessions — Create a new chat sessionSend Message
POST /sessions/{id}/messages — Send message (SSE stream)Get History
GET /sessions/{id}/messages — Retrieve message historyEnd Session
POST /sessions/{id}/end — End session and cleanupCreate Voice Session
POST /voice-sessions — Create LiveKit voice sessionAuthentication
Session Creation (Server-Side)
Two authentication methods supported: Method 1: API KeyAll Other Requests (Client-Side)
/sessions endpoint, valid for 24 hours.
Request/Response Models
CreateSessionRequest
CreateSessionResponse
SendMessageRequest
Message
MessagesResponse
EndSessionResponse
SSE Event Types
When sending messages, the response is streamed via Server-Sent Events:| Event | Data | Description |
|---|---|---|
stream_start | {"agent_name": "..."} | Agent started generating |
chunk | {"delta": "text..."} | Incremental text delta |
tool_call | {"name": "...", "status": "executing"} | Tool execution started |
tool_result | {"name": "...", "status": "completed"} | Tool execution finished |
handoff | {"to": "agent_name"} | Multi-agent handoff |
stream_end | {"usage": {...}, "end_session": bool} | Response complete |
error | {"error": "message"} | Error occurred |
Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | message_too_long | Message exceeds 10,000 characters |
| 400 | not_text_agent | Agent is not text architecture |
| 401 | invalid_api_key | API key missing or invalid |
| 401 | invalid_token | JWT token expired or invalid |
| 402 | insufficient_credits | Organization has no credits |
| 403 | conversation_mismatch | Conversation ID doesn’t match token |
| 404 | session_not_found | Session expired or not found |
| 503 | — | Billing service unavailable |
Session Lifecycle
Related Documentation
- Chat API Guide — Complete integration guide with examples
- Custom Functions — Add API integrations
- Conversation Memory — Enable long-term memory
- Agent Architectures — Text vs Voice agents
SDK Support
Official SDKs:- JavaScript/TypeScript (coming soon)
- Python (coming soon)
- React Hook (see guide)
- Check npm and PyPI for community-maintained packages
Rate Limits
| Endpoint | Limit |
|---|---|
| Create Session | 100/minute per API key |
| Send Message | 60/minute per session |
| Get History | 100/minute per session |
| End Session | 60/minute per session |
CORS
Allowed Origins:- All origins allowed (
*) - Configure in your API key settings
GET,POST,OPTIONS
Content-TypeAuthorizationX-API-KeyX-Studio-TokenOrigin
Webhooks
When a chat session ends, a webhook is sent if configured on the agent:Next Steps
Create Session
Start with POST /sessions to create your first chat session.
Integration Guide
See the complete guide with React/Next.js examples.