Assistant APIAssistant API Reference

Assistant API Reference

Endpoints, request and response fields, stream events and error codes of the Assistant API.

Overview

The Assistant API answers questions from your documentation. To create keys and connect tools, see Assistant API.

https://api.documentation.ai/api/v1/assistant

Requests and responses are JSON. Field names, event names and error codes don't change between releases.

Authentication

Send a key in the Authorization header: Authorization: Bearer <key>.

KeyStarts withUsed fromReads
Secret keyasst_sk_Servers and tools. Refused when the request comes from a web page.What the key allows
Publishable keyasst_pk_Pages on the key's allowed originsPublic pages only
Reader credentialasst_rc_The page it was created forWhat the key allows, narrowed to one reader

Ask a question

POST /answers

messagestring
Required

The question, up to 16,000 characters.

conversation_idstring

Your own id for the conversation, up to 200 characters, such as a ticket id. Earlier messages are kept for you, separately for each key, for 30 days after the last one. Secret key only: pages send history. Can't be sent with history.

historyarray

Earlier messages, oldest first, each { "role": "user" | "assistant", "content": "..." }. At most 49, so the conversation holds 50 with the new message. The assistant reads the latest 10 of them, or 4 in Lite mode, as on your docs site, so you can send a whole thread. Can't be sent with conversation_id.

streamboolean

true to receive the answer as stream events. Defaults to false.

formatstring

markdown (default), html, text or slack. HTML escapes any HTML in the answer. slack is Slack's own message formatting, ready to post as a message's text.

timeout_secondsnumber

How long to wait for an answer, from 3 to 120 seconds, counted from when the request arrives. Defaults to 25, or 120 with stream. Past it, the response is not answered, with reason set to timeout, and nothing is charged.

readerobject

The reader you are asking for, with the secret key only: signed_in (boolean) and roles (array of strings). It only narrows what the key reads.

Idempotency-Keystring

Requests with the same key and the same body within 10 minutes return the first answer, uncharged, with the Idempotent-Replayed: true header. Without it, the same message after the same earlier messages counts as a repeat. In a page, only the same visitor's requests count as repeats. A repeat sent while the first is still being answered waits for that answer. Publishing a change to which pages need sign-in, or to their roles, ends the 10 minutes early.

Send it if your tool retries after giving up on a slow answer. With it, an answer keeps being written after your tool hangs up, so the retry gets it, charged once. Without it, hanging up stops the answer, and nothing is charged.

Response

idstring
Required

The answer's id, starting with ans_. Send it to feedback.

conversation_idstring | null
Required

The conversation_id you sent, or null.

answeredboolean
Required

true when the assistant answered from your docs. Credits are used only then.

reasonstring | null
Required

Why answered is false: no_answer_found, timeout or small_talk. small_talk is a reply to a greeting or thanks, such as "hi": send answer as it is, without handing off. null when answered.

answerstring
Required

The answer in the requested format, with full links. Empty when not answered, except for small_talk.

formatstring
Required

markdown, html, text or slack.

confidencenumber | null
Required

The assistant's confidence, from 0 to 1. null after a timeout.

sourcesarray
Required

The pages the answer cites, each { "title": string | null, "url": string | null } with a full URL. An answer from a PDF your team uploaded lists the PDF by name, with url set to null, as it has no web address.

follow_up_questionsarray
Required

Questions the reader may ask next. Often empty, so treat it as optional.

created_atstring
Required

When the answer was given, in ISO 8601 UTC.

Stream events

With "stream": true, the response is text/event-stream. A comment line arrives at once, and another every 10 seconds while the answer is written.

EventData
answer.delta{ "text": "..." }: the next part of the answer, in Markdown as it is written
answer.completedThe response object, the same as in normal mode. Use its answer as the final text.
errorAn error object, if the answer fails after the stream starts

Refusals that happen before the answer starts, such as an invalid key, come back as normal JSON errors with their status code.

Rate an answer

POST /feedback

answer_idstring
Required

The id of an answer given to the same key in the last 30 days.

Returns { "recorded": true }.

Reader credentials

POST /reader-credentials, with the secret key, from your server.

originstring
Required

One of the key's allowed origins, exactly as the browser sends it, such as https://app.acme.com.

signed_inboolean

Whether the visitor is signed in to your product. false limits the credential to public pages. Defaults to true.

rolesarray

The visitor's roles. Only roles the key also has are kept, each time the credential is used.

expires_in_secondsinteger

From 60 to 3,600. Defaults to 900 (15 minutes).

credentialstring
Required

The credential, starting with asst_rc_. Pass it to the page, which sends it as its bearer token.

originstring
Required

The only origin the credential works from.

expires_atstring
Required

When it stops working, in ISO 8601 UTC.

expires_in_secondsnumber
Required

Its lifetime in seconds.

Check a key

GET /key returns whether the key works now and what it answers from, for setup screens. For a valid key it returns 200, with any problem reported in the body. It counts towards the key's rate limit like every request.

readyboolean
Required

true when the key can answer now.

problemstring | null
Required

The error code a question would get, or null. problem_message explains it.

answers_fromstring | null
Required

all_pages, public_pages or protected_pages, for the site as it is published now.

The response also has name, integration, caller, access, requests_per_minute and expires_at, and, for the secret key, access_roles and allowed_origins.

Delete a conversation

DELETE /conversations/{conversation_id}, with the secret key. Returns { "deleted": true }, or false if there was none.

Errors

Errors return the status code below and a flat body, as does a wrong path or method:

{ "error": "rate_limited", "message": "This key allows 60 requests a minute. Retry after 12 seconds.", "retry_after_seconds": 12 }

retry_after_seconds and the Retry-After header are set when retrying later can succeed. Once the key is accepted, refusals carry the X-RateLimit-* headers too.

StatuserrorWhat to do
400invalid_requestFix the field named in message.
413request_too_largeKeep requests under 64 KB.
401key_missingSend Authorization: Bearer <key>.
401key_invalidCheck the key was copied in full, and that it is an Assistant API key.
401key_expiredCreate a new key.
401key_revokedCreate a new key.
401reader_credential_invalidHave your server create a new reader credential.
403browser_not_allowedUse the secret key from a server only. Rotate it if it was in a page.
403origin_requiredCall with the publishable key or a reader credential from a page on an allowed origin.
403origin_not_allowedAdd the origin to the key, exactly as the browser sends it.
403plan_not_includedUpgrade to Standard or higher.
402credits_exhaustedAdd credits or turn on overage.
429monthly_quota_exceededWait for the quota to reset on the 1st (UTC).
403assistant_disabledTurn the AI assistant on for the documentation.
404site_not_publishedPublish the documentation.
403key_access_insufficientEvery page now needs sign-in. In the key's Edit dialog, choose All pages, including protected ones and save.
403reader_sign_in_requiredAsk for a signed-in reader: every page needs sign-in.
429rate_limitedRetry after retry_after_seconds.
429too_many_concurrent_requestsRetry when one of the key's 20 running requests finishes.
409request_in_progressThe same request was still being answered when your time limit ran out. Retry for its answer.
404answer_not_foundRate only answers given to this key in the last 30 days.
404not_foundCheck the method and path, such as POST /api/v1/assistant/answers.
503site_settings_unavailableRetry shortly. No answer is given without your access settings.
503temporarily_unavailableRetry shortly.
500internal_errorRetry shortly, and contact support if it persists.