v3

OpenAPI 3.1.0MIT2026-07-31192456807.8 KB
Chat

Create chat completion

Generate a model response for a given chat conversation. Supports single queries and multi-turn conversations with system, user, and assistant messages.

post/chat/completions

Request body

modelstring required

The name of the model to query.<br> <br> See all of Together AI's chat models

max_tokensinteger

The maximum number of tokens to generate.

stopstring[]

A list of string sequences that truncate (stop) inference text output. For example, "</s>" stops generation as soon as the model generates the given token.

temperaturenumber

A decimal number from 0-1 that determines the degree of randomness in the response. A temperature less than 1 favors more correctness and is appropriate for question answering or summarization. A value closer to 1 introduces more randomness in the output.

top_pnumber

A percentage (also called the nucleus parameter) that's used to dynamically adjust the number of choices for each predicted token based on the cumulative probabilities. It specifies a probability threshold below which all less likely tokens are filtered out. This technique helps maintain diversity and generate more fluent and natural-sounding text.

top_kinteger

An integer that's used to limit the number of choices for the next predicted word or token. It specifies the maximum number of tokens to consider at each step, based on their probability of occurrence. This technique helps to speed up the generation process and can improve the quality of the generated text by focusing on the most likely options.

context_length_exceeded_behavior'truncate' | 'error'

Defines the behavior of the API when max_tokens exceed the maximum context length of the model. When set to 'error', the API returns 400 with an appropriate error message. When set to 'truncate', overrides max_tokens with the maximum context length of the model.

repetition_penaltynumber

A number that controls the diversity of generated text by reducing the likelihood of repeated sequences. Higher values decrease repetition.

streamboolean

If true, stream tokens as Server-Sent Events as the model generates them instead of waiting for the full model response. The stream terminates with data: [DONE]. If false, return a single JSON object containing the results.

logprobsinteger

An integer between 0 and 20 of the top k tokens to return log probabilities for at each generation step, instead of only the sampled token. Log probabilities help assess model confidence in token predictions.

echoboolean

If true, the response contains the prompt. Can be used with logprobs to return prompt logprobs.

ninteger

The number of completions to generate for each prompt.

min_pnumber

A number between 0 and 1 that can be used as an alternative to top_p and top-k.

presence_penaltynumber

A number between -2.0 and 2.0 where a positive value increases the likelihood of a model talking about new topics.

frequency_penaltynumber

A number between -2.0 and 2.0 where a positive value decreases the likelihood of repeating tokens that have already been mentioned.

logit_biasobject

Adjusts the likelihood of specific tokens appearing in the generated output.

seedinteger

Seed value for reproducibility.

compliance'hipaa'
chat_template_kwargsobject

Additional configuration to pass to model engine.

safety_modelstring

The name of the moderation model used to validate tokens. Choose from the available moderation models found here.

reasoning_effort'low' | 'medium' | 'high'

Controls the level of reasoning effort the model should apply when generating responses. Higher values may result in more thoughtful and detailed responses but may take longer to generate.

Example request

{
  "messages": [
    {
      "tool_calls": [
        {
          "function": {
            "name": "function_name"
          }
        }
      ]
    }
  ],
  "logit_bias": {
    "105": 21.4,
    "1024": -10.5
  },
  "seed": 42,
  "tools": [
    {
      "type": "tool_type",
      "function": {
        "description": "A description of the function.",
        "name": "function_name"
      }
    }
  ],
  "tool_choice": "tool_name",
  "safety_model": "safety_model_name",
  "reasoning_effort": "medium"
}

Response

200

idstring required
createdinteger required
modelstring required
object'chat.completion' required

The object type, which is always chat.completion.

Example response

{
  "choices": [
    {
      "message": {
        "tool_calls": [
          {
            "function": {
              "name": "function_name"
            }
          }
        ]
      }
    }
  ],
  "prompt": [
    {
      "text": "<s>[INST] What is the capital of France? [/INST]"
    }
  ]
}