# 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.1
info:
  title: Post Chat Completion
  version: endpoint_chat.post_chat_completion
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 of the form `Bearer <token>`, where token is
            your auth token.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostChatCompletionResponse'
        '422':
          description: Validation Error
          content: {}
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PostChatCompletionRequest'
components:
  schemas:
    LanguageModel:
      type: string
      enum:
        - value: claude-4-sonnet
        - value: command-a-03-2025
        - value: claude-4.5-haiku
        - value: claude-4.5-sonnet
    ChatMessageRole:
      type: string
      enum:
        - value: user
        - value: assistant
    ChatMessage:
      type: object
      properties:
        role:
          $ref: '#/components/schemas/ChatMessageRole'
        content:
          type: string
      required:
        - role
        - content
    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
    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

```