curl --request POST \
--url https://api.example.com/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>",
"role": "developer",
"name": "<string>"
}
],
"model": "<string>",
"audio": {
"format": "<string>",
"voice": "<string>"
},
"frequency_penalty": 123,
"logit_bias": {},
"logprobs": true,
"max_completion_tokens": 1,
"metadata": {},
"modalities": [
"<string>"
],
"n": 1,
"parallel_tool_calls": true,
"prediction": {
"content": "<string>",
"type": "<string>"
},
"presence_penalty": 123,
"prompt_cache_key": "<string>",
"reasoning_effort": "<string>",
"response_format": "<unknown>",
"seed": 123,
"service_tier": "<string>",
"stop": [
"<string>"
],
"store": true,
"stream": true,
"stream_options": {
"include_usage": true
},
"temperature": 123,
"tool_choice": "<unknown>",
"tools": [
{
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>",
"strict": true
},
"type": "<string>"
}
],
"top_logprobs": 1,
"top_p": 123,
"user": "<string>"
}
'import requests
url = "https://api.example.com/v1/chat/completions"
payload = {
"messages": [
{
"content": "<string>",
"role": "developer",
"name": "<string>"
}
],
"model": "<string>",
"audio": {
"format": "<string>",
"voice": "<string>"
},
"frequency_penalty": 123,
"logit_bias": {},
"logprobs": True,
"max_completion_tokens": 1,
"metadata": {},
"modalities": ["<string>"],
"n": 1,
"parallel_tool_calls": True,
"prediction": {
"content": "<string>",
"type": "<string>"
},
"presence_penalty": 123,
"prompt_cache_key": "<string>",
"reasoning_effort": "<string>",
"response_format": "<unknown>",
"seed": 123,
"service_tier": "<string>",
"stop": ["<string>"],
"store": True,
"stream": True,
"stream_options": { "include_usage": True },
"temperature": 123,
"tool_choice": "<unknown>",
"tools": [
{
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>",
"strict": True
},
"type": "<string>"
}
],
"top_logprobs": 1,
"top_p": 123,
"user": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{content: '<string>', role: 'developer', name: '<string>'}],
model: '<string>',
audio: {format: '<string>', voice: '<string>'},
frequency_penalty: 123,
logit_bias: {},
logprobs: true,
max_completion_tokens: 1,
metadata: {},
modalities: ['<string>'],
n: 1,
parallel_tool_calls: true,
prediction: {content: '<string>', type: '<string>'},
presence_penalty: 123,
prompt_cache_key: '<string>',
reasoning_effort: '<string>',
response_format: '<unknown>',
seed: 123,
service_tier: '<string>',
stop: ['<string>'],
store: true,
stream: true,
stream_options: {include_usage: true},
temperature: 123,
tool_choice: '<unknown>',
tools: [
{
function: {
name: '<string>',
description: '<string>',
parameters: '<unknown>',
strict: true
},
type: '<string>'
}
],
top_logprobs: 1,
top_p: 123,
user: '<string>'
})
};
fetch('https://api.example.com/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.example.com/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>',
'role' => 'developer',
'name' => '<string>'
]
],
'model' => '<string>',
'audio' => [
'format' => '<string>',
'voice' => '<string>'
],
'frequency_penalty' => 123,
'logit_bias' => [
],
'logprobs' => true,
'max_completion_tokens' => 1,
'metadata' => [
],
'modalities' => [
'<string>'
],
'n' => 1,
'parallel_tool_calls' => true,
'prediction' => [
'content' => '<string>',
'type' => '<string>'
],
'presence_penalty' => 123,
'prompt_cache_key' => '<string>',
'reasoning_effort' => '<string>',
'response_format' => '<unknown>',
'seed' => 123,
'service_tier' => '<string>',
'stop' => [
'<string>'
],
'store' => true,
'stream' => true,
'stream_options' => [
'include_usage' => true
],
'temperature' => 123,
'tool_choice' => '<unknown>',
'tools' => [
[
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => '<unknown>',
'strict' => true
],
'type' => '<string>'
]
],
'top_logprobs' => 1,
'top_p' => 123,
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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.example.com/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"developer\",\n \"name\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"audio\": {\n \"format\": \"<string>\",\n \"voice\": \"<string>\"\n },\n \"frequency_penalty\": 123,\n \"logit_bias\": {},\n \"logprobs\": true,\n \"max_completion_tokens\": 1,\n \"metadata\": {},\n \"modalities\": [\n \"<string>\"\n ],\n \"n\": 1,\n \"parallel_tool_calls\": true,\n \"prediction\": {\n \"content\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"presence_penalty\": 123,\n \"prompt_cache_key\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"service_tier\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"store\": true,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"temperature\": 123,\n \"tool_choice\": \"<unknown>\",\n \"tools\": [\n {\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\",\n \"strict\": true\n },\n \"type\": \"<string>\"\n }\n ],\n \"top_logprobs\": 1,\n \"top_p\": 123,\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.example.com/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"developer\",\n \"name\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"audio\": {\n \"format\": \"<string>\",\n \"voice\": \"<string>\"\n },\n \"frequency_penalty\": 123,\n \"logit_bias\": {},\n \"logprobs\": true,\n \"max_completion_tokens\": 1,\n \"metadata\": {},\n \"modalities\": [\n \"<string>\"\n ],\n \"n\": 1,\n \"parallel_tool_calls\": true,\n \"prediction\": {\n \"content\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"presence_penalty\": 123,\n \"prompt_cache_key\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"service_tier\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"store\": true,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"temperature\": 123,\n \"tool_choice\": \"<unknown>\",\n \"tools\": [\n {\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\",\n \"strict\": true\n },\n \"type\": \"<string>\"\n }\n ],\n \"top_logprobs\": 1,\n \"top_p\": 123,\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"developer\",\n \"name\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"audio\": {\n \"format\": \"<string>\",\n \"voice\": \"<string>\"\n },\n \"frequency_penalty\": 123,\n \"logit_bias\": {},\n \"logprobs\": true,\n \"max_completion_tokens\": 1,\n \"metadata\": {},\n \"modalities\": [\n \"<string>\"\n ],\n \"n\": 1,\n \"parallel_tool_calls\": true,\n \"prediction\": {\n \"content\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"presence_penalty\": 123,\n \"prompt_cache_key\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"service_tier\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"store\": true,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"temperature\": 123,\n \"tool_choice\": \"<unknown>\",\n \"tools\": [\n {\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\",\n \"strict\": true\n },\n \"type\": \"<string>\"\n }\n ],\n \"top_logprobs\": 1,\n \"top_p\": 123,\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"choices": [
{
"finish_reason": "<string>",
"index": 1,
"message": {
"role": "<string>",
"annotations": "<unknown>",
"audio": "<unknown>",
"content": "<string>",
"refusal": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>"
}
]
},
"logprobs": "<unknown>"
}
],
"created": 1,
"id": "<string>",
"model": "<string>",
"object": "<string>",
"usage": {
"completion_tokens": 1,
"prompt_tokens": 1,
"total_tokens": 1,
"completion_tokens_details": "<unknown>",
"prompt_tokens_details": "<unknown>"
},
"service_tier": "<string>",
"system_fingerprint": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}Create Chat Completion
curl --request POST \
--url https://api.example.com/v1/chat/completions \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"content": "<string>",
"role": "developer",
"name": "<string>"
}
],
"model": "<string>",
"audio": {
"format": "<string>",
"voice": "<string>"
},
"frequency_penalty": 123,
"logit_bias": {},
"logprobs": true,
"max_completion_tokens": 1,
"metadata": {},
"modalities": [
"<string>"
],
"n": 1,
"parallel_tool_calls": true,
"prediction": {
"content": "<string>",
"type": "<string>"
},
"presence_penalty": 123,
"prompt_cache_key": "<string>",
"reasoning_effort": "<string>",
"response_format": "<unknown>",
"seed": 123,
"service_tier": "<string>",
"stop": [
"<string>"
],
"store": true,
"stream": true,
"stream_options": {
"include_usage": true
},
"temperature": 123,
"tool_choice": "<unknown>",
"tools": [
{
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>",
"strict": true
},
"type": "<string>"
}
],
"top_logprobs": 1,
"top_p": 123,
"user": "<string>"
}
'import requests
url = "https://api.example.com/v1/chat/completions"
payload = {
"messages": [
{
"content": "<string>",
"role": "developer",
"name": "<string>"
}
],
"model": "<string>",
"audio": {
"format": "<string>",
"voice": "<string>"
},
"frequency_penalty": 123,
"logit_bias": {},
"logprobs": True,
"max_completion_tokens": 1,
"metadata": {},
"modalities": ["<string>"],
"n": 1,
"parallel_tool_calls": True,
"prediction": {
"content": "<string>",
"type": "<string>"
},
"presence_penalty": 123,
"prompt_cache_key": "<string>",
"reasoning_effort": "<string>",
"response_format": "<unknown>",
"seed": 123,
"service_tier": "<string>",
"stop": ["<string>"],
"store": True,
"stream": True,
"stream_options": { "include_usage": True },
"temperature": 123,
"tool_choice": "<unknown>",
"tools": [
{
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>",
"strict": True
},
"type": "<string>"
}
],
"top_logprobs": 1,
"top_p": 123,
"user": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [{content: '<string>', role: 'developer', name: '<string>'}],
model: '<string>',
audio: {format: '<string>', voice: '<string>'},
frequency_penalty: 123,
logit_bias: {},
logprobs: true,
max_completion_tokens: 1,
metadata: {},
modalities: ['<string>'],
n: 1,
parallel_tool_calls: true,
prediction: {content: '<string>', type: '<string>'},
presence_penalty: 123,
prompt_cache_key: '<string>',
reasoning_effort: '<string>',
response_format: '<unknown>',
seed: 123,
service_tier: '<string>',
stop: ['<string>'],
store: true,
stream: true,
stream_options: {include_usage: true},
temperature: 123,
tool_choice: '<unknown>',
tools: [
{
function: {
name: '<string>',
description: '<string>',
parameters: '<unknown>',
strict: true
},
type: '<string>'
}
],
top_logprobs: 1,
top_p: 123,
user: '<string>'
})
};
fetch('https://api.example.com/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.example.com/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>',
'role' => 'developer',
'name' => '<string>'
]
],
'model' => '<string>',
'audio' => [
'format' => '<string>',
'voice' => '<string>'
],
'frequency_penalty' => 123,
'logit_bias' => [
],
'logprobs' => true,
'max_completion_tokens' => 1,
'metadata' => [
],
'modalities' => [
'<string>'
],
'n' => 1,
'parallel_tool_calls' => true,
'prediction' => [
'content' => '<string>',
'type' => '<string>'
],
'presence_penalty' => 123,
'prompt_cache_key' => '<string>',
'reasoning_effort' => '<string>',
'response_format' => '<unknown>',
'seed' => 123,
'service_tier' => '<string>',
'stop' => [
'<string>'
],
'store' => true,
'stream' => true,
'stream_options' => [
'include_usage' => true
],
'temperature' => 123,
'tool_choice' => '<unknown>',
'tools' => [
[
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => '<unknown>',
'strict' => true
],
'type' => '<string>'
]
],
'top_logprobs' => 1,
'top_p' => 123,
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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.example.com/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"developer\",\n \"name\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"audio\": {\n \"format\": \"<string>\",\n \"voice\": \"<string>\"\n },\n \"frequency_penalty\": 123,\n \"logit_bias\": {},\n \"logprobs\": true,\n \"max_completion_tokens\": 1,\n \"metadata\": {},\n \"modalities\": [\n \"<string>\"\n ],\n \"n\": 1,\n \"parallel_tool_calls\": true,\n \"prediction\": {\n \"content\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"presence_penalty\": 123,\n \"prompt_cache_key\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"service_tier\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"store\": true,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"temperature\": 123,\n \"tool_choice\": \"<unknown>\",\n \"tools\": [\n {\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\",\n \"strict\": true\n },\n \"type\": \"<string>\"\n }\n ],\n \"top_logprobs\": 1,\n \"top_p\": 123,\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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.example.com/v1/chat/completions")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"developer\",\n \"name\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"audio\": {\n \"format\": \"<string>\",\n \"voice\": \"<string>\"\n },\n \"frequency_penalty\": 123,\n \"logit_bias\": {},\n \"logprobs\": true,\n \"max_completion_tokens\": 1,\n \"metadata\": {},\n \"modalities\": [\n \"<string>\"\n ],\n \"n\": 1,\n \"parallel_tool_calls\": true,\n \"prediction\": {\n \"content\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"presence_penalty\": 123,\n \"prompt_cache_key\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"service_tier\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"store\": true,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"temperature\": 123,\n \"tool_choice\": \"<unknown>\",\n \"tools\": [\n {\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\",\n \"strict\": true\n },\n \"type\": \"<string>\"\n }\n ],\n \"top_logprobs\": 1,\n \"top_p\": 123,\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"role\": \"developer\",\n \"name\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"audio\": {\n \"format\": \"<string>\",\n \"voice\": \"<string>\"\n },\n \"frequency_penalty\": 123,\n \"logit_bias\": {},\n \"logprobs\": true,\n \"max_completion_tokens\": 1,\n \"metadata\": {},\n \"modalities\": [\n \"<string>\"\n ],\n \"n\": 1,\n \"parallel_tool_calls\": true,\n \"prediction\": {\n \"content\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"presence_penalty\": 123,\n \"prompt_cache_key\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"response_format\": \"<unknown>\",\n \"seed\": 123,\n \"service_tier\": \"<string>\",\n \"stop\": [\n \"<string>\"\n ],\n \"store\": true,\n \"stream\": true,\n \"stream_options\": {\n \"include_usage\": true\n },\n \"temperature\": 123,\n \"tool_choice\": \"<unknown>\",\n \"tools\": [\n {\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\",\n \"strict\": true\n },\n \"type\": \"<string>\"\n }\n ],\n \"top_logprobs\": 1,\n \"top_p\": 123,\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"choices": [
{
"finish_reason": "<string>",
"index": 1,
"message": {
"role": "<string>",
"annotations": "<unknown>",
"audio": "<unknown>",
"content": "<string>",
"refusal": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>"
}
]
},
"logprobs": "<unknown>"
}
],
"created": 1,
"id": "<string>",
"model": "<string>",
"object": "<string>",
"usage": {
"completion_tokens": 1,
"prompt_tokens": 1,
"total_tokens": 1,
"completion_tokens_details": "<unknown>",
"prompt_tokens_details": "<unknown>"
},
"service_tier": "<string>",
"system_fingerprint": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>"
}
}Body
An object specifying the format that the model must output. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. Setting to { "type": "json_schema", "json_schema": {...} } enables Structured Outputs which ensures the model will match your supplied JSON schema.
Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service. If set to 'auto', the system will utilize scale tier credits until they are exhausted. If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guarantee.
Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool.
Response
Chat completion created successfully
Represents a chat completion response returned by model, based on the provided input.