curl -X POST https://api-llm.sunra.ai/v1/chat/completions \
-H "Authorization: Bearer <SUNRA_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-2.5-flash",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'
import requests
response = requests.post(
"https://api-llm.sunra.ai/v1/chat/completions",
headers={
"Authorization": "Bearer <SUNRA_KEY>",
"Content-Type": "application/json"
},
json={
"model": "google/gemini-2.5-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
}
)
print(response.json())
const response = await fetch("https://api-llm.sunra.ai/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer <SUNRA_KEY>",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "google/gemini-2.5-flash",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the capital of France?" }
]
})
});
const data = await response.json();
console.log(data);
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677652288,
"model": "google/gemini-2.5-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop",
"logprobs": null
}
],
"system_fingerprint": "fp_44709d6fcb",
"usage": {
"prompt_tokens": 25,
"completion_tokens": 8,
"total_tokens": 33
}
}
LLM
Create a chat completion
POST
/
v1
/
chat
/
completions
curl -X POST https://api-llm.sunra.ai/v1/chat/completions \
-H "Authorization: Bearer <SUNRA_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-2.5-flash",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'
import requests
response = requests.post(
"https://api-llm.sunra.ai/v1/chat/completions",
headers={
"Authorization": "Bearer <SUNRA_KEY>",
"Content-Type": "application/json"
},
json={
"model": "google/gemini-2.5-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
}
)
print(response.json())
const response = await fetch("https://api-llm.sunra.ai/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer <SUNRA_KEY>",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "google/gemini-2.5-flash",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the capital of France?" }
]
})
});
const data = await response.json();
console.log(data);
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677652288,
"model": "google/gemini-2.5-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop",
"logprobs": null
}
],
"system_fingerprint": "fp_44709d6fcb",
"usage": {
"prompt_tokens": 25,
"completion_tokens": 8,
"total_tokens": 33
}
}
发送请求以获取给定聊天对话的模型响应。支持流式和非流式模式。兼容 OpenAI Chat Completions API 格式。
认证
string
必填
Bearer 令牌。在 Authorization 请求头中使用您的 API 密钥作为 Bearer 令牌。格式:
Bearer <SUNRA_KEY>请求
此端点接受一个 JSON 对象。object[]
必填
string
必填
用于补全的模型。在 sunra.ai/models 浏览可用模型。
object
可选的 Provider 路由偏好。省略时使用自动路由。支持的字段和 Provider 查询方式见 Provider 路由。
boolean
默认值:false
如果设置为
true,将以服务器发送事件(SSE)的方式发送部分消息增量。流式请求受空闲超时与生命周期上限约束,见输出上限与流生命周期。integer
补全中生成的最大令牌数。输入令牌和生成令牌的总长度受模型上下文长度的限制。超过模型自身输出上限的值会返回
400,而不会被静默削平。number
默认值:1
采样温度,介于 0 到 2 之间。较高的值(如 0.8)使输出更随机,较低的值(如 0.2)使其更集中和确定性。
number
默认值:1
核采样参数(0-1)。温度采样的替代方案,模型会考虑具有 top_p 概率质量的令牌。
number
默认值:0
介于 -2.0 和 2.0 之间的数字。正值会根据新令牌在文本中的现有频率进行惩罚,降低模型逐字重复相同内容的可能性。
number
默认值:0
介于 -2.0 和 2.0 之间的数字。正值会根据新令牌是否出现在文本中进行惩罚,增加模型谈论新话题的可能性。
string | string[]
最多 4 个序列,API 将在这些序列处停止生成更多令牌。
integer
默认值:1
为每条输入消息生成多少个聊天补全选择。
boolean
默认值:false
是否返回输出令牌的对数概率。如果为 true,则返回消息内容中每个输出令牌的对数概率。
integer
一个介于 0 到 20 之间的整数,指定在每个令牌位置返回最可能的令牌数量。使用此参数时,
logprobs 必须设置为 true。object
integer
如果指定,系统将尽最大努力进行确定性采样,使得具有相同种子和参数的重复请求应返回相同的结果。
object[]
string | object
控制模型调用哪个(如果有的话)工具。
none 表示模型不会调用任何工具。auto 表示模型可以在生成消息或调用工具之间选择。required 表示模型必须调用一个或多个工具。也可以通过 {"type": "function", "function": {"name": "my_function"}} 指定特定函数。boolean
默认值:true
是否在工具使用期间启用并行函数调用。
string
代表您的最终用户的唯一标识符,可帮助监控和检测滥用行为。
响应
成功的聊天补全响应。string
聊天补全的唯一标识符。
string
对象类型。始终为
chat.completion。integer
聊天补全创建时的 Unix 时间戳(秒)。
string
用于聊天补全的模型。
object[]
聊天补全选择列表。如果
n 大于 1,则可以有多个选择。显示 属性
显示 属性
integer
选择在列表中的索引。
object
string
模型停止生成令牌的原因。可以是
stop、length、tool_calls 或 content_filter。object | null
该选择的对数概率信息。
string | null
此指纹表示模型运行的后端配置。可与
seed 参数一起使用,以了解后端何时发生了更改。curl -X POST https://api-llm.sunra.ai/v1/chat/completions \
-H "Authorization: Bearer <SUNRA_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-2.5-flash",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'
import requests
response = requests.post(
"https://api-llm.sunra.ai/v1/chat/completions",
headers={
"Authorization": "Bearer <SUNRA_KEY>",
"Content-Type": "application/json"
},
json={
"model": "google/gemini-2.5-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
}
)
print(response.json())
const response = await fetch("https://api-llm.sunra.ai/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer <SUNRA_KEY>",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "google/gemini-2.5-flash",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the capital of France?" }
]
})
});
const data = await response.json();
console.log(data);
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677652288,
"model": "google/gemini-2.5-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop",
"logprobs": null
}
],
"system_fingerprint": "fp_44709d6fcb",
"usage": {
"prompt_tokens": 25,
"completion_tokens": 8,
"total_tokens": 33
}
}
⌘I