Chat

Create chat completion

POST
/chat/completions

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

Authorization

bearerAuth
AuthorizationBearer <token>

In: header

Request Body

application/json

messages*array<||||>

A list of messages comprising the conversation so far.

model*string

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

max_tokens?integer

The maximum number of tokens to generate.

stop?array<string>

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

temperature?number

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_p?number

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_k?integer

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?string

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.

Default"error"

Value in

  • "truncate"
  • "error"
repetition_penalty?number

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

stream?boolean

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.

logprobs?integer

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.

Range0 <= value <= 20
echo?boolean

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

n?integer

The number of completions to generate for each prompt.

Range1 <= value <= 128
min_p?number

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

presence_penalty?number

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

frequency_penalty?number

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

logit_bias?

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

seed?integer

Seed value for reproducibility.

function_call?|
response_format?||

An object specifying the format that the model must output.

Setting to { "type": "json_schema", "json_schema": {...} } enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.

Setting to { "type": "json_object" } enables the older JSON mode, which ensures the message the model generates is valid JSON. Using json_schema is preferred for models that support it.

tools?array<>

A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.

tool_choice?|

Controls which (if any) function is called by the model. By default uses auto, which lets the model pick between generating a message or calling a function.

compliance?unknown
chat_template_kwargs?

Additional configuration to pass to model engine.

safety_model?string

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

reasoning_effort?string

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.

Value in

  • "low"
  • "medium"
  • "high"
reasoning?

For models that support toggling reasoning functionality, this object can be used to control that functionality.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/chat/completions" \  -H "Content-Type: application/json" \  -d '{    "messages": [      {        "content": "string",        "role": "system"      }    ],    "model": "string"  }'
{  "id": "string",  "choices": [    {      "text": "string",      "index": 0,      "seed": 0,      "finish_reason": "stop",      "message": {        "content": "string",        "role": "assistant",        "tool_calls": [          {            "index": 0,            "id": "string",            "type": "function",            "function": {              "name": "string",              "arguments": "string"            }          }        ],        "function_call": {          "arguments": "string",          "name": "string"        },        "reasoning": "string",        "reasoning_content": "string"      },      "logprobs": {        "token_ids": [          0        ],        "tokens": [          "string"        ],        "token_logprobs": [          0        ],        "top_logprobs": {          "property1": 0,          "property2": 0        }      },      "top_logprobs": {        "property1": 0,        "property2": 0      }    }  ],  "usage": {    "prompt_tokens": 0,    "completion_tokens": 0,    "total_tokens": 0  },  "created": 0,  "model": "string",  "prompt": [    {      "text": "string",      "logprobs": {        "token_ids": [          0        ],        "tokens": [          "string"        ],        "token_logprobs": [          0        ],        "top_logprobs": {          "property1": 0,          "property2": 0        }      }    }  ],  "object": "chat.completion",  "warnings": [    {      "message": "string"    }  ]}