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トークン。APIキーをAuthorizationヘッダーの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)。temperatureサンプリングの代替として、モデルがtop_pの確率質量を持つトークンを考慮します。
number
デフォルト:0
-2.0から2.0の間の数値。正の値は、テキスト中の既存の頻度に基づいて新しいトークンにペナルティを課し、モデルが同じ行をそのまま繰り返す可能性を低下させます。
number
デフォルト:0
-2.0から2.0の間の数値。正の値は、テキスト中に既に出現しているかどうかに基づいて新しいトークンにペナルティを課し、モデルが新しいトピックについて話す可能性を高めます。
string | string[]
APIがそれ以上トークンを生成するのを停止する最大4つのシーケンス。
integer
デフォルト:1
各入力メッセージに対して生成するチャット補完の選択肢の数。
boolean
デフォルト:false
出力トークンの対数確率を返すかどうか。trueの場合、メッセージのコンテンツに返される各出力トークンの対数確率を返します。
integer
各トークン位置で返す最も可能性の高いトークンの数を指定する0から20の整数。このパラメータを使用する場合は、
logprobsをtrueに設定する必要があります。object
integer
指定した場合、システムは決定論的にサンプリングするよう最善を尽くします。同じseedとパラメータを使用した繰り返しのリクエストは同じ結果を返すはずです。
object[]
string | object
モデルがどのツールを呼び出すかを制御します。
noneはモデルがツールを呼び出さないことを意味します。autoはモデルがメッセージ生成とツール呼び出しのいずれかを選択できることを意味します。requiredはモデルが1つ以上のツールを呼び出す必要があることを意味します。{"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
選択肢の対数確率情報。
object
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