curl -X POST https://api-llm.sunra.ai/v1/chat/completions \
-H "Authorization: Bearer <SUNRA_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"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": "openai/gpt-4o",
"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: "openai/gpt-4o",
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": "openai/gpt-4o",
"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": "openai/gpt-4o",
"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": "openai/gpt-4o",
"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: "openai/gpt-4o",
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": "openai/gpt-4o",
"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 令牌。Format:
Bearer <SUNRA_KEY>請求
此端點接受一個 JSON 物件。object[]
必填
string
必填
用於補全的模型。在 sunra.ai/models 瀏覽可用模型。
boolean
預設值:false
如果設為
true,將以伺服器傳送事件(SSE)的方式傳送部分訊息增量。integer
補全中生成的最大令牌數。輸入令牌和生成令牌的總長度受模型上下文長度的限制。
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": "openai/gpt-4o",
"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": "openai/gpt-4o",
"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: "openai/gpt-4o",
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": "openai/gpt-4o",
"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