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

# Kimi-K2.6

> 通过 Anyfast OpenAI 兼容接口调用月之暗面 Kimi-K2.6 多模态对话模型。最新最智能、支持思考与文本/图片/视频输入。

Kimi-K2.6 是月之暗面（MoonShot）最新最智能的模型，通过 Anyfast 以 OpenAI 兼容接口提供。相比 Kimi-K2.5，在智能体编码（agentic coding）、长上下文推理、长周期执行和前端设计上有较大升级，同时支持文本、图片与视频输入，以及思考与非思考模式。

## 核心能力

* **OpenAI 兼容** — 可直接替换 OpenAI SDK，无需修改其他代码
* **256K 上下文** — 262,144 tokens，支持大规模文档和多轮对话
* **多模态输入** — 支持文本、图片和视频输入
* **思考模式** — 通过 `thinking` 参数开启/关闭，返回 `reasoning_content` 推理过程，并支持 Preserved Thinking
* **长程编码** — 在 Rust、Go、Python 等多语言和前端、运维、性能优化等场景下更可靠
* **丰富能力** — 支持 Tool Calls（函数调用）、JSON Mode、Partial Mode、联网搜索与自动上下文缓存

## 快速示例

<CodeGroup>
  ```bash cURL theme={null}
  curl https://www.anyfast.ai/v1/chat/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "kimi-k2.6",
      "messages": [
        { "role": "user", "content": "用简单的语言解释量子纠缠。" }
      ]
    }'
  ```

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

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

  response = client.chat.completions.create(
      model="kimi-k2.6",
      messages=[
          {"role": "user", "content": "用简单的语言解释量子纠缠。"}
      ]
  )

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

  ```python 流式输出 theme={null}
  from openai import OpenAI

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

  stream = client.chat.completions.create(
      model="kimi-k2.6",
      messages=[
          {"role": "user", "content": "写一首关于大海的短诗。"}
      ],
      stream=True
  )

  for chunk in stream:
      print(chunk.choices[0].delta.content or "", end="")
  ```

  ```python 思考模式 theme={null}
  from openai import OpenAI

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

  # 思考模式默认开启；如需关闭可传 {"type": "disabled"}
  completion = client.chat.completions.create(
      model="kimi-k2.6",
      messages=[
          {"role": "user", "content": "解这道数学题：x² + 5x + 6 = 0，求 x。"}
      ],
      extra_body={"thinking": {"type": "enabled"}},
      stream=True
  )

  for chunk in completion:
      if chunk.choices and chunk.choices[0].delta:
          delta = chunk.choices[0].delta
          if hasattr(delta, "reasoning_content") and delta.reasoning_content:
              print(delta.reasoning_content, end="", flush=True)
          if delta.content:
              print(delta.content, end="", flush=True)
  ```

  ```python 图片输入 theme={null}
  import base64
  from openai import OpenAI

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

  with open("your_image.jpg", "rb") as f:
      img_base = base64.b64encode(f.read()).decode("utf-8")

  response = client.chat.completions.create(
      model="kimi-k2.6",
      messages=[
          {
              "role": "user",
              "content": [
                  {"type": "text", "text": "请描述这张图片。"},
                  {
                      "type": "image_url",
                      "image_url": {
                          "url": f"data:image/jpeg;base64,{img_base}"
                          # 或文件引用: "url": "ms://<file_id>"
                      }
                  }
              ]
          }
      ]
  )

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

  ```python 视频输入 theme={null}
  import base64
  from openai import OpenAI

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

  with open("your_video.mp4", "rb") as f:
      video_base = base64.b64encode(f.read()).decode("utf-8")

  response = client.chat.completions.create(
      model="kimi-k2.6",
      messages=[
          {
              "role": "user",
              "content": [
                  {"type": "text", "text": "请总结这个视频的内容。"},
                  {
                      "type": "video_url",
                      "video_url": {
                          "url": f"data:video/mp4;base64,{video_base}"
                          # 或文件引用: "url": "ms://<file_id>"
                      }
                  }
              ]
          }
      ]
  )

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

  ```bash cURL (图片) theme={null}
  curl https://www.anyfast.ai/v1/chat/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "kimi-k2.6",
      "messages": [
        {
          "role": "user",
          "content": [
            {"type": "text", "text": "请描述这张图片。"},
            {"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KGgo..."}}
          ]
        }
      ]
    }'
  ```
</CodeGroup>

> **注意：** `image_url` 和 `video_url` 支持两种格式：base64 数据 URI（`data:image/png;base64,...` / `data:video/mp4;base64,...`）或文件引用（`ms://<file_id>`）。命中上下文缓存的 Token 数会在响应的 `usage.prompt_tokens_details.cached_tokens` 中体现。

## 参数说明

| 参数                      | 类型             | 必填 | 说明                                                                                              |
| ----------------------- | -------------- | -- | ----------------------------------------------------------------------------------------------- |
| `model`                 | string         | 是  | 固定为 `kimi-k2.6`                                                                                 |
| `messages`              | array          | 是  | `{ role, content }` 对象数组。`content` 可为字符串，或包含 `text`/`image_url`/`video_url` 的多模态数组              |
| `thinking`              | object         | 否  | 控制思考模式，如 `{"type": "enabled"}`（默认）或 `{"type": "disabled"}`；`keep: "all"` 可启用 Preserved Thinking |
| `max_completion_tokens` | integer        | 否  | 最大生成 Token 数。（`max_tokens` 已弃用且不生效）                                                             |
| `temperature`           | float          | 否  | `0`–`2`，控制随机性，默认 `1`                                                                            |
| `stream`                | boolean        | 否  | 开启 SSE 流式传输，默认 `false`                                                                          |
| `top_p`                 | float          | 否  | 核采样阈值，默认 `1`                                                                                    |
| `response_format`       | object         | 否  | 设为 `{"type": "json_object"}` 可启用 JSON Mode                                                      |
| `tools`                 | array          | 否  | 模型可调用的工具列表（函数调用）                                                                                |
| `stop`                  | string / array | 否  | 触发停止生成的序列，最多 5 个，每个不超过 32 字节                                                                    |

<Card title="API 参考" icon="code" href="/zh/api-reference/model-api/moonshot/kimi-k2-6">
  查看 Kimi-K2.6 的交互式 API Playground。
</Card>

<script src="/feedback.js" />
