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

# Create chat completion

> Query a chat model.



## OpenAPI

````yaml together-openapi.yaml post /chat/completions
openapi: 3.0.0
info:
  title: Together API
  description: The Together REST API. Please see https://docs.together.ai for more details.
  version: 2.0.0
  termsOfService: https://www.together.ai/terms-of-service
  contact:
    name: Together Support
    url: https://www.together.ai/contact
  license:
    name: MIT
    url: https://github.com/togethercomputer/openapi/blob/main/LICENSE
servers:
  - url: https://api.together.xyz/v1
security:
  - bearerAuth: []
paths:
  /chat/completions:
    post:
      tags:
        - Chat
      summary: Create chat completion
      description: Query a chat model.
      operationId: chat-completions
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: '200'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ChatCompletionStream'
        '400':
          description: BadRequest
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '404':
          description: NotFound
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '429':
          description: RateLimit
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '503':
          description: Overloaded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '504':
          description: Timeout
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
      deprecated: false
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        messages:
          type: array
          description: A list of messages comprising the conversation so far.
          items:
            type: object
            properties:
              role:
                type: string
                description: >-
                  The role of the messages author. Choice between: system, user,
                  or assistant.
                enum:
                  - system
                  - user
                  - assistant
              content:
                type: string
                description: The contents of the message.
            required:
              - role
              - content
        model:
          type: string
          description: The name of the model to query.
          example: mistralai/Mixtral-8x7B-Instruct-v0.1
        max_tokens:
          type: integer
          description: The maximum number of tokens to generate.
        stop:
          type: array
          description: >-
            A list of string sequences that will truncate (stop) inference text
            output.
          items:
            type: string
        temperature:
          type: number
          description: Determines the degree of randomness in the response.
          format: float
        top_p:
          type: number
          description: >-
            The `top_p` (nucleus) parameter is used to dynamically adjust the
            number of choices for each predicted token based on the cumulative
            probabilities.
          format: float
        top_k:
          type: integer
          description: >-
            The `top_k` parameter is used to limit the number of choices for the
            next predicted word or token.
          format: int32
        repetition_penalty:
          type: number
          description: >-
            A number that controls the diversity of generated text by reducing
            the likelihood of repeated sequences. Higher values decrease
            repetition.
          format: float
        stream:
          type: boolean
          description: >-
            If set, tokens are returned as Server-Sent Events as they are made
            available. Stream terminates with `data: [DONE]`. If false, return a
            single JSON object containing the results.
        logprobs:
          type: integer
          minimum: 0
          maximum: 1
          description: >-
            Determines the number of most likely tokens to return at each token
            position log probabilities to return
        echo:
          type: boolean
          description: >-
            If set, the response will contain the prompt, and will also return
            prompt logprobs if set with logprobs.
        'n':
          type: integer
          description: Number of generations to return
          minimum: 1
          maximum: 128
        min_p:
          type: number
          description: >-
            The `min_p` parameter is a number between 0 and 1 and an alternative
            to `temperature`.
          format: float
        presence_penalty:
          type: number
          description: >-
            The `presence_penalty` parameter is a number between -2.0 and 2.0
            where a positive value will increase the likelihood of a model
            talking about new topics.
          format: float
        frequency_penalty:
          type: number
          description: >-
            The `frequency_penalty` parameter is a number between -2.0 and 2.0
            where a positive value will decrease the likelihood of repeating
            tokens that were mentioned prior.
          format: float
        logit_bias:
          type: object
          additionalProperties:
            type: number
            format: float
          description: >-
            The `logit_bias` parameter allows us to adjust the likelihood of
            specific tokens appearing in the generated output.
          example:
            '105': 21.4
            '1024': -10.5
        response_format:
          type: object
          description: Specifies the format of the response.
          properties:
            type:
              type: string
              description: The type of the response format.
              example: json
            schema:
              type: object
              additionalProperties:
                type: string
              description: The schema of the response format.
        tools:
          type: array
          description: A list of tools to be used in the query.
          items:
            $ref: '#/components/schemas/ToolsPart'
        tool_choice:
          type: object
          description: The choice of tool to use.
          oneOf:
            - type: string
              example: tool_name
            - $ref: '#/components/schemas/ToolChoice'
        safety_model:
          type: string
          description: The name of the safety model to use.
          example: safety_model_name
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        choices:
          $ref: '#/components/schemas/ChatCompletionChoicesData'
        usage:
          $ref: '#/components/schemas/UsageData'
        created:
          type: integer
        model:
          type: string
        object:
          type: string
          enum:
            - chat.completion
    ChatCompletionStream:
      oneOf:
        - $ref: '#/components/schemas/ChatCompletionEvent'
        - $ref: '#/components/schemas/StreamSentinel'
    ErrorData:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              nullable: false
            type:
              type: string
              nullable: false
            param:
              type: string
              nullable: true
              default: null
            code:
              type: string
              nullable: true
              default: null
          required:
            - type
            - message
            - param
            - code
    ToolsPart:
      type: object
      properties:
        type:
          type: string
          example: tool_type
        function:
          type: object
          properties:
            description:
              type: string
              example: A description of the function.
            name:
              type: string
              example: function_name
            parameters:
              type: object
              additionalProperties: true
              description: A map of parameter names to their values.
    ToolChoice:
      type: object
      properties:
        type:
          type: string
          example: tool_choice_type
        function:
          type: object
          properties:
            name:
              type: string
              example: function_name
    ChatCompletionChoicesData:
      type: array
      items:
        type: object
        properties:
          message:
            type: object
            properties:
              role:
                type: string
                example: assistant
              content:
                type: string
          finish_reason:
            $ref: '#/components/schemas/FinishReason'
          logprobs:
            allOf:
              - nullable: true
              - $ref: '#/components/schemas/LogprobsPart'
    UsageData:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      nullable: true
    ChatCompletionEvent:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/ChatCompletionChunk'
    StreamSentinel:
      type: object
      required:
        - data
      properties:
        data:
          title: stream_signal
          type: string
          enum:
            - '[DONE]'
    FinishReason:
      type: string
      enum:
        - stop
        - eos
        - length
        - tool_calls
    LogprobsPart:
      type: object
      properties:
        tokens:
          type: array
          items:
            type: string
          description: List of token strings
        token_logprobs:
          type: array
          items:
            type: number
            format: float
          description: List of token log probabilities
    ChatCompletionChunk:
      type: object
      required:
        - id
        - object
        - created
        - token
        - choices
      properties:
        id:
          type: string
        object:
          type: string
          enum:
            - chat.completion.chunk
        created:
          type: integer
        token:
          $ref: '#/components/schemas/ChatCompletionToken'
        choices:
          title: ChatCompletionChoices
          type: array
          items:
            $ref: '#/components/schemas/ChatCompletionChoice'
        usage:
          allOf:
            - $ref: '#/components/schemas/UsageData'
            - nullable: true
        finish_reason:
          allOf:
            - $ref: '#/components/schemas/FinishReason'
            - nullable: true
    ChatCompletionToken:
      type: object
      required:
        - id
        - text
        - logprob
        - special
      properties:
        id:
          type: integer
        text:
          type: string
        logprob:
          type: number
          format: float
        special:
          type: boolean
    ChatCompletionChoice:
      type: object
      required:
        - index
        - delta
      properties:
        index:
          type: integer
        delta:
          title: ChatCompletionChoiceDelta
          type: object
          required:
            - content
          properties:
            content:
              type: string
  securitySchemes:
    bearerAuth:
      type: apiKey
      in: header
      name: Authorization
      x-bearer-format: bearer
      x-default: default

````