curl --request POST \
--url https://api.together.xyz/v1/chat/completions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>"
}
],
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"max_tokens": 123,
"stop": [
"<string>"
],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"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
},
"response_format": {
"type": "json",
"schema": {}
},
"tools": [
{
"type": "tool_type",
"function": {
"description": "A description of the function.",
"name": "function_name",
"parameters": {}
}
}
],
"tool_choice": {
"type": "tool_choice_type",
"function": {
"name": "function_name"
}
},
"safety_model": "safety_model_name"
}
'import requests
url = "https://api.together.xyz/v1/chat/completions"
payload = {
"messages": [{ "content": "<string>" }],
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"max_tokens": 123,
"stop": ["<string>"],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"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
},
"response_format": {
"type": "json",
"schema": {}
},
"tools": [
{
"type": "tool_type",
"function": {
"description": "A description of the function.",
"name": "function_name",
"parameters": {}
}
}
],
"tool_choice": {
"type": "tool_choice_type",
"function": { "name": "function_name" }
},
"safety_model": "safety_model_name"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{content: '<string>'}],
model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
max_tokens: 123,
stop: ['<string>'],
temperature: 123,
top_p: 123,
top_k: 123,
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},
response_format: {type: 'json', schema: {}},
tools: [
{
type: 'tool_type',
function: {
description: 'A description of the function.',
name: 'function_name',
parameters: {}
}
}
],
tool_choice: {type: 'tool_choice_type', function: {name: 'function_name'}},
safety_model: 'safety_model_name'
})
};
fetch('https://api.together.xyz/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.xyz/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'messages' => [
[
'content' => '<string>'
]
],
'model' => 'mistralai/Mixtral-8x7B-Instruct-v0.1',
'max_tokens' => 123,
'stop' => [
'<string>'
],
'temperature' => 123,
'top_p' => 123,
'top_k' => 123,
'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
],
'response_format' => [
'type' => 'json',
'schema' => [
]
],
'tools' => [
[
'type' => 'tool_type',
'function' => [
'description' => 'A description of the function.',
'name' => 'function_name',
'parameters' => [
]
]
]
],
'tool_choice' => [
'type' => 'tool_choice_type',
'function' => [
'name' => 'function_name'
]
],
'safety_model' => 'safety_model_name'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.together.xyz/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n \"max_tokens\": 123,\n \"stop\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"repetition_penalty\": 123,\n \"stream\": true,\n \"logprobs\": 0,\n \"echo\": true,\n \"n\": 64,\n \"min_p\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"logit_bias\": {\n \"105\": 21.4,\n \"1024\": -10.5\n },\n \"response_format\": {\n \"type\": \"json\",\n \"schema\": {}\n },\n \"tools\": [\n {\n \"type\": \"tool_type\",\n \"function\": {\n \"description\": \"A description of the function.\",\n \"name\": \"function_name\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"tool_choice_type\",\n \"function\": {\n \"name\": \"function_name\"\n }\n },\n \"safety_model\": \"safety_model_name\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.together.xyz/v1/chat/completions")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n \"max_tokens\": 123,\n \"stop\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"repetition_penalty\": 123,\n \"stream\": true,\n \"logprobs\": 0,\n \"echo\": true,\n \"n\": 64,\n \"min_p\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"logit_bias\": {\n \"105\": 21.4,\n \"1024\": -10.5\n },\n \"response_format\": {\n \"type\": \"json\",\n \"schema\": {}\n },\n \"tools\": [\n {\n \"type\": \"tool_type\",\n \"function\": {\n \"description\": \"A description of the function.\",\n \"name\": \"function_name\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"tool_choice_type\",\n \"function\": {\n \"name\": \"function_name\"\n }\n },\n \"safety_model\": \"safety_model_name\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.xyz/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n \"max_tokens\": 123,\n \"stop\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"repetition_penalty\": 123,\n \"stream\": true,\n \"logprobs\": 0,\n \"echo\": true,\n \"n\": 64,\n \"min_p\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"logit_bias\": {\n \"105\": 21.4,\n \"1024\": -10.5\n },\n \"response_format\": {\n \"type\": \"json\",\n \"schema\": {}\n },\n \"tools\": [\n {\n \"type\": \"tool_type\",\n \"function\": {\n \"description\": \"A description of the function.\",\n \"name\": \"function_name\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"tool_choice_type\",\n \"function\": {\n \"name\": \"function_name\"\n }\n },\n \"safety_model\": \"safety_model_name\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"choices": [
{
"message": {
"role": "assistant",
"content": "<string>"
},
"finish_reason": "stop",
"logprobs": {
"tokens": [
"<string>"
],
"token_logprobs": [
123
]
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
},
"created": 123,
"model": "<string>",
"object": "chat.completion"
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Create chat completion
Query a chat model.
curl --request POST \
--url https://api.together.xyz/v1/chat/completions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>"
}
],
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"max_tokens": 123,
"stop": [
"<string>"
],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"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
},
"response_format": {
"type": "json",
"schema": {}
},
"tools": [
{
"type": "tool_type",
"function": {
"description": "A description of the function.",
"name": "function_name",
"parameters": {}
}
}
],
"tool_choice": {
"type": "tool_choice_type",
"function": {
"name": "function_name"
}
},
"safety_model": "safety_model_name"
}
'import requests
url = "https://api.together.xyz/v1/chat/completions"
payload = {
"messages": [{ "content": "<string>" }],
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"max_tokens": 123,
"stop": ["<string>"],
"temperature": 123,
"top_p": 123,
"top_k": 123,
"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
},
"response_format": {
"type": "json",
"schema": {}
},
"tools": [
{
"type": "tool_type",
"function": {
"description": "A description of the function.",
"name": "function_name",
"parameters": {}
}
}
],
"tool_choice": {
"type": "tool_choice_type",
"function": { "name": "function_name" }
},
"safety_model": "safety_model_name"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{content: '<string>'}],
model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
max_tokens: 123,
stop: ['<string>'],
temperature: 123,
top_p: 123,
top_k: 123,
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},
response_format: {type: 'json', schema: {}},
tools: [
{
type: 'tool_type',
function: {
description: 'A description of the function.',
name: 'function_name',
parameters: {}
}
}
],
tool_choice: {type: 'tool_choice_type', function: {name: 'function_name'}},
safety_model: 'safety_model_name'
})
};
fetch('https://api.together.xyz/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.xyz/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'messages' => [
[
'content' => '<string>'
]
],
'model' => 'mistralai/Mixtral-8x7B-Instruct-v0.1',
'max_tokens' => 123,
'stop' => [
'<string>'
],
'temperature' => 123,
'top_p' => 123,
'top_k' => 123,
'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
],
'response_format' => [
'type' => 'json',
'schema' => [
]
],
'tools' => [
[
'type' => 'tool_type',
'function' => [
'description' => 'A description of the function.',
'name' => 'function_name',
'parameters' => [
]
]
]
],
'tool_choice' => [
'type' => 'tool_choice_type',
'function' => [
'name' => 'function_name'
]
],
'safety_model' => 'safety_model_name'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.together.xyz/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n \"max_tokens\": 123,\n \"stop\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"repetition_penalty\": 123,\n \"stream\": true,\n \"logprobs\": 0,\n \"echo\": true,\n \"n\": 64,\n \"min_p\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"logit_bias\": {\n \"105\": 21.4,\n \"1024\": -10.5\n },\n \"response_format\": {\n \"type\": \"json\",\n \"schema\": {}\n },\n \"tools\": [\n {\n \"type\": \"tool_type\",\n \"function\": {\n \"description\": \"A description of the function.\",\n \"name\": \"function_name\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"tool_choice_type\",\n \"function\": {\n \"name\": \"function_name\"\n }\n },\n \"safety_model\": \"safety_model_name\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.together.xyz/v1/chat/completions")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n \"max_tokens\": 123,\n \"stop\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"repetition_penalty\": 123,\n \"stream\": true,\n \"logprobs\": 0,\n \"echo\": true,\n \"n\": 64,\n \"min_p\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"logit_bias\": {\n \"105\": 21.4,\n \"1024\": -10.5\n },\n \"response_format\": {\n \"type\": \"json\",\n \"schema\": {}\n },\n \"tools\": [\n {\n \"type\": \"tool_type\",\n \"function\": {\n \"description\": \"A description of the function.\",\n \"name\": \"function_name\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"tool_choice_type\",\n \"function\": {\n \"name\": \"function_name\"\n }\n },\n \"safety_model\": \"safety_model_name\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.xyz/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"model\": \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n \"max_tokens\": 123,\n \"stop\": [\n \"<string>\"\n ],\n \"temperature\": 123,\n \"top_p\": 123,\n \"top_k\": 123,\n \"repetition_penalty\": 123,\n \"stream\": true,\n \"logprobs\": 0,\n \"echo\": true,\n \"n\": 64,\n \"min_p\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"logit_bias\": {\n \"105\": 21.4,\n \"1024\": -10.5\n },\n \"response_format\": {\n \"type\": \"json\",\n \"schema\": {}\n },\n \"tools\": [\n {\n \"type\": \"tool_type\",\n \"function\": {\n \"description\": \"A description of the function.\",\n \"name\": \"function_name\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"tool_choice_type\",\n \"function\": {\n \"name\": \"function_name\"\n }\n },\n \"safety_model\": \"safety_model_name\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"choices": [
{
"message": {
"role": "assistant",
"content": "<string>"
},
"finish_reason": "stop",
"logprobs": {
"tokens": [
"<string>"
],
"token_logprobs": [
123
]
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
},
"created": 123,
"model": "<string>",
"object": "chat.completion"
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Authorizations
Body
A list of messages comprising the conversation so far.
Show child attributes
Show child attributes
The name of the model to query.
"mistralai/Mixtral-8x7B-Instruct-v0.1"
The maximum number of tokens to generate.
A list of string sequences that will truncate (stop) inference text output.
Determines the degree of randomness in the response.
The top_p (nucleus) parameter is used to dynamically adjust the number of choices for each predicted token based on the cumulative probabilities.
The top_k parameter is used to limit the number of choices for the next predicted word or token.
A number that controls the diversity of generated text by reducing the likelihood of repeated sequences. Higher values decrease repetition.
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.
Determines the number of most likely tokens to return at each token position log probabilities to return
0 <= x <= 1If set, the response will contain the prompt, and will also return prompt logprobs if set with logprobs.
Number of generations to return
1 <= x <= 128The min_p parameter is a number between 0 and 1 and an alternative to temperature.
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.
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.
The logit_bias parameter allows us to adjust the likelihood of specific tokens appearing in the generated output.
Show child attributes
Show child attributes
{ "105": 21.4, "1024": -10.5 }
Specifies the format of the response.
Show child attributes
Show child attributes
A list of tools to be used in the query.
Show child attributes
Show child attributes
The choice of tool to use.
Show child attributes
Show child attributes
The name of the safety model to use.
"safety_model_name"