logo

Chat Completions

POST /v1/chat/completions は主要な OpenAI 互換チャットインターフェースです。

curl https://llmoxy.com/v1/chat/completions \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      { "role": "system", "content": "Be concise." },
      { "role": "user", "content": "What is LLMoxy?" }
    ]
  }'

リクエストボディ

常用フィールド:

フィールド説明
model必須。モデル ID。
messages必須。会話メッセージの配列。
temperature, top_p, n, stopサンプリング制御パラメータ。互換性のある上流に渡されます。
max_tokens, max_completion_tokens出力トークン制限。
streamtrue に設定すると SSE ストリーミングを有効化。
stream_options.include_usage上流が対応している場合、ストリーミングレスポンスに usage を含める。
tools, tool_choiceOpenAI 互換のツール呼び出し。
response_format対応モデルで構造化出力をリクエスト。
reasoning_effort推論対応モデルで lowmediumhigh を使用可能。
modalities, audioマルチモーダル音声対応モデルで使用可能。
userオプション。エンドユーザー識別用。

モデルごとに対応するパラメータが異なります。レスポンスでパラメータが非対応と表示された場合、削除するか別のモデルを使用してください。

ストリーミング出力

{
  "model": "gpt-4o-mini",
  "stream": true,
  "messages": [
    { "role": "user", "content": "Stream one sentence." }
  ]
}

レスポンスは OpenAI スタイルの SSE チャンクを使用し、[DONE] で終了します。

ツール呼び出し

{
  "model": "gpt-4o-mini",
  "messages": [
    { "role": "user", "content": "What is the weather in Singapore?" }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string" }
          },
          "required": ["city"]
        }
      }
    }
  ]
}

ツール呼び出しに対応したモデルはツール定義を受け取り、OpenAI 互換のツール呼び出しレスポンスを返します。

旧 Completions

従来のテキスト補完クライアントは POST /v1/completions を使用できます。