> ## Documentation Index
> Fetch the complete documentation index at: https://docs.petal.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a chat message

> Create a new message in a given AI Session



## OpenAPI

````yaml POST /api/ai/session/{ai_session_id}/qa/create
openapi: 3.0.3
info:
  title: Petal API Document
  description: Reference document for Petal app
  license:
    name: MIT
  version: 1.2.5
servers:
  - url: https://cite.petal.org
security:
  - bearerAuth: []
tags:
  - name: signup
  - name: extraction
  - name: referral
  - name: site
  - name: citegen
  - name: invite
  - name: user
  - name: tag
  - name: ai
  - name: notification
  - name: organization
  - name: annotation
  - name: search
  - name: attachment
  - name: collection
  - name: discourse
  - name: main
  - name: ai-create
  - name: document
  - name: payment
  - name: comment
  - name: lambda
  - name: sauce
  - name: admin
  - name: error
  - name: opengraph
  - name: default
  - name: media
  - name: file
  - name: oauth
paths:
  /api/ai/session/{ai_session_id}/qa/create:
    post:
      tags:
        - ai
      summary: Asks for an AI-generated answer from query.
      description: Create a new message in a given AI Session
      operationId: post_/api/ai/session/{ai_session_id}/qa/create
      parameters:
        - description: >-
            The unique ID of the Session in which the new message is to be
            created
          in: path
          name: ai_session_id
          required: true
          schema:
            format: int32
            type: integer
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AIQABody'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AIQAList'
          description: OK
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
          description: Unprocessable Entity
components:
  schemas:
    AIQABody:
      additionalProperties: false
      properties:
        chat_model:
          title: Chat Model
          description: >-
            The model of AI to use. Defaults to gpt-3.5-turbo for single-doc
            chat, and gpt-3.5-turbo-16k for multi-doc chat. Do not change unless
            you are will to incur potentially much higher costs
          type: string
        language:
          title: Language
          description: Desired language of the AI response
          default: English (US)
          type: string
        meta:
          title: Meta
          description: Metadata, for internal use
          type: object
        query:
          title: Query
          description: Your chat message to the AI
          type: string
        restrict_to_context:
          title: Restrict To Context
          description: Whether to only use information from the document(s) in this Session
          default: 'True'
          type: boolean
        use_cells:
          title: Use Cells
          description: >-
            Whether to use information from AI Cells associated with Documents
            from this Sesssion
          default: 'True'
          type: boolean
        use_context:
          title: Use Context
          description: >-
            Whether to use information from the document(s) in this Session.
            Cannot be False if restrict_to_context is True
          default: 'True'
          type: boolean
        use_history:
          title: Use History
          description: >-
            Whether the new AI response should be related to the previous chat
            history
          default: 'True'
          type: boolean
        use_meta:
          title: Use Meta
          description: Whether to use the metadata of the document(s) in this Session
          default: 'True'
          type: boolean
      required:
        - query
      title: AIQABody
      type: object
    AIQAList:
      additionalProperties: false
      items:
        $ref: '#/components/schemas/AIQA'
      title: AIQAList
      type: array
    ValidationError:
      description: Model of a validation error response.
      items:
        $ref: '#/components/schemas/ValidationError.ValidationErrorElement'
      title: ValidationError
      type: array
    AIQA:
      additionalProperties: false
      properties:
        ai_session_id:
          title: AI Session ID
          description: The unique ID of the AI Session this message belongs to
          type: integer
        created_at:
          title: Created At
          description: Time of message creation, in UTC
          type: string
        id:
          title: ID
          description: Unique ID of this message
          type: integer
        meta:
          title: Meta
          description: Metadata, for internal use
          type: object
        query:
          title: Query
          description: The user-provided message to the AI
          type: string
        response:
          title: Response
          description: The AI's response to the user
          type: string
        task_id:
          title: Task ID
          description: Task ID for internal use
          type: string
        task_status:
          title: Task Status
          description: Progress on obtaining a response from the AI
          type: string
        user_id:
          title: User ID
          description: ID of user who submitted the message
          type: integer
        user_rating:
          title: User Rating
          description: User's assessment of the AI response
          type: string
      required:
        - id
        - ai_session_id
        - user_id
        - task_id
        - user_rating
        - created_at
        - query
        - meta
        - task_status
      title: AIQA
      type: object
    ValidationError.ValidationErrorElement:
      description: Model of a validation error response element.
      properties:
        ctx:
          title: Error context
          type: object
        loc:
          items:
            type: string
          title: Missing field name
          type: array
        msg:
          title: Error message
          type: string
        type:
          title: Error type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationErrorElement
      type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````