# Chat Completions

> LLMoxy を介して OpenAI 互換の Chat Completions インターフェースを使用します。

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

```bash
curl https://llmoxy.com/v1/chat/completions \
  -H "Authorization: Bearer <LLMOXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.7",
    "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` | 出力トークン制限。 |
| `stream` | `true` に設定すると SSE ストリーミングを有効化。 |
| `stream_options.include_usage` | 上流が対応している場合、ストリーミングレスポンスに usage を含める。 |
| `tools`, `tool_choice` | OpenAI 互換のツール呼び出し。 |
| `response_format` | 対応モデルで構造化出力をリクエスト。 |
| `reasoning_effort` | 推論対応モデルで `low`、`medium`、`high` を使用可能。 |
| `modalities`, `audio` | マルチモーダル音声対応モデルで使用可能。 |
| `user` | オプション。エンドユーザー識別用。 |

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

## ストリーミング出力

```json
{
  "model": "grok-4.7",
  "stream": true,
  "messages": [
    { "role": "user", "content": "Stream one sentence." }
  ]
}
```

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

## ツール呼び出し

```json
{
  "model": "grok-4.7",
  "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` を使用できます。

これは https://jp.llmoxy.com/docs/api-reference/chat-completions の markdown 版です。
