> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI0ZjZlMTA2Ni1hZjBjLTRhMzMtOWE4Ny1jOWNkMzJkNGE0MGEiLCJleHAiOjE3NzgyNzM1NjcsImlhdCI6MTc3ODI3MzI2N30.iqznmMyfX00BaqL48tZtTcdQRH4TUWzvB7UMSb4Be3A
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: fai
  version: 1.0.0
paths:
  /chat/{domain}:
    post:
      operationId: post-chat-completion
      summary: Post Chat Completion
      tags:
        - subpackage_chat
      parameters:
        - name: domain
          in: path
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostChatCompletionResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PostChatCompletionRequest'
servers:
  - url: https://fai.buildwithfern.com
  - url: https://fai-dev.buildwithfern.com
  - url: http://localhost:8080
components:
  schemas:
    LanguageModel:
      type: string
      enum:
        - claude-4-sonnet
        - claude-4.5-haiku
        - claude-4.5-sonnet
        - claude-4.6-sonnet
      title: LanguageModel
    ChatMessageRole:
      type: string
      enum:
        - user
        - assistant
      title: ChatMessageRole
    ChatMessage:
      type: object
      properties:
        role:
          $ref: '#/components/schemas/ChatMessageRole'
        content:
          type: string
      required:
        - role
        - content
      title: ChatMessage
    PostChatCompletionRequest:
      type: object
      properties:
        model:
          oneOf:
            - $ref: '#/components/schemas/LanguageModel'
            - type: 'null'
          description: The model to use for the chat completion
        max_tokens:
          type:
            - integer
            - 'null'
          default: 3000
          description: >-
            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:
          type:
            - string
            - 'null'
          description: The system prompt to use for the chat completion
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
          description: The messages to use for the chat completion
        rewrite_query:
          type:
            - boolean
            - 'null'
          default: false
          description: Whether to rewrite the query using query decomposition
      required:
        - messages
      title: PostChatCompletionRequest
    PostChatCompletionResponse:
      type: object
      properties:
        turns:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
          description: The conversation turns in the chat completion
        citations:
          type: array
          items:
            type: string
          description: List of citation strings
      required:
        - turns
        - citations
      title: PostChatCompletionResponse
    ValidationErrorLocItems:
      oneOf:
        - type: string
        - type: integer
      title: ValidationErrorLocItems
    ValidationError:
      type: object
      properties:
        loc:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorLocItems'
        msg:
          type: string
        type:
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
    HTTPValidationError:
      type: object
      properties:
        detail:
          type: array
          items:
            $ref: '#/components/schemas/ValidationError'
      title: HTTPValidationError
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

```