Chat Completions
チャット補完レスポンスを作成します。テキスト生成、マルチモーダル入力、ファンクションコーリング、ストリーミングレスポンスなどの機能に対応しています。
エンドポイント
POST https://api.ofox.ai/v1/chat/completionsリクエストパラメータ
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | ✅ | モデル識別子(例:openai/gpt-4o) |
messages | array | ✅ | メッセージ配列 |
temperature | number | — | サンプリング温度 0-2、デフォルト 1 |
max_tokens | number | — | 最大生成トークン数 |
stream | boolean | — | ストリーミングレスポンスを有効にするか |
top_p | number | — | 核サンプリングパラメータ |
frequency_penalty | number | — | 頻度ペナルティ -2 から 2 |
presence_penalty | number | — | 存在ペナルティ -2 から 2 |
tools | array | — | 利用可能なツール定義(Function Calling) |
tool_choice | string/object | — | ツール選択戦略 |
response_format | object | — | レスポンス形式(JSON Mode) |
provider | object | — | OfoxAI拡張:ルーティングとフォールバック設定 |
Message形式
interface Message {
role: 'system' | 'user' | 'assistant' | 'tool'
content: string | ContentPart[] // テキストまたはマルチモーダルコンテンツ
name?: string
tool_calls?: ToolCall[] // assistantメッセージのツールコール
tool_call_id?: string // toolメッセージのコールID
}
// マルチモーダルコンテンツ
type ContentPart =
| { type: 'text'; text: string }
| { type: 'image_url'; image_url: { url: string; detail?: 'auto' | 'low' | 'high' } }リクエスト例
cURL
Terminal
curl https://api.ofox.ai/v1/chat/completions \
-H "Authorization: Bearer $OFOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{"role": "system", "content": "あなたは親切なアシスタントです。"},
{"role": "user", "content": "API Gatewayとは何か説明してください"}
],
"temperature": 0.7
}'レスポンス形式
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1703123456,
"model": "openai/gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "API Gateway(APIゲートウェイ)とは..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}ストリーミングレスポンス
stream: true を設定してSSEストリーミングレスポンスを有効にします:
Python
stream.py
stream = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "物語を聞かせてください"}],
stream=True
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)ストリーミングレスポンス形式
各chunkはSSE経由で送信されます:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"こん"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"にちは"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]マルチモーダル入力(ビジョン)
画像を送信してモデルに分析させます:
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "この画像には何が写っていますか?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
)ビジョン機能に対応しているモデルは以下の通りです:openai/gpt-4o、anthropic/claude-sonnet-4.5、google/gemini-3-flash-preview 等。
詳細はビジョンガイドをご覧ください。
Function Calling
詳細はファンクションコーリングガイドをご覧ください。
Last updated on