curl --request POST \
--url https://api.example.com/v1/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{
"tool_calls": [
{
"id": "<string>",
"index": 123,
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"reasoning_content": "<string>",
"content": {},
"name": "<string>",
"refusal": "<string>",
"annotations": [
{}
]
}
],
"stream_options": {
"include_usage": true
},
"top_p": 123,
"max_tokens": 123,
"max_completion_tokens": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": {
"key": 123
},
"top_logprobs": 123,
"response_format": {
"json_schema": {
"name": "<string>",
"description": "<string>",
"schema": {},
"strict": true
},
"type": "<string>"
},
"prompt_cache_key": "<string>",
"prompt_cache_retention": "<string>",
"safety_identifier": "<string>",
"tool_choice": {},
"parallel_tool_calls": true,
"service_tier": "<string>",
"reasoning_effort": "<string>",
"web_search_options": {},
"function_call": {},
"stream": true,
"temperature": 123,
"stop": {},
"n": 123,
"logprobs": true,
"seed": 123,
"user": "<string>",
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": true
}
}
],
"modalities": [
"<string>"
],
"audio": {},
"metadata": {
"key": "<string>"
},
"prediction": {},
"verbosity": "<string>",
"functions": [
{}
]
}
'import requests
url = "https://api.example.com/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"tool_calls": [
{
"id": "<string>",
"index": 123,
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"reasoning_content": "<string>",
"content": {},
"name": "<string>",
"refusal": "<string>",
"annotations": [{}]
}
],
"stream_options": { "include_usage": True },
"top_p": 123,
"max_tokens": 123,
"max_completion_tokens": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": { "key": 123 },
"top_logprobs": 123,
"response_format": {
"json_schema": {
"name": "<string>",
"description": "<string>",
"schema": {},
"strict": True
},
"type": "<string>"
},
"prompt_cache_key": "<string>",
"prompt_cache_retention": "<string>",
"safety_identifier": "<string>",
"tool_choice": {},
"parallel_tool_calls": True,
"service_tier": "<string>",
"reasoning_effort": "<string>",
"web_search_options": {},
"function_call": {},
"stream": True,
"temperature": 123,
"stop": {},
"n": 123,
"logprobs": True,
"seed": 123,
"user": "<string>",
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": True
}
}
],
"modalities": ["<string>"],
"audio": {},
"metadata": { "key": "<string>" },
"prediction": {},
"verbosity": "<string>",
"functions": [{}]
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [
{
tool_calls: [
{
id: '<string>',
index: 123,
type: '<string>',
function: {name: '<string>', arguments: '<string>'}
}
],
tool_call_id: '<string>',
reasoning_content: '<string>',
content: {},
name: '<string>',
refusal: '<string>',
annotations: [{}]
}
],
stream_options: {include_usage: true},
top_p: 123,
max_tokens: 123,
max_completion_tokens: 123,
frequency_penalty: 123,
presence_penalty: 123,
logit_bias: {key: 123},
top_logprobs: 123,
response_format: {
json_schema: {name: '<string>', description: '<string>', schema: {}, strict: true},
type: '<string>'
},
prompt_cache_key: '<string>',
prompt_cache_retention: '<string>',
safety_identifier: '<string>',
tool_choice: {},
parallel_tool_calls: true,
service_tier: '<string>',
reasoning_effort: '<string>',
web_search_options: {},
function_call: {},
stream: true,
temperature: 123,
stop: {},
n: 123,
logprobs: true,
seed: 123,
user: '<string>',
tools: [
{
type: '<string>',
function: {name: '<string>', description: '<string>', parameters: {}, strict: true}
}
],
modalities: ['<string>'],
audio: {},
metadata: {key: '<string>'},
prediction: {},
verbosity: '<string>',
functions: [{}]
})
};
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([
'model' => '<string>',
'messages' => [
[
'tool_calls' => [
[
'id' => '<string>',
'index' => 123,
'type' => '<string>',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
],
'tool_call_id' => '<string>',
'reasoning_content' => '<string>',
'content' => [
],
'name' => '<string>',
'refusal' => '<string>',
'annotations' => [
[
]
]
]
],
'stream_options' => [
'include_usage' => true
],
'top_p' => 123,
'max_tokens' => 123,
'max_completion_tokens' => 123,
'frequency_penalty' => 123,
'presence_penalty' => 123,
'logit_bias' => [
'key' => 123
],
'top_logprobs' => 123,
'response_format' => [
'json_schema' => [
'name' => '<string>',
'description' => '<string>',
'schema' => [
],
'strict' => true
],
'type' => '<string>'
],
'prompt_cache_key' => '<string>',
'prompt_cache_retention' => '<string>',
'safety_identifier' => '<string>',
'tool_choice' => [
],
'parallel_tool_calls' => true,
'service_tier' => '<string>',
'reasoning_effort' => '<string>',
'web_search_options' => [
],
'function_call' => [
],
'stream' => true,
'temperature' => 123,
'stop' => [
],
'n' => 123,
'logprobs' => true,
'seed' => 123,
'user' => '<string>',
'tools' => [
[
'type' => '<string>',
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => [
],
'strict' => true
]
]
],
'modalities' => [
'<string>'
],
'audio' => [
],
'metadata' => [
'key' => '<string>'
],
'prediction' => [
],
'verbosity' => '<string>',
'functions' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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 \"model\": \"<string>\",\n \"messages\": [\n {\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"index\": 123,\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"reasoning_content\": \"<string>\",\n \"content\": {},\n \"name\": \"<string>\",\n \"refusal\": \"<string>\",\n \"annotations\": [\n {}\n ]\n }\n ],\n \"stream_options\": {\n \"include_usage\": true\n },\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"max_completion_tokens\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {\n \"key\": 123\n },\n \"top_logprobs\": 123,\n \"response_format\": {\n \"json_schema\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"schema\": {},\n \"strict\": true\n },\n \"type\": \"<string>\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"prompt_cache_retention\": \"<string>\",\n \"safety_identifier\": \"<string>\",\n \"tool_choice\": {},\n \"parallel_tool_calls\": true,\n \"service_tier\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"web_search_options\": {},\n \"function_call\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"stop\": {},\n \"n\": 123,\n \"logprobs\": true,\n \"seed\": 123,\n \"user\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n }\n ],\n \"modalities\": [\n \"<string>\"\n ],\n \"audio\": {},\n \"metadata\": {\n \"key\": \"<string>\"\n },\n \"prediction\": {},\n \"verbosity\": \"<string>\",\n \"functions\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"index\": 123,\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"reasoning_content\": \"<string>\",\n \"content\": {},\n \"name\": \"<string>\",\n \"refusal\": \"<string>\",\n \"annotations\": [\n {}\n ]\n }\n ],\n \"stream_options\": {\n \"include_usage\": true\n },\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"max_completion_tokens\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {\n \"key\": 123\n },\n \"top_logprobs\": 123,\n \"response_format\": {\n \"json_schema\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"schema\": {},\n \"strict\": true\n },\n \"type\": \"<string>\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"prompt_cache_retention\": \"<string>\",\n \"safety_identifier\": \"<string>\",\n \"tool_choice\": {},\n \"parallel_tool_calls\": true,\n \"service_tier\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"web_search_options\": {},\n \"function_call\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"stop\": {},\n \"n\": 123,\n \"logprobs\": true,\n \"seed\": 123,\n \"user\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n }\n ],\n \"modalities\": [\n \"<string>\"\n ],\n \"audio\": {},\n \"metadata\": {\n \"key\": \"<string>\"\n },\n \"prediction\": {},\n \"verbosity\": \"<string>\",\n \"functions\": [\n {}\n ]\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["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"index\": 123,\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"reasoning_content\": \"<string>\",\n \"content\": {},\n \"name\": \"<string>\",\n \"refusal\": \"<string>\",\n \"annotations\": [\n {}\n ]\n }\n ],\n \"stream_options\": {\n \"include_usage\": true\n },\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"max_completion_tokens\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {\n \"key\": 123\n },\n \"top_logprobs\": 123,\n \"response_format\": {\n \"json_schema\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"schema\": {},\n \"strict\": true\n },\n \"type\": \"<string>\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"prompt_cache_retention\": \"<string>\",\n \"safety_identifier\": \"<string>\",\n \"tool_choice\": {},\n \"parallel_tool_calls\": true,\n \"service_tier\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"web_search_options\": {},\n \"function_call\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"stop\": {},\n \"n\": 123,\n \"logprobs\": true,\n \"seed\": 123,\n \"user\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n }\n ],\n \"modalities\": [\n \"<string>\"\n ],\n \"audio\": {},\n \"metadata\": {\n \"key\": \"<string>\"\n },\n \"prediction\": {},\n \"verbosity\": \"<string>\",\n \"functions\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"system_fingerprint": "<string>",
"service_tier": "<string>",
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"finish_reason": "<string>",
"index": 123,
"message": {
"role": "SYSTEM",
"tool_calls": [
{
"id": "<string>",
"index": 123,
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"reasoning_content": "<string>",
"content": {},
"name": "<string>",
"refusal": "<string>",
"annotations": [
{}
]
},
"logprobs": {
"content": [
{
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"refusal": [
{
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
]
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123,
"audio_tokens": 123
},
"completion_tokens_details": {
"reasoning_tokens": 123,
"audio_tokens": 123,
"accepted_prediction_tokens": 123,
"rejected_prediction_tokens": 123
},
"ephemeral_5m_input_tokens": 123,
"ephemeral_1h_input_tokens": 123,
"web_search_requests": 123
}
}OpenAI 格式
创建聊天补全请求,兼容 OpenAI Chat Completions 协议,支持流式和非流式响应
curl --request POST \
--url https://api.example.com/v1/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{
"tool_calls": [
{
"id": "<string>",
"index": 123,
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"reasoning_content": "<string>",
"content": {},
"name": "<string>",
"refusal": "<string>",
"annotations": [
{}
]
}
],
"stream_options": {
"include_usage": true
},
"top_p": 123,
"max_tokens": 123,
"max_completion_tokens": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": {
"key": 123
},
"top_logprobs": 123,
"response_format": {
"json_schema": {
"name": "<string>",
"description": "<string>",
"schema": {},
"strict": true
},
"type": "<string>"
},
"prompt_cache_key": "<string>",
"prompt_cache_retention": "<string>",
"safety_identifier": "<string>",
"tool_choice": {},
"parallel_tool_calls": true,
"service_tier": "<string>",
"reasoning_effort": "<string>",
"web_search_options": {},
"function_call": {},
"stream": true,
"temperature": 123,
"stop": {},
"n": 123,
"logprobs": true,
"seed": 123,
"user": "<string>",
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": true
}
}
],
"modalities": [
"<string>"
],
"audio": {},
"metadata": {
"key": "<string>"
},
"prediction": {},
"verbosity": "<string>",
"functions": [
{}
]
}
'import requests
url = "https://api.example.com/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"tool_calls": [
{
"id": "<string>",
"index": 123,
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"reasoning_content": "<string>",
"content": {},
"name": "<string>",
"refusal": "<string>",
"annotations": [{}]
}
],
"stream_options": { "include_usage": True },
"top_p": 123,
"max_tokens": 123,
"max_completion_tokens": 123,
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": { "key": 123 },
"top_logprobs": 123,
"response_format": {
"json_schema": {
"name": "<string>",
"description": "<string>",
"schema": {},
"strict": True
},
"type": "<string>"
},
"prompt_cache_key": "<string>",
"prompt_cache_retention": "<string>",
"safety_identifier": "<string>",
"tool_choice": {},
"parallel_tool_calls": True,
"service_tier": "<string>",
"reasoning_effort": "<string>",
"web_search_options": {},
"function_call": {},
"stream": True,
"temperature": 123,
"stop": {},
"n": 123,
"logprobs": True,
"seed": 123,
"user": "<string>",
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": True
}
}
],
"modalities": ["<string>"],
"audio": {},
"metadata": { "key": "<string>" },
"prediction": {},
"verbosity": "<string>",
"functions": [{}]
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [
{
tool_calls: [
{
id: '<string>',
index: 123,
type: '<string>',
function: {name: '<string>', arguments: '<string>'}
}
],
tool_call_id: '<string>',
reasoning_content: '<string>',
content: {},
name: '<string>',
refusal: '<string>',
annotations: [{}]
}
],
stream_options: {include_usage: true},
top_p: 123,
max_tokens: 123,
max_completion_tokens: 123,
frequency_penalty: 123,
presence_penalty: 123,
logit_bias: {key: 123},
top_logprobs: 123,
response_format: {
json_schema: {name: '<string>', description: '<string>', schema: {}, strict: true},
type: '<string>'
},
prompt_cache_key: '<string>',
prompt_cache_retention: '<string>',
safety_identifier: '<string>',
tool_choice: {},
parallel_tool_calls: true,
service_tier: '<string>',
reasoning_effort: '<string>',
web_search_options: {},
function_call: {},
stream: true,
temperature: 123,
stop: {},
n: 123,
logprobs: true,
seed: 123,
user: '<string>',
tools: [
{
type: '<string>',
function: {name: '<string>', description: '<string>', parameters: {}, strict: true}
}
],
modalities: ['<string>'],
audio: {},
metadata: {key: '<string>'},
prediction: {},
verbosity: '<string>',
functions: [{}]
})
};
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([
'model' => '<string>',
'messages' => [
[
'tool_calls' => [
[
'id' => '<string>',
'index' => 123,
'type' => '<string>',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
],
'tool_call_id' => '<string>',
'reasoning_content' => '<string>',
'content' => [
],
'name' => '<string>',
'refusal' => '<string>',
'annotations' => [
[
]
]
]
],
'stream_options' => [
'include_usage' => true
],
'top_p' => 123,
'max_tokens' => 123,
'max_completion_tokens' => 123,
'frequency_penalty' => 123,
'presence_penalty' => 123,
'logit_bias' => [
'key' => 123
],
'top_logprobs' => 123,
'response_format' => [
'json_schema' => [
'name' => '<string>',
'description' => '<string>',
'schema' => [
],
'strict' => true
],
'type' => '<string>'
],
'prompt_cache_key' => '<string>',
'prompt_cache_retention' => '<string>',
'safety_identifier' => '<string>',
'tool_choice' => [
],
'parallel_tool_calls' => true,
'service_tier' => '<string>',
'reasoning_effort' => '<string>',
'web_search_options' => [
],
'function_call' => [
],
'stream' => true,
'temperature' => 123,
'stop' => [
],
'n' => 123,
'logprobs' => true,
'seed' => 123,
'user' => '<string>',
'tools' => [
[
'type' => '<string>',
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => [
],
'strict' => true
]
]
],
'modalities' => [
'<string>'
],
'audio' => [
],
'metadata' => [
'key' => '<string>'
],
'prediction' => [
],
'verbosity' => '<string>',
'functions' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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 \"model\": \"<string>\",\n \"messages\": [\n {\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"index\": 123,\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"reasoning_content\": \"<string>\",\n \"content\": {},\n \"name\": \"<string>\",\n \"refusal\": \"<string>\",\n \"annotations\": [\n {}\n ]\n }\n ],\n \"stream_options\": {\n \"include_usage\": true\n },\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"max_completion_tokens\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {\n \"key\": 123\n },\n \"top_logprobs\": 123,\n \"response_format\": {\n \"json_schema\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"schema\": {},\n \"strict\": true\n },\n \"type\": \"<string>\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"prompt_cache_retention\": \"<string>\",\n \"safety_identifier\": \"<string>\",\n \"tool_choice\": {},\n \"parallel_tool_calls\": true,\n \"service_tier\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"web_search_options\": {},\n \"function_call\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"stop\": {},\n \"n\": 123,\n \"logprobs\": true,\n \"seed\": 123,\n \"user\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n }\n ],\n \"modalities\": [\n \"<string>\"\n ],\n \"audio\": {},\n \"metadata\": {\n \"key\": \"<string>\"\n },\n \"prediction\": {},\n \"verbosity\": \"<string>\",\n \"functions\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"index\": 123,\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"reasoning_content\": \"<string>\",\n \"content\": {},\n \"name\": \"<string>\",\n \"refusal\": \"<string>\",\n \"annotations\": [\n {}\n ]\n }\n ],\n \"stream_options\": {\n \"include_usage\": true\n },\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"max_completion_tokens\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {\n \"key\": 123\n },\n \"top_logprobs\": 123,\n \"response_format\": {\n \"json_schema\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"schema\": {},\n \"strict\": true\n },\n \"type\": \"<string>\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"prompt_cache_retention\": \"<string>\",\n \"safety_identifier\": \"<string>\",\n \"tool_choice\": {},\n \"parallel_tool_calls\": true,\n \"service_tier\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"web_search_options\": {},\n \"function_call\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"stop\": {},\n \"n\": 123,\n \"logprobs\": true,\n \"seed\": 123,\n \"user\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n }\n ],\n \"modalities\": [\n \"<string>\"\n ],\n \"audio\": {},\n \"metadata\": {\n \"key\": \"<string>\"\n },\n \"prediction\": {},\n \"verbosity\": \"<string>\",\n \"functions\": [\n {}\n ]\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["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"index\": 123,\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"reasoning_content\": \"<string>\",\n \"content\": {},\n \"name\": \"<string>\",\n \"refusal\": \"<string>\",\n \"annotations\": [\n {}\n ]\n }\n ],\n \"stream_options\": {\n \"include_usage\": true\n },\n \"top_p\": 123,\n \"max_tokens\": 123,\n \"max_completion_tokens\": 123,\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {\n \"key\": 123\n },\n \"top_logprobs\": 123,\n \"response_format\": {\n \"json_schema\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"schema\": {},\n \"strict\": true\n },\n \"type\": \"<string>\"\n },\n \"prompt_cache_key\": \"<string>\",\n \"prompt_cache_retention\": \"<string>\",\n \"safety_identifier\": \"<string>\",\n \"tool_choice\": {},\n \"parallel_tool_calls\": true,\n \"service_tier\": \"<string>\",\n \"reasoning_effort\": \"<string>\",\n \"web_search_options\": {},\n \"function_call\": {},\n \"stream\": true,\n \"temperature\": 123,\n \"stop\": {},\n \"n\": 123,\n \"logprobs\": true,\n \"seed\": 123,\n \"user\": \"<string>\",\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n }\n ],\n \"modalities\": [\n \"<string>\"\n ],\n \"audio\": {},\n \"metadata\": {\n \"key\": \"<string>\"\n },\n \"prediction\": {},\n \"verbosity\": \"<string>\",\n \"functions\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"system_fingerprint": "<string>",
"service_tier": "<string>",
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"finish_reason": "<string>",
"index": 123,
"message": {
"role": "SYSTEM",
"tool_calls": [
{
"id": "<string>",
"index": 123,
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"reasoning_content": "<string>",
"content": {},
"name": "<string>",
"refusal": "<string>",
"annotations": [
{}
]
},
"logprobs": {
"content": [
{
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"refusal": [
{
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
],
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
]
}
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"prompt_tokens_details": {
"cached_tokens": 123,
"audio_tokens": 123
},
"completion_tokens_details": {
"reasoning_tokens": 123,
"audio_tokens": 123,
"accepted_prediction_tokens": 123,
"rejected_prediction_tokens": 123
},
"ephemeral_5m_input_tokens": 123,
"ephemeral_1h_input_tokens": 123,
"web_search_requests": 123
}
}功能特性
- 支持流式(SSE)和非流式两种响应模式
- 支持多模态输入(文本、图片等)
- 支持函数调用与工具调用(Function/Tool Calling)
- 支持结构化输出(JSON Schema)
- 支持推理模式配置(reasoning_effort)
- 支持网络搜索选项
使用场景
适用于需要与 OpenAI 兼容模型进行对话交互的场景,包括:- 单轮或多轮对话
- 函数调用与工具编排
- 结构化 JSON 输出
- 流式实时响应
认证方式
在请求头中携带Authorization 字段,格式为 Bearer YOUR_API_KEY。
快速示例
import requests
url = "https://api.haitoken.ai/v1/chat/completions"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "你好,请介绍一下自己"}
]
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
const response = await fetch('https://api.haitoken.ai/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [
{ role: 'user', content: '你好,请介绍一下自己' }
]
})
});
const data = await response.json();
console.log(data);
curl -X POST 'https://api.haitoken.ai/v1/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "你好,请介绍一下自己"}
]
}'
请求体
模型 ID,如 gpt-4o、deepseek-chat 等
消息列表
Show child attributes
Show child attributes
流式响应选项(仅在 stream=true 时使用)
Show child attributes
Show child attributes
核采样,0-1 之间
生成的最大 token 数量(已弃用,建议使用 max_completion_tokens)
生成的最大 token 数量(包括可见输出 token 和推理 token)
频率惩罚,-2.0 到 2.0
存在惩罚,-2.0 到 2.0
修改指定 token 出现概率的映射
Show child attributes
Show child attributes
每个 token 位置返回的最可能 token 的最大数量(0-20)
响应格式,支持 "text"、"json_object"、"json_schema"
Show child attributes
Show child attributes
稳定标识符,用于缓存优化
缓存保留策略:"in_memory" 或 "24h"
安全标识符,用于检测违规用户
控制模型调用哪个工具,可以是字符串("none"/"auto"/"required")或对象
是否启用并行工具调用
服务层级:"auto"、"default"、"flex"、"scale"、"priority"
推理努力程度:"none"、"minimal"、"low"、"medium"、"high"、"xhigh"
网络搜索选项
已弃用:函数调用控制
是否启用流式输出
采样温度,0-2 之间,值越高输出越随机
停止序列
每个输入消息生成的聊天补全选择数量
是否返回输出 token 的对数概率
用于确定性采样的种子值
用户标识(已弃用,建议使用 prompt_cache_key)
模型可调用的工具列表
Show child attributes
Show child attributes
输出类型列表:["text"] 或 ["text", "audio"]
音频输出参数
元数据,最多16个键值对
Show child attributes
Show child attributes
预测输出内容
响应详细程度:"low"、"medium"、"high"
已弃用:函数定义列表