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

# Create chat completion



## OpenAPI

````yaml chat-completion.yaml POST /v1/chat/completions
openapi: 3.0.1
info:
  title: ''
  version: 1.0.0
servers:
  - url: https://tokensmind.ai
    description: Production
security:
  - bearer: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat / Native OpenAI format
      summary: Chat completions format
      description: |
        Generates a model response for the given chat conversation
      operationId: createChatCompletion
      parameters:
        - name: Content-Type
          in: header
          description: ''
          required: true
          example: application/json
          schema:
            type: string
            enum:
              - application/json
            x-apifox-enum:
              - value: application/json
                name: application/json
                description: ''
        - name: Authorization
          in: header
          description: 'Bearer authentication: Bearer {{API key}}.'
          required: true
          example: Bearer sk-***
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: Model ID
                  example: gpt-4
                messages:
                  type: array
                  items:
                    $ref: '#/components/schemas/Message'
                  description: Conversation messages
                temperature:
                  type: number
                  minimum: 0
                  maximum: 2
                  default: 1
                  description: >-
                    Sampling temperature between 0 and 2. Higher values (e.g.
                    0.8) make output more random; lower values (e.g. 0.2) make
                    it more focused and deterministic.


                    We generally recommend changing either this or top_p, not
                    both.
                top_p:
                  type: number
                  description: >-
                    An alternative to temperature, called nucleus sampling: the
                    model considers tokens whose cumulative probability mass is
                    top_p. So 0.1 means only the top 10% probability mass is
                    considered. We generally recommend changing either this or
                    temperature, not both.
                  minimum: 0
                  maximum: 1
                  default: 1
                  exclusiveMinimum: true
                  nullable: true
                'n':
                  type: integer
                  minimum: 1
                  maximum: 128
                  default: 1
                  description: >
                    How many completions to generate for each prompt.

                    Note: This can consume your token quota quickly. Use with
                    care and set max_tokens and stop to reasonable values.
                stream:
                  type: boolean
                  default: false
                  description: >-
                    Whether to stream partial progress. When enabled, tokens are
                    sent as data-only server-sent events (SSE) as they become
                    available; the stream ends with a data: [DONE] message.
                stream_options:
                  type: object
                  properties:
                    include_usage:
                      type: boolean
                  x-apifox-orders:
                    - include_usage
                  description: >-
                    Options for streaming responses. Only set when stream is
                    true.
                stop:
                  type: string
                  description: >
                    Up to 4 sequences where the API will stop generating further
                    tokens. Returned text includes the stop sequence.
                max_tokens:
                  type: integer
                  description: >-
                    Maximum number of tokens to generate


                    If your prompt (prior messages) plus max_tokens would exceed
                    the model context length, behavior depends on
                    context_length_exceeded_behavior. By default, max_tokens is
                    reduced to fit the context window instead of returning an
                    error.
                max_completion_tokens:
                  type: integer
                  description: Maximum completion tokens
                presence_penalty:
                  type: number
                  minimum: -2
                  maximum: 2
                  default: 0
                  description: >-
                    Positive values penalize new tokens based on whether they
                    appear in the text so far, increasing the chance the model
                    talks about new topics.


                    For mild repetition reduction, try roughly 0.1 to 1. For
                    strong suppression, you can increase toward 2, but quality
                    may drop. Negative values encourage repetition.


                    See also frequency_penalty for penalizing tokens by how
                    often they appear.


                    Required range: -2 < x < 2
                frequency_penalty:
                  type: number
                  minimum: -2
                  maximum: 2
                  default: 0
                  description: >-
                    Positive values penalize new tokens based on their existing
                    frequency in the text, reducing the chance of repeating the
                    same line verbatim.


                    For mild repetition reduction, try roughly 0.1 to 1. For
                    strong suppression, you can increase toward 2, but quality
                    may drop. Negative values encourage repetition.


                    See also presence_penalty for a fixed penalty on tokens that
                    appear at least once.


                    Required range: -2 < x < 2
                logit_bias:
                  type: object
                  additionalProperties:
                    type: number
                  properties: {}
                  x-apifox-orders: []
                  description: >-
                    Modifies the likelihood of specified tokens appearing in the
                    completion.

                    Accepts a JSON object mapping tokens to bias values between
                    -100 and 100. Mathematically, the bias is added to the
                    logits before sampling. Exact behavior varies by model.

                    For example, "logit_bias":{"1024": 6} increases the
                    likelihood of token ID 1024.
                tools:
                  type: array
                  items:
                    $ref: '#/components/schemas/Tool'
                  description: >
                    Tools the model may call. Currently only functions are
                    supported. Provide a list of functions the model can
                    generate JSON arguments for.


                    See the [function calling
                    guide](/docs/model/llm-function-calling) for more.
                  nullable: true
                tool_choice:
                  oneOf:
                    - type: string
                      enum:
                        - none
                        - auto
                        - required
                    - type: object
                      properties:
                        type:
                          type: string
                        function:
                          type: object
                          properties:
                            name:
                              type: string
                          x-apifox-orders:
                            - name
                      x-apifox-orders:
                        - type
                        - function
                response_format:
                  type: object
                  properties: {}
                  x-apifox-orders: []
                  nullable: true
                seed:
                  type: integer
                  description: >-
                    If specified, the system will try to sample
                    deterministically so repeated requests with the same seed
                    and parameters return the same result.
                reasoning_effort:
                  type: string
                  enum:
                    - low
                    - medium
                    - high
                  description: Reasoning effort (for models that support reasoning)
                modalities:
                  type: array
                  items:
                    type: string
                    enum:
                      - text
                      - audio
                audio:
                  type: object
                  properties:
                    voice:
                      type: string
                    format:
                      type: string
                  x-apifox-orders:
                    - voice
                    - format
                repetition_penalty:
                  type: integer
                  description: >-
                    Penalty on repeated tokens to discourage or encourage
                    repetition. 1.0 means no penalty and free repetition. Values
                    above 1.0 penalize repetition. Values between 0.0 and 1.0
                    reward repetition. A balanced value is often around 1.2. The
                    penalty applies to generated output and, in decoder-only
                    models, to the prompt.


                    Required range: 0 < x < 2
                top_k:
                  type: integer
                  description: >-
                    Top-k sampling keeps only the k most likely next tokens and
                    redistributes probability mass among them. k controls how
                    many candidates are considered per step.
                  minimum: 0
                  maximum: 128
                  exclusiveMaximum: true
                  exclusiveMinimum: true
                  nullable: true
                min_p:
                  type: number
                  minimum: 0
                  maximum: 1
                  description: >
                    Minimum relative probability for a token to be considered,
                    compared to the most likely token.
                  nullable: true
                logprobs:
                  type: boolean
                  description: >
                    Whether to return log probabilities of output tokens. If
                    true, returns logprobs for each output token in the message
                    content.
                  default: false
                  nullable: true
                top_logprobs:
                  type: integer
                  minimum: 0
                  maximum: 20
                  description: >-
                    Integer between 0 and 20: how many most likely tokens to
                    return at each position, each with an associated log
                    probability. If you use this, set logprobs to true.
                  nullable: true
              x-apifox-refs: {}
              x-apifox-orders:
                - model
                - messages
                - temperature
                - top_p
                - top_k
                - min_p
                - 'n'
                - stream
                - stream_options
                - stop
                - max_tokens
                - max_completion_tokens
                - presence_penalty
                - frequency_penalty
                - repetition_penalty
                - logit_bias
                - logprobs
                - top_logprobs
                - tools
                - tool_choice
                - response_format
                - seed
                - reasoning_effort
                - modalities
                - audio
              required:
                - model
                - messages
            example:
              model: <string>
              messages:
                - content:
                    type: <string>
                    text: <string>
                    image_url: <string>
                    video_url: <string>
                  role: <string>
                  name: <string>
              max_tokens: 123
              stream: {}
              stream_options:
                include_usage: true
              'n': {}
              seed: {}
              frequency_penalty: {}
              presence_penalty: {}
              repetition_penalty: {}
              stop: {}
              temperature: {}
              top_p: {}
              top_k: {}
              min_p: {}
              logit_bias: {}
              logprobs: {}
              top_logprobs: {}
              tools:
                type: <string>
                function:
                  name: <string>
                  description: {}
                  parameters: {}
                  strict: true
              response_format:
                type: <string>
                json_schema:
                  name: <string>
                  description: {}
                  schema: {}
                  strict: true
              separate_reasoning: {}
              enable_thinking: {}
        required: true
      responses:
        '200':
          description: Response created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
          headers: {}
          x-apifox-name: Success
          x-apifox-ordering: 0
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          headers: {}
          x-apifox-name: Bad request
          x-apifox-ordering: 1
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          headers: {}
          x-apifox-ordering: 2
      deprecated: false
      security:
        - bearer: []
components:
  schemas:
    Message:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
            - developer
          description: Message role
        content:
          oneOf:
            - type: string
            - type: array
              items:
                $ref: '#/components/schemas/MessageContent'
          description: Message content
        name:
          type: string
          description: Sender name
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/ToolCall'
        tool_call_id:
          type: string
          description: Tool call ID (for tool role messages)
        reasoning_content:
          type: string
          description: Reasoning content
      x-apifox-orders:
        - role
        - content
        - name
        - tool_calls
        - tool_call_id
        - reasoning_content
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    Tool:
      type: object
      properties:
        type:
          type: string
          example: function
        function:
          type: object
          properties:
            name:
              type: string
            description:
              type: string
            parameters:
              type: object
              description: Parameter definition in JSON Schema format
              properties: {}
              x-apifox-orders: []
              x-apifox-ignore-properties: []
          x-apifox-orders:
            - name
            - description
            - parameters
          x-apifox-ignore-properties: []
      x-apifox-orders:
        - type
        - function
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/Message'
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - tool_calls
                  - content_filter
            x-apifox-orders:
              - index
              - message
              - finish_reason
            x-apifox-ignore-properties: []
        usage:
          $ref: '#/components/schemas/Usage'
        system_fingerprint:
          type: string
      x-apifox-orders:
        - id
        - object
        - created
        - model
        - choices
        - usage
        - system_fingerprint
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Error message
            type:
              type: string
              description: Error type
            param:
              type: string
              description: Related parameter
              nullable: true
            code:
              type: string
              description: Error code
              nullable: true
          x-apifox-orders:
            - message
            - type
            - param
            - code
          x-apifox-ignore-properties: []
      x-apifox-orders:
        - error
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    MessageContent:
      type: object
      properties:
        type:
          type: string
          enum:
            - text
            - image_url
            - input_audio
            - file
            - video_url
        text:
          type: string
        image_url:
          type: object
          properties:
            url:
              type: string
              description: Image URL or base64
            detail:
              type: string
              enum:
                - low
                - high
                - auto
          x-apifox-orders:
            - url
            - detail
          x-apifox-ignore-properties: []
        input_audio:
          type: object
          properties:
            data:
              type: string
              description: Base64-encoded audio data
            format:
              type: string
              enum:
                - wav
                - mp3
          x-apifox-orders:
            - data
            - format
          x-apifox-ignore-properties: []
        file:
          type: object
          properties:
            filename:
              type: string
            file_data:
              type: string
            file_id:
              type: string
          x-apifox-orders:
            - filename
            - file_data
            - file_id
          x-apifox-ignore-properties: []
        video_url:
          type: object
          properties:
            url:
              type: string
          x-apifox-orders:
            - url
          x-apifox-ignore-properties: []
      x-apifox-orders:
        - type
        - text
        - image_url
        - input_audio
        - file
        - video_url
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    ToolCall:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
          example: function
        function:
          type: object
          properties:
            name:
              type: string
            arguments:
              type: string
          x-apifox-orders:
            - name
            - arguments
          x-apifox-ignore-properties: []
      x-apifox-orders:
        - id
        - type
        - function
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          description: Prompt tokens
        completion_tokens:
          type: integer
          description: Completion tokens
        total_tokens:
          type: integer
          description: Total tokens
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            image_tokens:
              type: integer
          x-apifox-orders:
            - cached_tokens
            - text_tokens
            - audio_tokens
            - image_tokens
          x-apifox-ignore-properties: []
        completion_tokens_details:
          type: object
          properties:
            text_tokens:
              type: integer
            audio_tokens:
              type: integer
            reasoning_tokens:
              type: integer
          x-apifox-orders:
            - text_tokens
            - audio_tokens
            - reasoning_tokens
          x-apifox-ignore-properties: []
      x-apifox-orders:
        - prompt_tokens
        - completion_tokens
        - total_tokens
        - prompt_tokens_details
        - completion_tokens_details
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
  securitySchemes:
    bearer:
      type: http
      scheme: bearer

````