POST
/
chat
/
completions
Create chat completion
curl --request POST \
  --url https://api.together.xyz/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "messages": [
    {
      "role": "system",
      "content": "<string>"
    }
  ],
  "model": "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
  "max_tokens": 123,
  "stop": [
    "<string>"
  ],
  "temperature": 123,
  "top_p": 123,
  "top_k": 123,
  "context_length_exceeded_behavior": "error",
  "repetition_penalty": 123,
  "stream": true,
  "logprobs": 0,
  "echo": true,
  "n": 64,
  "min_p": 123,
  "presence_penalty": 123,
  "frequency_penalty": 123,
  "logit_bias": {
    "105": 21.4,
    "1024": -10.5
  },
  "seed": 42,
  "function_call": "none",
  "response_format": {
    "type": "json",
    "schema": {}
  },
  "tools": [
    {
      "type": "tool_type",
      "function": {
        "description": "A description of the function.",
        "name": "function_name",
        "parameters": {}
      }
    }
  ],
  "tool_choice": "tool_name",
  "safety_model": "safety_model_name"
}'
{
  "id": "<string>",
  "choices": [
    {
      "text": "<string>",
      "index": 123,
      "seed": 123,
      "finish_reason": "stop",
      "message": {
        "content": "<string>",
        "role": "assistant",
        "tool_calls": [
          {
            "index": 123,
            "id": "<string>",
            "type": "function",
            "function": {
              "name": "function_name",
              "arguments": "<string>"
            }
          }
        ],
        "function_call": {
          "arguments": "<string>",
          "name": "<string>"
        }
      },
      "logprobs": {
        "token_ids": [
          123
        ],
        "tokens": [
          "<string>"
        ],
        "token_logprobs": [
          123
        ]
      }
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  },
  "created": 123,
  "model": "<string>",
  "object": "chat.completion"
}

Authorizations

Authorization
string
header
default:default
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
messages
object[]
required

A list of messages comprising the conversation so far.

model
required

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

Available options:
Qwen/Qwen2.5-72B-Instruct-Turbo,
Qwen/Qwen2.5-7B-Instruct-Turbo,
meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo,
meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo,
meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo
Example:

"meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"

max_tokens
integer

The maximum number of tokens to generate.

stop
string[]

A list of string sequences that will truncate (stop) inference text output. For example, "</s>" will stop 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
enum<string>
default:error

Defined the behavior of the API when max_tokens exceed the maximum context length of the model. When set to 'error', API will return 400 with appropriate error message. When set to 'truncate', override the max_tokens with maximum context length of the model.

Available options:
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

Integer (0 or 1) that controls whether log probabilities of generated tokens are returned. Log probabilities help assess model confidence in token predictions.

Required range: 0 <= x <= 1
echo
boolean

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

n
integer

The number of completions to generate for each prompt.

Required range: 1 <= x <= 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
object

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

Example:
{ "105": 21.4, "1024": -10.5 }
seed
integer

Seed value for reproducibility.

Example:

42

function_call
Available options:
none,
auto
response_format
object

An object specifying the format that the model must output.

tools
object[]

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.

Example:

"tool_name"

safety_model
string

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

Example:

"safety_model_name"

Response

200

id
string
required
choices
object[]
required
created
integer
required
model
string
required
object
enum<string>
required
Available options:
chat.completion
usage
object | null