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

# General Chat API

* Unified chat API supporting all major text generation models
* Fully compatible with the OpenAI Chat Completions API format
* Switch between AI models seamlessly via the `model` parameter
* Supports streaming, function calling, and other advanced features

<RequestExample>
  ```bash cURL theme={"system"}
  curl -X POST https://www.qingbo.dev/v1/chat/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-5",
      "messages": [
        {
          "role": "system",
          "content": "你是一个专业的AI助手。"
        },
        {
          "role": "user",
          "content": "解释一下冒泡排序算法。"
        }
      ],
      "temperature": 0.7,
      "max_tokens": 1024
    }'
  ```

  ```python Python theme={"system"}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://www.qingbo.dev/v1",
      api_key="YOUR_API_KEY"
  )

  response = client.chat.completions.create(
      model="gpt-5",
      messages=[
          {"role": "system", "content": "你是一个专业的AI助手。"},
          {"role": "user", "content": "解释一下冒泡排序算法。"}
      ],
      temperature=0.7,
      max_tokens=1024
  )

  print(response.choices[0].message.content)
  ```

  ```javascript JavaScript theme={"system"}
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://www.qingbo.dev/v1',
    apiKey: 'YOUR_API_KEY'
  });

  const response = await client.chat.completions.create({
    model: 'gpt-5',
    messages: [
      { role: 'system', content: '你是一个专业的AI助手。' },
      { role: 'user', content: '解释一下冒泡排序算法。' }
    ],
    temperature: 0.7,
    max_tokens: 1024
  });

  console.log(response.choices[0].message.content);
  ```

  ```go Go theme={"system"}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "io"
      "net/http"
  )

  func main() {
      payload := map[string]interface{}{
          "model": "gpt-5",
          "messages": []map[string]string{
              {"role": "system", "content": "你是一个专业的AI助手。"},
              {"role": "user", "content": "解释一下冒泡排序算法。"},
          },
          "temperature": 0.7,
          "max_tokens": 1024,
      }

      body, _ := json.Marshal(payload)
      req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/chat/completions", bytes.NewBuffer(body))
      req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
      req.Header.Set("Content-Type", "application/json")

      resp, err := http.DefaultClient.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      result, _ := io.ReadAll(resp.Body)
      fmt.Println(string(result))
  }
  ```

  ```java Java theme={"system"}
  import java.net.http.*;
  import java.net.URI;

  public class Main {
      public static void main(String[] args) throws Exception {
          String payload = """
          {
            "model": "gpt-5",
            "messages": [
              {"role": "system", "content": "你是一个专业的AI助手。"},
              {"role": "user", "content": "解释一下冒泡排序算法。"}
            ],
            "temperature": 0.7,
            "max_tokens": 1024
          }
          """;

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create("https://www.qingbo.dev/v1/chat/completions"))
              .header("Authorization", "Bearer YOUR_API_KEY")
              .header("Content-Type", "application/json")
              .POST(HttpRequest.BodyPublishers.ofString(payload))
              .build();

          HttpResponse<String> response = client.send(request,
              HttpResponse.BodyHandlers.ofString());
          System.out.println(response.body());
      }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null} theme={"system"}
  {
    "id": "chatcmpl-CdA8u0qPqzeN2gu8QLuQfjaP9CHU4",
    "object": "chat.completion",
    "created": 1763449816,
    "model": "gpt-5-2025-08-07",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "冒泡排序（Bubble Sort）是一种简单的比较交换排序。它通过重复遍历序列，比较相邻元素并把较大的“冒泡”到右侧末端，直到序列有序。\n\n核心思想\n- 每一趟从左到右比较相邻元素，若前者大于后者则交换。一次趟结束后，当前未排部分中最大的元素被放到末尾。\n- 重复多趟，直到没有发生交换或已完成 n−1 趟。\n\n流程示例（以 [5, 1, 4, 2] 为例）\n- 第1趟：比较并交换 → [1, 5, 4, 2] → [1, 4, 5, 2] → [1, 4, 2, 5]（最大元素5到末尾）\n- 第2趟：比较并交换 → [1, 4, 2, 5] → [1, 2, 4, 5]（已整体有序，可提前结束）\n\n性质\n- 时间复杂度：平均/最坏 O(n^2)，最好 O(n)（当已基本有序且使用提前退出优化）\n- 空间复杂度：O(1)（就地排序）\n- 稳定性：稳定（相等元素相对次序不变）\n- 适用场景：数据量小或序列几乎有序；不适合大规模无序数据\n\n常见优化\n- 提前退出：某趟未发生交换则已排序完成。\n- 缩短边界：记录本趟最后一次交换的位置，下一趟只需遍历到该位置。\n- 双向冒泡（鸡尾酒排序）：从左到右、再从右到左各走一遍，更快收敛。\n\n简要伪代码\nfunction bubbleSort(a):\n    n = length(a)\n    repeat\n        swapped = false\n        for j = 0 to n-2:\n            if a[j] > a[j+1]:\n                swap(a[j], a[j+1])\n                swapped = true\n        n = n - 1    // 末尾已就位，缩短范围\n    until swapped == false\n\n如需，我可以给出某种语言的实现代码或更多变体说明。",
          "refusal": null,
          "annotations": []
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 24,
      "completion_tokens": 1030,
      "total_tokens": 1054,
      "prompt_tokens_details": {
        "cached_tokens": 0,
        "audio_tokens": 0
      },
      "completion_tokens_details": {
        "reasoning_tokens": 512,
        "audio_tokens": 0,
        "accepted_prediction_tokens": 0,
        "rejected_prediction_tokens": 0
      }
    }
  }
  ```

  ```json 400 theme={null} theme={"system"}
  {
    "error": {
      "code": 400,
      "message": "Invalid request parameters",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={null} theme={"system"}
  {
    "error": {
      "code": 401,
      "message": "Authentication failed, please check your API key",
      "type": "authentication_error"
    }
  }
  ```

  ```json 402 theme={null} theme={"system"}
  {
    "error": {
      "code": 402,
      "message": "Insufficient account balance, please top up and try again",
      "type": "payment_required"
    }
  }
  ```

  ```json 403 theme={null} theme={"system"}
  {
    "error": {
      "code": 403,
      "message": "Access forbidden, you do not have permission to access this resource",
      "type": "permission_error"
    }
  }
  ```

  ```json 429 theme={null} theme={"system"}
  {
    "error": {
      "code": 429,
      "message": "Too many requests, please try again later",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 theme={null} theme={"system"}
  {
    "error": {
      "code": 500,
      "message": "Internal server error, please try again later",
      "type": "server_error"
    }
  }
  ```

  ```json 502 theme={null} theme={"system"}
  {
    "error": {
      "code": 502,
      "message": "Bad gateway, the server is temporarily unavailable",
      "type": "bad_gateway"
    }
  }
  ```
</ResponseExample>

## Authorizations

<ParamField header="Authorization" type="string" required>
  All endpoints require Bearer Token authentication.

  Get your API Key:

  Visit the [API Key management page](https://qingbo.dev/dashboard/keys) to obtain your API Key.

  Add it to the request header:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" required>
  Model name.

  Supported models include:

  * **OpenAI**: `gpt-5`, `gpt-5-mini`, `gpt-5-nano`, `gpt-5.1`, `gpt-5.2`, `gpt-5.4`, `gpt-4.1`, `gpt-4.1-mini`, `gpt-4.1-nano`, `gpt-4o`, `gpt-4o-mini`, `o1`, `o3-mini`, `o4-mini`
  * **Anthropic**: `claude-opus-4.6`, `claude-sonnet-4.6`, `claude-opus-4.5`, `claude-sonnet-4.5`, `claude-haiku-4.5`
  * **Google**: `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite`, `gemini-3-flash-preview`, `gemini-3.1-pro-preview`
  * **DeepSeek**: `deepseek-r1-0528`, `deepseek-v3.2`, `deepseek-v3.2-exp`
  * **MiniMax**: `minimax-m2.1`, `minimax-m2.5`
  * **MoonshotAI**: `kimi-k2.5`, `kimi-k2-thinking`
  * **Z.ai**: `glm-4.6`, `glm-4.7`, `glm-5`, `glm-5.1`
  * More models added regularly...
</ParamField>

<ParamField body="messages" type="array" required>
  List of conversation messages.

  <Expandable title="Message object properties">
    <ParamField body="role" type="string" required>
      Role: `system` (system prompt), `user` (user input), or `assistant` (model reply).
    </ParamField>

    <ParamField body="content" type="string" required>
      Message content. Accepts a string or an array of multimodal content parts.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="temperature" type="number">
  Controls output randomness, range 0–2.

  * Lower values (e.g., 0.2) make output more deterministic.
  * Higher values (e.g., 1.8) make output more random.

  Default: 1.0
</ParamField>

<ParamField body="max_tokens" type="integer">
  Maximum number of tokens to generate.

  The maximum allowed value varies by model — refer to the specific model documentation.
</ParamField>

<ParamField body="stream" type="boolean">
  Whether to use streaming output.

  * `true`: Stream the response as Server-Sent Events (SSE).
  * `false`: Return the full response in one go.

  Default: false
</ParamField>

<ParamField body="top_p" type="number">
  Nucleus sampling parameter, range 0–1.

  Controls diversity. We recommend using either `temperature` or `top_p`, not both.

  Default: 1.0
</ParamField>

<ParamField body="frequency_penalty" type="number">
  Frequency penalty, range -2.0 to 2.0.

  Positive values reduce the likelihood of repeating the same words.

  Default: 0
</ParamField>

<ParamField body="presence_penalty" type="number">
  Presence penalty, range -2.0 to 2.0.

  Positive values increase the likelihood of introducing new topics.

  Default: 0
</ParamField>

<ParamField body="stop" type="string or array">
  Stop sequences.

  Up to 4 sequences. Generation stops when any of them is encountered.
</ParamField>

<ParamField body="n" type="integer">
  Number of completions to generate.

  Default: 1
</ParamField>

## Response

<ResponseField name="id" type="string">
  Unique identifier of the response.
</ResponseField>

<ResponseField name="object" type="string">
  Object type, always `chat.completion`.
</ResponseField>

<ResponseField name="created" type="integer">
  Creation timestamp.
</ResponseField>

<ResponseField name="model" type="string">
  Name of the model that actually served the request.
</ResponseField>

<ResponseField name="choices" type="array">
  List of generated completions.

  <Expandable title="Properties">
    <ResponseField name="index" type="integer">
      Choice index.
    </ResponseField>

    <ResponseField name="message" type="object">
      Message content.

      <Expandable title="Properties">
        <ResponseField name="role" type="string">
          Role (assistant).
        </ResponseField>

        <ResponseField name="content" type="string">
          Generated text content.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="logprobs" type="object">
      Log probability info (null by default).
    </ResponseField>

    <ResponseField name="finish_reason" type="string">
      Reason generation stopped.

      Possible values:

      * `stop` — Natural completion
      * `length` — Reached max length
      * `content_filter` — Filtered by content moderation
      * `function_call` — Function call
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usage" type="object">
  Token usage statistics.

  <Expandable title="Properties">
    <ResponseField name="prompt_tokens" type="integer">
      Number of input tokens.
    </ResponseField>

    <ResponseField name="completion_tokens" type="integer">
      Number of generated tokens.
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      Total tokens.
    </ResponseField>

    <ResponseField name="prompt_tokens_details" type="object">
      Input token breakdown.

      <Expandable title="Properties">
        <ResponseField name="cached_tokens" type="integer">
          Cached tokens.
        </ResponseField>

        <ResponseField name="text_tokens" type="integer">
          Text tokens.
        </ResponseField>

        <ResponseField name="audio_tokens" type="integer">
          Audio tokens.
        </ResponseField>

        <ResponseField name="image_tokens" type="integer">
          Image tokens.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="completion_tokens_details" type="object">
      Output token breakdown.

      <Expandable title="Properties">
        <ResponseField name="text_tokens" type="integer">
          Text tokens.
        </ResponseField>

        <ResponseField name="audio_tokens" type="integer">
          Audio tokens.
        </ResponseField>

        <ResponseField name="reasoning_tokens" type="integer">
          Reasoning tokens (thinking models only).
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="system_fingerprint" type="string">
  System fingerprint (used to track backend configuration).
</ResponseField>

## Supported Models

### OpenAI series

* `gpt-5` — GPT-5 base model
* `gpt-5-mini` — GPT-5 lightweight
* `gpt-5-nano` — GPT-5 ultra-lightweight
* `gpt-5.1` — GPT-5.1
* `gpt-5.2` — GPT-5.2
* `gpt-5.4` — GPT-5.4
* `gpt-4.1` — GPT-4.1
* `gpt-4.1-mini` — GPT-4.1 lightweight
* `gpt-4.1-nano` — GPT-4.1 ultra-lightweight
* `gpt-4o` — GPT-4o multimodal model
* `gpt-4o-mini` — GPT-4o lightweight
* `o1` — OpenAI o1 reasoning model
* `o3-mini` — OpenAI o3 Mini
* `o4-mini` — OpenAI o4 Mini

### Anthropic series

* `claude-opus-4.6` — Claude 4.6 Opus, latest flagship
* `claude-sonnet-4.6` — Claude 4.6 Sonnet, latest version
* `claude-opus-4.5` — Claude 4.5 Opus flagship
* `claude-sonnet-4.5` — Claude 4.5 Sonnet, balanced
* `claude-haiku-4.5` — Claude 4.5 Haiku, fast response

### Google series

* `gemini-3.1-pro-preview` — Gemini 3.1 Pro preview
* `gemini-3-flash-preview` — Gemini 3 Flash preview
* `gemini-2.5-pro` — Gemini 2.5 Pro
* `gemini-2.5-flash` — Gemini 2.5 Flash
* `gemini-2.5-flash-lite` — Gemini 2.5 Flash Lite

### DeepSeek series

* `deepseek-r1-0528` — DeepSeek R1 reasoning model
* `deepseek-v3.2` — DeepSeek V3.2
* `deepseek-v3.2-exp` — DeepSeek V3.2 experimental

### MiniMax series

* `minimax-m2.1` — MiniMax M2.1
* `minimax-m2.5` — MiniMax M2.5

### MoonshotAI series

* `kimi-k2.5` — Kimi K2.5
* `kimi-k2-thinking` — Kimi K2 Thinking

### Z.ai series

* `glm-4.6` — GLM 4.6
* `glm-4.7` — GLM 4.7
* `glm-5` — GLM 5
* `glm-5.1` — GLM 5.1

## Examples

### Basic chat

```json theme={null} theme={"system"}
{
  "model": "gpt-5",
  "messages": [
    {"role": "user", "content": "你好"}
  ]
}
```

### System prompt

```json theme={null} theme={"system"}
{
  "model": "claude-sonnet-4.5",
  "messages": [
    {"role": "system", "content": "你是一位专业的Python编程导师"},
    {"role": "user", "content": "如何使用列表推导式？"}
  ]
}
```

### Multi-turn conversation

```json theme={null} theme={"system"}
{
  "model": "gemini-2.5-flash",
  "messages": [
    {"role": "user", "content": "什么是机器学习？"},
    {"role": "assistant", "content": "机器学习是人工智能的一个分支..."},
    {"role": "user", "content": "能举个例子吗？"}
  ]
}
```

### Streaming output

```json theme={null} theme={"system"}
{
  "model": "gpt-5",
  "messages": [
    {"role": "user", "content": "写一首关于春天的诗"}
  ],
  "stream": true
}
```

## Advanced features

<Note>
  This endpoint covers basic text chat. For advanced features, see:

  * **Image / video analysis** — [Multimodal Responses API](/en/api-reference/text/openai-multimodal)
  * **Function calling** — [Multimodal Responses API](/en/api-reference/text/openai-multimodal)
  * **Web search, file search** — [Multimodal Responses API](/en/api-reference/text/openai-multimodal)
  * **Streaming output** — [Streaming guide](/en/docs/streaming)
</Note>
