{"openapi":"3.1.0","info":{"title":"Tala Chat API","version":"1.0.0","description":"Widget-embedded chat backend: a streaming SSE chat turn, a synchronous JSON chat turn, feedback capture, and public widget config delivery.","contact":{"name":"Tala Support","email":"support@tala.ai"},"license":{"name":"Proprietary"}},"paths":{"/chat":{"post":{"summary":"Streaming chat turn (SSE)","description":"Runs one chat turn (retrieval + generation) and streams the result as Server-Sent Events. Events, in emission order: `meta` (once, near the start) `{messageId, sessionId}`; zero or more `delta` events whose `data` is the raw answer text as it is produced — NOT JSON, do not `JSON.parse` it, concatenate the `data` values verbatim to reassemble the answer; then exactly one terminal event, either `done` `{messageId, sources}` on success or `error` `{message}` on a pipeline failure. There is deliberately no `replace` event — earlier client versions that expected one to swap in a corrected answer will not receive it. The HTTP status is always 200 once the stream has started (a mid-stream failure surfaces as an `error` event, not an HTTP error status); pre-stream failures (auth, bad body, D1 unavailable) return a plain JSON error response before any SSE bytes are written.","security":[{"EmbedKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["query"],"properties":{"query":{"type":"string","maxLength":2000,"description":"The user's message. Required, non-empty after trimming, at most 2000 characters."},"sessionId":{"type":"string","pattern":"^[a-zA-Z0-9_-]{1,128}$","description":"Optional session/conversation id to continue a prior turn. Omit on the first turn; a fresh id is generated server-side when absent or invalid. Note: `conversation_id` is NOT accepted as an alias on this route (that alias exists only on POST /chat/answer)."}}}}}},"responses":{"200":{"description":"Server-Sent Events stream. See the operation description for the event sequence and payload shapes.","content":{"text/event-stream":{"schema":{"type":"string","description":"A sequence of Server-Sent Events. Each event is prefixed with `event:` and `data:` fields followed by a blank line."},"examples":{"meta":{"summary":"meta event — emitted once, near the start of the turn","value":"event: meta\ndata: {\"messageId\":\"m_abc123\",\"sessionId\":\"s_abc123\"}\n\n"},"delta":{"summary":"delta event — raw answer text, NOT JSON; concatenate data verbatim","value":"event: delta\ndata: Based on\n\n"},"done":{"summary":"done event — terminal, success","value":"event: done\ndata: {\"messageId\":\"m_abc123\",\"sources\":[{\"url\":\"https://example.com/page\",\"title\":\"Example Page\"}]}\n\n"},"error":{"summary":"error event — terminal, pipeline failure mid-stream","value":"event: error\ndata: {\"message\":\"Internal error\"}\n\n"}}}}},"400":{"description":"Bad request — the body could not be parsed as JSON, or `query` is missing/empty/too long.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","enum":["invalid_json","invalid_query"]}}}}}},"401":{"description":"Unauthorized — missing/invalid X-Embed-Key header, or a disallowed/absent Origin. All auth failures return 401, never 403 (unlike search-api).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}},"503":{"description":"Service unavailable — a pre-stream D1 lookup failed (widget config or enabled-sources list).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","enum":["db_unavailable"]},"message":{"type":"string","description":"Raw driver error string."}}}}}}}}},"/chat/answer":{"post":{"summary":"Synchronous JSON chat turn","description":"Runs the identical retrieval/generation pipeline as `POST /chat` — same auth, same D1 config, same behavior — but buffers the whole turn and returns one flat JSON object instead of an SSE stream. A turn that completes normally but finds no relevant context is NOT an error: it returns 200 with a fallback answer as `summary` and `sources: []`.","security":[{"EmbedKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["query"],"properties":{"query":{"type":"string","maxLength":2000,"description":"The user's message. Required, non-empty after trimming, at most 2000 characters."},"sessionId":{"type":"string","pattern":"^[a-zA-Z0-9_-]{1,128}$","description":"Optional session/conversation id to continue a prior turn. If both `sessionId` and `conversation_id` are present, `sessionId` wins."},"conversation_id":{"type":"string","pattern":"^[a-zA-Z0-9_-]{1,128}$","description":"Alias for `sessionId`, accepted ONLY on this endpoint (not on POST /chat) so request/response field names can match. Ignored if `sessionId` is also present."}}}}}},"responses":{"200":{"description":"The completed turn. The body has EXACTLY these three keys — no `results`, `page`, `turn`, `has_more`, or token/latency fields (those are /ai-search-only).","content":{"application/json":{"schema":{"type":"object","required":["conversation_id","summary","sources"],"properties":{"conversation_id":{"type":"string","description":"The session id the turn actually used. Echo this back as `sessionId` or `conversation_id` on the next request to continue the conversation."},"summary":{"type":"string","description":"The complete answer text — no streaming, citation markup left as-is (not stripped)."},"sources":{"type":"array","description":"Deduplicated citation sources referenced in the summary. Empty on a no-context fallback turn.","items":{"$ref":"#/components/schemas/Source"}}}}}}},"400":{"description":"Bad request — the body could not be parsed as JSON, or `query` is missing/empty/too long.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","enum":["invalid_json","invalid_query"]}}}}}},"401":{"description":"Unauthorized — missing/invalid X-Embed-Key header, or a disallowed/absent Origin. All auth failures return 401, never 403 (unlike search-api).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}},"500":{"description":"An unexpected pipeline failure.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","enum":["internal_error"]}}}}}},"503":{"description":"Service unavailable. `db_unavailable` — a pre-turn D1 lookup failed (widget config or enabled-sources list); `retrieval_unavailable` — the Qdrant retrieval step failed (a genuine infrastructure error, distinct from a turn that legitimately found no relevant context, which is a 200).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","enum":["db_unavailable","retrieval_unavailable"]},"message":{"type":"string","description":"Raw driver error string. Present only for db_unavailable."}}}}}}}}},"/feedback":{"post":{"summary":"Record or clear a thumbs rating for a chat message","description":"Sets or clears the feedback rating for one `(sessionId, messageId)` pair. Passing `rating: null` clears any existing rating for that pair. Best-effort also updates the aggregate thumbs-up/down counters on the corresponding chat session row; a failure there does not fail the request, since the feedback event itself has already been written.","security":[{"EmbedKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["sessionId","messageId"],"properties":{"sessionId":{"type":"string","description":"The session id the message belongs to."},"messageId":{"type":"string","description":"The id of the message being rated (the `messageId` from a `meta`/`done` SSE event or a /chat/answer response's turn)."},"rating":{"type":["string","null"],"enum":["up","down",null],"description":"The rating to set, or null to clear an existing rating."}}}}}},"responses":{"201":{"description":"Rating recorded (or cleared).","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]}}}}}},"400":{"description":"Bad request — `sessionId`/`messageId` missing, or `rating` is not `'up'`, `'down'`, or `null`.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}},"401":{"description":"Unauthorized — missing/invalid X-Embed-Key header, or a disallowed/absent Origin.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}},"/config":{"get":{"summary":"Public widget configuration","description":"Returns the widget's display configuration (branding, fonts, starter questions, terms/privacy content, etc.) for the caller's embed key. Called by the widget on mount. Unlike `/chat`, `/chat/answer`, and `/feedback`, this endpoint validates ONLY the embed key header — it does NOT check the request's Origin against the domain allowlist, since it may legitimately be called from contexts where Origin is absent (e.g. a `data:` URI host page).","security":[{"EmbedKey":[]}],"responses":{"200":{"description":"Widget configuration.","content":{"application/json":{"schema":{"type":"object","properties":{"chatbotName":{"type":"string"},"avatarUrl":{"type":["string","null"]},"launcherIcon":{"type":["string","null"]},"fallbackMessage":{"type":"string"},"defaultMessage":{"type":"string"},"starterQuestions":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string"},"iconUrl":{"type":["string","null"]}}}},"brandColor":{"type":"string"},"secondaryColor":{"type":"string"},"fontSizeBase":{"type":"string"},"fontFamily":{"type":"string"},"customFontId":{"type":["string","null"]},"customFont":{"type":["object","null"]},"tncContent":{"type":"string"},"tncVersionHash":{"type":"string"},"dataPrivacyContent":{"type":"string"},"dpnVersionHash":{"type":"string"},"sessionTimeoutMinutes":{"type":["integer","null"]}}}}}},"401":{"description":"Unauthorized — missing or invalid X-Embed-Key header.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","enum":["missing_key","invalid_key"]}}}}}}}}},"/health":{"get":{"summary":"Liveness check","description":"Unauthenticated liveness probe.","security":[],"responses":{"200":{"description":"The worker is up.","content":{"application/json":{"schema":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]},"worker":{"type":"string","enum":["chat-api"]}}}}}}}}}},"components":{"schemas":{"Source":{"type":"object","description":"A citation source referenced in an answer. Has no `id` field — unlike search-api's published (and stale) Source schema, this reflects the true runtime shape.","properties":{"url":{"type":"string","description":"Source URL."},"title":{"type":"string","description":"Source page title."}}}},"securitySchemes":{"EmbedKey":{"type":"apiKey","in":"header","name":"X-Embed-Key","description":"Per-client embed key issued by the Tala dashboard. On POST /chat, POST /chat/answer and POST /feedback, requests are additionally validated against a per-embed-key domain allowlist using the request's Origin header — the caller's domain must be added to the allowlist in the Tala dashboard. Browsers send Origin automatically; server-to-server callers must set an allowlisted Origin header explicitly. Auth failures on those three routes always return 401 (never 403 — unlike search-api). GET /config validates only this header, not Origin."}}},"security":[{"EmbedKey":[]}],"servers":[{"url":"https://api.playground-preview.talabot.app","description":"This deployment's base URL"}]}