> ## 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)

> Universal text chat API supporting OpenAI-compatible LLMs

## Introduction

Universal text chat interface supporting OpenAI-compatible large language models. Through a unified API, you can access OpenAI, Claude, DeepSeek, Grok, Qwen, and many other mainstream models via MixRoute

## Authentication

Bearer Token, e.g., `Bearer sk-xxxxxxxxxx`

## Request Parameters

<ParamField body="model" type="string" required>
  Model identifier, corresponding to the Model Marketplace.

  <Tip>
    MixRoute supports multiple models. See the complete list at [Model Marketplace](https://console.mixroute.ai/models).
  </Tip>
</ParamField>

<ParamField body="messages" type="array" required>
  Array of conversation messages, each containing `role` (user/system/assistant) and `content`
</ParamField>

<ParamField body="temperature" type="number">
  Randomness control, 0-2. Higher values produce more random responses
</ParamField>

<ParamField body="stream" type="boolean">
  Enable streaming output, returns SSE format chunked data
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum tokens to generate, controls response length
</ParamField>

<ParamField body="response_format" type="object">
  Output format, supports `text` or `json_object` / `json_schema`
</ParamField>

<ParamField body="top_p" type="number">
  Nucleus sampling parameter, 0-1, alternative to temperature. Lower values make sampling more conservative
</ParamField>

<ParamField body="frequency_penalty" type="number">
  Frequency penalty, -2 to 2. Positive values reduce repetition of frequent tokens
</ParamField>

<ParamField body="presence_penalty" type="number">
  Presence penalty, -2 to 2. Positive values encourage discussing new topics
</ParamField>

<ParamField body="stop" type="string | array">
  Stop sequences, generation stops when specified strings are encountered
</ParamField>

<ParamField body="seed" type="integer">
  Random seed. Same seed makes results more consistent
</ParamField>

<ParamField body="user" type="string">
  End-user identifier for monitoring and rate-limiting
</ParamField>

<ParamField body="n" type="integer">
  Number of response candidates per prompt, defaults to 1
</ParamField>

<ParamField body="logit_bias" type="object">
  Token bias, maps token IDs to bias values (-100 to 100)
</ParamField>

<ParamField body="tools" type="array">
  Tools definition list, each tool must include `type` and `function`
</ParamField>

<ParamField body="tool_choice" type="string">
  Tool selection strategy: `"auto"` / `"none"` / `"required"`, or specify a tool name
</ParamField>

## Basic Examples

<Tabs>
  <Tab title="Non-Streaming Request">
    ```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="Streaming Request (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 Example">
    ```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>

## Advanced Features

<Tabs>
  <Tab title="Tool Calling">
    Supports OpenAI-compatible tool calling format:

    ```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="Structured Output">
    Use JSON Schema to constrain model output format:

    ```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="Thinking Capability">
    <Tabs>
      <Tab title="DeepSeek">
        DeepSeek series supports deep thinking capability:

        ```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
          }'
        ```

        Response will include `reasoning_content` field showing the thinking process.
      </Tab>

      <Tab title="Qwen">
        Qwen series supports thinking capability:

        ```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 series (`gpt-5.6-sol` / `gpt-5.6-terra` / `gpt-5.6-luna`) supports advanced reasoning configuration:

        * `reasoning.mode` — Execution mode: `"standard"` (default) or `"pro"`. Pro Mode performs additional model work to improve reliability on difficult tasks
        * `reasoning.effort` — Reasoning intensity: `none` / `low` / `medium` / `high` / `xhigh` / `max` (`max` is a new level)

        ```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 supports thinking capability:

        ```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 Extended">
    Qwen supports additional extended parameters:

    ```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
        }
      }'
    ```

    | Parameter                        | Description                       |
    | -------------------------------- | --------------------------------- |
    | `enable_search`                  | Enable web search                 |
    | `search_options.search_strategy` | Search strategy: `standard`/`pro` |
    | `search_options.forced_search`   | Force search                      |
  </Tab>

  <Tab title="Web Search">
    <Tabs>
      <Tab title="Claude Search">
        Claude models support web search functionality:

        ```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 Search">
        Grok models support real-time web search:

        ```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 File Input">
    GPT models support direct file content processing:

    ```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"
                }
              }
            ]
          }
        ]
      }'
    ```

    Supported file types include PDF, Word, Excel, images, etc.

    <Tip>
      Model file processing capabilities vary between models, please choose a model that supports the file types you need.
    </Tip>
  </Tab>

  <Tab title="Grok Reasoning">
    Grok models support enhanced reasoning capability:

    ```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 | Description                     |
    | ----------------- | ------------------------------- |
    | `low`             | Quick response, basic reasoning |
    | `medium`          | Balanced mode                   |
    | `high`            | Deep reasoning, more accurate   |
  </Tab>
</Tabs>

## Response Format

<Tabs>
  <Tab title="Non-Streaming Response">
    ```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="Streaming Response">
    Streaming responses use Server-Sent Events (SSE) format:

    ```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]
    ```

    Each chunk contains incremental content, ending with `[DONE]`.
  </Tab>
</Tabs>

## Error Handling

| Error Type          | Trigger Scenario                              |
| ------------------- | --------------------------------------------- |
| AuthenticationError | Invalid API key or unauthorized               |
| NotFoundError       | Model does not exist or is not supported      |
| APIConnectionError  | Network interruption or server not responding |
| RateLimitError      | Request rate limit exceeded                   |

<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>
