Chat, Vision & Conversations
Detailed reference for POST /chat text and multimodal image input, SSE streaming and Nginx proxy setup, run cancellation, and conversation history endpoints.
Send a Chat Turn POST /api/partner/v1/chat
Include Authorization: Bearer <API_KEY> and Content-Type: application/json. Body size ceiling is 64 KB for text-only payloads and 24 MB when images are included.
Request Body (JSON, strict)
| Field | Type | Required | Description |
|---|---|---|---|
user_id | string | Yes | 1-128 chars, stable anonymous user identifier |
message | string | Conditional | 0-8,000 trimmed chars; provide message, images, or both |
images | ImageInput[] | Conditional | 1-3 inline images; provide message, images, or both |
conversation_id | string (UUID) | No | Pass to continue an existing conversation; omit to create one |
request_id | string | No | Idempotency key (1-100 chars, ^[A-Za-z0-9_-]+$) |
stream | boolean | No | Default true (SSE stream); false returns one JSON payload |
Multimodal images[] Input Rules
To prevent broken external URLs and SSRF risks, only inline Base64 or Data URIs are accepted (no remote image URL fetching):
| Field | Type | Required | Description |
|---|---|---|---|
data | string | Yes | Raw Base64 string or data:image/<type>;base64,... Data URI |
media_type | string | No | Optional declaration: image/png, image/jpeg, image/webp, image/gif, image/avif (verified via magic bytes) |
filename | string | No | Original filename (1-160 chars) |
- Decoded limits: <= 5 MB per image, <= 15 MB combined across up to 3 images.
- Unsupported formats return
415 IMAGE_FORMAT, invalid encoding or MIME mismatches return422 INVALID_IMAGE, oversized payloads return413 IMAGE_TOO_LARGE, and missing vision model configuration returns400 VISION_UNAVAILABLE.
Synchronous Success Response (stream: false, HTTP 200)
{
"conversation_id": "7d0c4e1a-5b32-4c9a-9f12-8a7e3d4c2b10",
"run_id": "a3f19b20-1c4d-4e8a-8b11-2f6c9a4d0e77",
"request_id": "req-20261202-0001",
"status": "completed",
"text": "As of 2026-12-02 12:30 (UTC+8), BTC is trading near $95,420 (24h +2.15%).",
"suggestions": [
"Compare BTC and ETH performance over the past 7 days",
"What macro events are driving BTC this week?"
],
"usage": {
"input_tokens": 5321,
"cached_tokens": 4096,
"output_tokens": 612,
"tool_calls": 3,
"web_searches": 1
}
}SSE Streaming Protocol & Proxy Settings
Streaming responses use Content-Type: text/event-stream; charset=utf-8 with : ping heartbeat comments every 15 seconds:
Success: meta ──▶ delta (0..N) ──▶ done
Failure: meta ──▶ delta (0..N) ──▶ error| Event | Payload | Client Handling |
|---|---|---|
meta | conversation_id, run_id, request_id | First event; store conversation and run IDs |
delta | text | Append and re-render full Markdown; unclosed links are briefly buffered |
done | Same shape as sync 200 | Atomically replace accumulated text with done.text before persisting, then render suggestions |
error | Flat JSON: code, message, text, etc. | No outer {"error":...} wrapper; preserve partial text and handle by code |
Proxy & Disconnect Notes
- No resume via
Last-Event-ID:id:is for troubleshooting only; dropping the connection cancels the active turn. - Node.js 18+ / Express abort handling:
req.on("close")fires as soon as the request body finishes reading. Never abort upstream onreq.on("close"); bindres.on("close", () => { if (!res.writableEnded) controller.abort(); })instead. - Disable proxy buffering: Configure Nginx proxies with
proxy_buffering off;,gzip off;,client_max_body_size 30m;, andproxy_read_timeout 660s;.
Cancel an Active Run POST /api/partner/v1/chat/{run_id}/cancel
- Path parameter:
run_id(UUID frommeta). - Request body:
{}; Response (HTTP200):{"ok":true}(idempotent for already finished runs; returns404 RUN_NOT_FOUNDif missing or cross-tenant). - Closing an active SSE connection also stops generation immediately.
Conversation Management
Pre-create a Conversation POST /api/partner/v1/conversations
- Body:
{"user_id":"u_anon_9f2c1a8b"} - Response (HTTP
201):{"conversation_id":"7d0c4e1a-5b32-4c9a-9f12-8a7e3d4c2b10"}
List Conversations GET /api/partner/v1/conversations
Query params: user_id (required), limit (optional, 1-100, default 50), archived (optional, "true" or "false", default "false"). Unknown user_id values return an empty array without creating user state.
{
"conversations": [
{
"conversation_id": "7d0c4e1a-5b32-4c9a-9f12-8a7e3d4c2b10",
"title": "What is the latest BTC price?",
"archived": false,
"message_count": 4,
"updated_at": "2026-12-02T04:30:12.000Z"
}
]
}Fetch Conversation Messages GET /api/partner/v1/conversations/{conversation_id}/messages
Query params: user_id (required), limit (optional, 1-100, default 100, latest N messages in chronological order). Missing or cross-user IDs return 404 CONVERSATION_NOT_FOUND.
{
"conversation_id": "7d0c4e1a-5b32-4c9a-9f12-8a7e3d4c2b10",
"title": "What is the latest BTC price?",
"archived": false,
"active_run_id": null,
"messages": [
{ "id": "msg-u-1", "role": "user", "text": "Analyze this chart", "image_count": 1 },
{ "id": "msg-a-1", "role": "assistant", "text": "Key support levels appear near...", "suggestions": ["Inspect recent volume trends"] }
]
}Delete a Conversation DELETE /api/partner/v1/conversations/{conversation_id}
Accepts query ?user_id=<user_id> (recommended) or JSON body {"user_id":"<user_id>"}. Returns 200 {"ok":true,"conversation_id":"..."}; returns 409 RUN_ACTIVE if a run is currently executing.