> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixroute.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Completions（OpenAI）

> OpenAI互換LLMに対応した汎用テキストチャットAPI

## はじめに

OpenAI互換の大規模言語モデルをサポートする汎用テキストチャットインターフェースです。統一されたAPIを通じて、MixRoute経由でOpenAI、Claude、DeepSeek、Grok、Qwenなど、多くの主要モデルにアクセスできます。

<Info>
  `gpt-6.1-sol`: 関数呼び出しと`reasoning.effort="max"`にはResponsesを使用してください。Chat Completionsはツールなしのリクエストを受け付け、`reasoning_effort`の値として`low`、`medium`、`high`、`xhigh`に対応しています。どちらのインターフェースも`none`と`minimal`は受け付けません。`temperature`、`top_p`および対数確率のオプションは省略してください。[GPT 6.1 Sol](/ja/model-api/openai/gpt-6.1-sol)を参照してください。
</Info>

## 認証

Bearerトークン。例: `Bearer sk-xxxxxxxxxx`

## リクエストパラメーター

<ParamField body="model" type="string" required>
  モデルマーケットプレイスに対応するモデル識別子。

  <Tip>
    MixRouteは複数のモデルに対応しています。完全な一覧は[モデルマーケットプレイス](https://console.mixroute.ai/models)で確認してください。
  </Tip>
</ParamField>

<ParamField body="messages" type="array" required>
  会話メッセージの配列。各メッセージには`role`（user/system/assistant）と`content`を含めます。
</ParamField>

<ParamField body="temperature" type="number">
  ランダム性の制御。0〜2。値を高くすると、応答のランダム性が増します。
</ParamField>

<ParamField body="stream" type="boolean">
  ストリーミング出力を有効にし、SSE形式のデータをチャンク単位で返します
</ParamField>

<ParamField body="max_tokens" type="integer">
  生成するトークンの最大数。レスポンスの長さを制御します
</ParamField>

<ParamField body="response_format" type="object">
  出力形式。`text`または`json_object` / `json_schema`に対応
</ParamField>

<ParamField body="top_p" type="number">
  Nucleusサンプリングのパラメータ。範囲は0～1で、temperatureの代わりに使用します。値を小さくすると、サンプリングがより保守的になります
</ParamField>

<ParamField body="frequency_penalty" type="number">
  頻度ペナルティ。-2～2。正の値は、頻出するトークンの繰り返しを減らします
</ParamField>

<ParamField body="presence_penalty" type="number">
  存在ペナルティ。-2〜2。正の値を指定すると、新しい話題に言及しやすくなります。
</ParamField>

<ParamField body="stop" type="string | array">
  停止シーケンス。指定した文字列が現れると生成を停止します
</ParamField>

<ParamField body="seed" type="integer">
  乱数シード。同じシードを使用すると、結果の一貫性が高まります。
</ParamField>

<ParamField body="user" type="string">
  監視とレート制限に使用するエンドユーザー識別子
</ParamField>

<ParamField body="n" type="integer">
  プロンプトごとの応答候補数。デフォルトは1です。
</ParamField>

<ParamField body="logit_bias" type="object">
  トークンバイアス。トークンIDをバイアス値（-100～100）に対応付けます
</ParamField>

<ParamField body="tools" type="array">
  ツール定義のリスト。各ツールには`type`と`function`を含める必要があります。
</ParamField>

<ParamField body="tool_choice" type="string">
  ツールの選択方法：`"auto"` / `"none"` / `"required"`、またはツール名を指定
</ParamField>

## 基本的な例

<Tabs>
  <Tab title="非ストリーミングリクエスト">
    ```bash theme={null}
    curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-xxxxxxxxxx" \
      -d '{
        "model": "gpt-5.5",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant"},
          {"role": "user", "content": "Please briefly introduce artificial intelligence"}
        ],
        "temperature": 0.7
      }'
    ```
  </Tab>

  <Tab title="ストリーミングリクエスト（SSE）">
    ```bash theme={null}
    curl -N -X POST "https://api.mixroute.ai/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-xxxxxxxxxx" \
      -d '{
        "model": "doubao-seed-1-8-251228",
        "stream": true,
        "messages": [
          {"role": "system", "content": "You are a helpful assistant"},
          {"role": "user", "content": "Please briefly introduce artificial intelligence"}
        ]
      }'
    ```
  </Tab>

  <Tab title="Pythonの例">
    ```python theme={null}
    from openai import OpenAI

    client = OpenAI(
        api_key="sk-xxxxxxxxxx",
        base_url="https://api.mixroute.ai/v1"
    )

    # Non-streaming
    completion = client.chat.completions.create(
        model="gpt-5.5",
        messages=[
            {"role": "system", "content": "You are a helpful assistant"},
            {"role": "user", "content": "Please briefly introduce artificial intelligence"}
        ],
        temperature=0.7
    )
    print(completion.choices[0].message.content)

    # Streaming
    stream = client.chat.completions.create(
        model="doubao-seed-1-8-251228",
        messages=[
            {"role": "user", "content": "Please briefly introduce artificial intelligence"}
        ],
        stream=True
    )
    for chunk in stream:
        if chunk.choices[0].delta.content:
            print(chunk.choices[0].delta.content, end="")
    ```
  </Tab>
</Tabs>

## 高度な機能

<Tabs>
  <Tab title="ツール呼び出し">
    OpenAI互換のツール呼び出し形式に対応しています。

    ```bash theme={null}
    curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-xxxxxxxxxx" \
      -d '{
        "model": "gpt-5.5",
        "messages": [
          {"role": "user", "content": "What is the weather in Shanghai?"}
        ],
        "tools": [
          {
            "type": "function",
            "function": {
              "name": "get_weather",
              "description": "Get weather information by city",
              "parameters": {
                "type": "object",
                "properties": {
                  "city": {"type": "string"}
                },
                "required": ["city"]
              }
            }
          }
        ],
        "tool_choice": "auto"
      }'
    ```
  </Tab>

  <Tab title="構造化出力">
    JSON Schemaを使用して、モデルの出力形式を制約します。

    ```bash theme={null}
    curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-xxxxxxxxxx" \
      -d '{
        "model": "gpt-5.5",
        "response_format": {
          "type": "json_schema",
          "json_schema": {
            "name": "Answer",
            "schema": {
              "type": "object",
              "properties": {
                "summary": {"type": "string"}
              },
              "required": ["summary"]
            }
          }
        },
        "messages": [
          {"role": "user", "content": "Return a JSON with a summary field"}
        ]
      }'
    ```
  </Tab>

  <Tab title="思考機能">
    <Tabs>
      <Tab title="DeepSeek">
        DeepSeekシリーズは、深い思考機能に対応しています。

        ```bash theme={null}
        curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer sk-xxxxxxxxxx" \
          -d '{
            "model": "deepseek-v4-pro",
            "messages": [
              {"role": "user", "content": "Analyze this math problem: if x^2 + 2x - 3 = 0, find x"}
            ],
            "temperature": 0.6
          }'
        ```

        レスポンスには、思考過程を示す`reasoning_content`フィールドが含まれます。
      </Tab>

      <Tab title="Qwen">
        Qwenシリーズは思考機能に対応しています。

        ```bash theme={null}
        curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer sk-xxxxxxxxxx" \
          -d '{
            "model": "qwen3.7-max",
            "messages": [
              {"role": "user", "content": "Analyze the development trends of artificial intelligence"}
            ],
            "enable_thinking": true
          }'
        ```
      </Tab>

      <Tab title="GPT-5.6">
        GPT-5.6シリーズ（`gpt-5.6-sol` / `gpt-5.6-terra` / `gpt-5.6-luna`）は、高度な推論設定に対応しています。

        * `reasoning.mode`: 実行モード。`"standard"`（デフォルト）または`"pro"`。Pro Modeではモデルが追加の処理を行い、難しいタスクでの信頼性を高めます
        * `reasoning.effort`：推論の強度：`none` / `low` / `medium` / `high` / `xhigh` / `max`（`max`は新しいレベル）

        ```bash theme={null}
        curl https://api.mixroute.ai/v1/responses \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer sk" \
          -d '{
            "model": "gpt-5.6-luna",
            "reasoning": {
              "mode": "pro",
        	"effort":"max"
            },
            "input": "Analyze the potential risks of this database migration plan."
          }'
        ```
      </Tab>

      <Tab title="Gemini">
        Gemini 2.0 Flash Thinkingは推論機能をサポートします。

        ```bash theme={null}
        curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer sk-xxxxxxxxxx" \
          -d '{
            "model": "gemini-2.0-flash-thinking-exp",
            "messages": [
              {"role": "user", "content": "Explain the basic principles of quantum computing"}
            ]
          }'
        ```
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="Qwenの拡張機能">
    Qwenは追加の拡張パラメーターをサポートします。

    ```bash theme={null}
    curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-xxxxxxxxxx" \
      -d '{
        "model": "qwen3.7-max",
        "messages": [
          {"role": "user", "content": "Hello"}
        ],
        "enable_search": true,
        "search_options": {
          "search_strategy": "standard",
          "forced_search": false
        }
      }'
    ```

    | パラメーター | 説明 |
    | - | - |
    | `enable_search` | ウェブ検索を有効にする |
    | `search_options.search_strategy` | 検索戦略: `standard`/`pro` |
    | `search_options.forced_search` | 検索を強制 |
  </Tab>

  <Tab title="ウェブ検索">
    <Tabs>
      <Tab title="Claudeの検索">
        Claudeモデルはウェブ検索機能に対応しています。

        ```bash theme={null}
        curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer sk-xxxxxxxxxx" \
          -d '{
            "model": "claude-sonnet-5",
            "messages": [
              {"role": "user", "content": "What are today major news?"}
            ],
            "tools": [
              {
                "type": "web_search_20250305",
                "name": "web_search",
                "max_uses": 5
              }
            ]
          }'
        ```
      </Tab>

      <Tab title="Grok検索">
        Grokモデルはリアルタイムのウェブ検索に対応しています。

        ```bash theme={null}
        curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer sk-xxxxxxxxxx" \
          -d '{
            "model": "grok-3",
            "messages": [
              {"role": "user", "content": "What are the latest tech news?"}
            ],
            "search_parameters": {
              "mode": "auto",
              "return_citations": true
            }
          }'
        ```
      </Tab>
    </Tabs>
  </Tab>

  <Tab title="GPTファイル入力">
    GPTモデルは、ファイル内容の直接処理をサポートします。

    ```bash theme={null}
    curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-xxxxxxxxxx" \
      -d '{
        "model": "gpt-5.5",
        "messages": [
          {
            "role": "user",
            "content": [
              {"type": "text", "text": "Please analyze the content of this document"},
              {
                "type": "file",
                "file": {
                  "url": "https://example.com/document.pdf"
                }
              }
            ]
          }
        ]
      }'
    ```

    対応するファイル形式には、PDF、Word、Excel、画像などがあります。

    <Tip>
      ファイルの処理能力はモデルによって異なります。必要なファイル形式に対応したモデルを選択してください。
    </Tip>
  </Tab>

  <Tab title="Grokの推論">
    Grokモデルは、強化された推論機能に対応しています。

    ```bash theme={null}
    curl -X POST "https://api.mixroute.ai/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer sk-xxxxxxxxxx" \
      -d '{
        "model": "grok-3-mini",
        "messages": [
          {"role": "user", "content": "Analyze this logic problem: If all A are B, and all B are C, then..."}
        ],
        "reasoning_effort": "high"
      }'
    ```

    | reasoning\_effort | 説明 |
    | - | - |
    | `low` | 高速な応答、基本的な推論 |
    | `medium` | バランスモード |
    | `high` | 深い推論、より高い精度 |
  </Tab>
</Tabs>

## レスポンス形式

<Tabs>
  <Tab title="非ストリーミングレスポンス">
    ```json theme={null}
    {
      "id": "chatcmpl-xxx",
      "object": "chat.completion",
      "created": 1234567890,
      "model": "gpt-5.5",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "Response content..."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 25,
        "completion_tokens": 100,
        "total_tokens": 125
      }
    }
    ```
  </Tab>

  <Tab title="ストリーミングレスポンス">
    ストリーミングレスポンスはServer-Sent Events（SSE）形式を使用します。

    ```text theme={null}
    data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1234567890,"model":"gpt-5.5","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}]}

    data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1234567890,"model":"gpt-5.5","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

    data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1234567890,"model":"gpt-5.5","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

    data: [DONE]
    ```

    各チャンクには差分のコンテンツが含まれます。ストリームは`[DONE]`で終了します。
  </Tab>
</Tabs>

## エラー処理

| エラーの種類 | 発生する状況 |
| - | - |
| AuthenticationError | APIキーが無効、または認証されていない |
| NotFoundError | モデルが存在しないか、対応していません |
| APIConnectionError | ネットワークの中断、またはサーバーが応答していない |
| RateLimitError | リクエストのレート制限を超過 |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.mixroute.ai/v1/chat/completions \
    --header 'Authorization: Bearer sk-xxxxxxxxxx' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gpt-5.5",
      "messages": [
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Briefly introduce artificial intelligence"}
      ],
      "temperature": 0.7
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-xxxxxxxxxx",
      base_url="https://api.mixroute.ai/v1"
  )

  response = client.chat.completions.create(
      model="gpt-5.5",
      messages=[
          {"role": "system", "content": "You are a helpful assistant"},
          {"role": "user", "content": "Briefly introduce artificial intelligence"}
      ],
      temperature=0.7
  )
  print(response.choices[0].message.content)
  ```

  ```javascript JavaScript theme={null}
  const OpenAI = require('openai');

  const client = new OpenAI({
    apiKey: 'sk-xxxxxxxxxx',
    baseURL: 'https://api.mixroute.ai/v1'
  });

  const response = await client.chat.completions.create({
    model: 'gpt-5.5',
    messages: [
      { role: 'system', content: 'You are a helpful assistant' },
      { role: 'user', content: 'Briefly introduce artificial intelligence' }
    ],
    temperature: 0.7
  });
  console.log(response.choices[0].message.content);
  ```

  ```php PHP theme={null}
  <?php
  $client = new GuzzleHttp\Client();
  $response = $client->post('https://api.mixroute.ai/v1/chat/completions', [
      'headers' => [
          'Authorization' => 'Bearer sk-xxxxxxxxxx',
          'Content-Type' => 'application/json',
      ],
      'json' => [
          'model' => 'gpt-5.5',
          'messages' => [
              ['role' => 'system', 'content' => 'You are a helpful assistant'],
              ['role' => 'user', 'content' => 'Briefly introduce artificial intelligence']
          ],
          'temperature' => 0.7
      ]
  ]);
  echo $response->getBody();
  ```

  ```go Go theme={null}
  package main

  import (
      "context"
      "fmt"
      openai "github.com/sashabaranov/go-openai"
  )

  func main() {
      config := openai.DefaultConfig("sk-xxxxxxxxxx")
      config.BaseURL = "https://api.mixroute.ai/v1"
      client := openai.NewClientWithConfig(config)

      resp, _ := client.CreateChatCompletion(
          context.Background(),
          openai.ChatCompletionRequest{
              Model: "gpt-5.5",
              Messages: []openai.ChatCompletionMessage{
                  {Role: "system", Content: "You are a helpful assistant"},
                  {Role: "user", Content: "Briefly introduce artificial intelligence"},
              },
          },
      )
      fmt.Println(resp.Choices[0].Message.Content)
  }
  ```

  ```java Java theme={null}
  import com.theokanning.openai.OpenAiService;
  import com.theokanning.openai.completion.chat.*;

  OpenAiService service = new OpenAiService("sk-xxxxxxxxxx");
  ChatCompletionRequest request = ChatCompletionRequest.builder()
      .model("gpt-5.5")
      .messages(Arrays.asList(
          new ChatMessage("system", "You are a helpful assistant"),
          new ChatMessage("user", "Briefly introduce artificial intelligence")
      ))
      .temperature(0.7)
      .build();
  ChatCompletionResult result = service.createChatCompletion(request);
  System.out.println(result.getChoices().get(0).getMessage().getContent());
  ```

  ```ruby Ruby theme={null}
  require 'openai'

  client = OpenAI::Client.new(
    access_token: 'sk-xxxxxxxxxx',
    uri_base: 'https://api.mixroute.ai/v1'
  )

  response = client.chat(
    parameters: {
      model: 'gpt-5.5',
      messages: [
        { role: 'system', content: 'You are a helpful assistant' },
        { role: 'user', content: 'Briefly introduce artificial intelligence' }
      ],
      temperature: 0.7
    }
  )
  puts response.dig('choices', 0, 'message', 'content')
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "chatcmpl-xxx",
    "object": "chat.completion",
    "created": 1234567890,
    "model": "gpt-5.5",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "Artificial intelligence is a new technical science that researches and develops theories, methods, techniques, and application systems for simulating, extending, and expanding human intelligence..."
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 25,
      "completion_tokens": 100,
      "total_tokens": 125
    }
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.