> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. # Post Chat Completion POST https://fai.buildwithfern.com/chat/{domain} Content-Type: application/json Reference: https://buildwithfern.com/learn/docs/ai-features/ask-fern/api-reference/chat/post-chat-completion ## Authentication - `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer `, where token is your auth token. ## Servers - `https://fai.buildwithfern.com` (Production, default) - `https://fai-dev.buildwithfern.com` (Development) - `http://localhost:8080` (Local) ## Request ### Path parameters - `domain` (string, required) ### Body (application/json) This endpoint expects a PostChatCompletionRequest. - `messages` (list of ChatMessage, required) — The messages to use for the chat completion - `model` (enum, optional, nullable) — The model to use for the chat completion - Allowed values: `claude-4-sonnet`, `claude-4.5-haiku`, `claude-4.5-sonnet`, `claude-4.6-sonnet` - `max_tokens` (integer, optional, nullable, default: 3000) — The maximum number of tokens to generate. Note: setting a token count lower than 2000 may result in incomplete responses. You can add a custom system prompt to control the verbosity of the response. - `system_prompt` (string, optional, nullable) — The system prompt to use for the chat completion - `rewrite_query` (boolean, optional, nullable, default: false) — Whether to rewrite the query using query decomposition - `user_is_authed` (boolean, optional, default: false) — Whether the requesting user is authenticated. When true, authed chunks are included in results. - `allowed_roles` (list of string, optional, nullable) — Roles the authenticated user has. Used to filter chunks by role-based access control. - `source` (string, optional, nullable) — The origin of the request (e.g. 'web', 'slack', 'api'). - `basepaths` (list of string, optional, nullable) — Restrict retrieval to pages under these URL path prefixes (e.g. ['/my-product']). Matches the scoping the Ask AI widget applies when embedded under a product path. Omit to search the whole site. - `skip_save_query` (boolean, optional, default: false) — Set to true for test or eval traffic. The request is answered (and billed) normally but is excluded from usage analytics. ## Response ### 200 Successful Response - `turns` (list of ChatMessage, required) — The conversation turns in the chat completion - `citations` (list of string, required) — List of citation strings - `sources` (list of ChatSource, optional) — Pages the answer was grounded in, one entry per cited page ## Errors ### 422 Unprocessable Entity Error Validation Error - `detail` (list of ValidationError, optional) ## Types ### ChatMessage - `role` (enum, required) - Allowed values: `user`, `assistant` - `content` (string, required) ### ChatSource - `url` (string, required) — URL of the cited documentation page - `title` (string, required) — Title of the cited documentation page ### ValidationError - `loc` (list of ValidationErrorLocItems, required) - `msg` (string, required) - `type` (string, required) ### ValidationErrorLocItems ## Examples **Request** ```json { "messages": [ { "role": "user", "content": "string" } ] } ``` **Response** ```json { "turns": [ { "role": "user", "content": "string" } ], "citations": [ "string" ], "sources": [ { "url": "string", "title": "string" } ] } ```