Create chat completion
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
}
}Chat
Create chat completion
Query a chat model.
POST
/
chat
/
completions
Create chat completion
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
}
}Body
application/json