studioglobal
热门发现
答案已发布8 来源

Kimi K2.6 API 怎么用:Moonshot 端点、model ID 与快速示例

Moonshot API 的 base url 是 直连聊天接口时使用 /chat/completions。 不要凭产品名猜 model,也不要把 OpenRouter、AIMLAPI 的 ID 直接搬到 Moonshot;先调用 GET /models,使用返回的 id。

17K0
Minh họa lập trình viên cấu hình API Kimi K2.6 với endpoint Moonshot và model ID
Cách dùng Kimi K2.6 qua API Moonshot: endpoint đúng và model IDLuồng nên dùng: cấu hình endpoint Moonshot, gọi /models để xác minh model ID, rồi gửi request chat.
AI 提示

Create a landscape editorial hero image for this Studio Global article: Cách dùng Kimi K2.6 qua API Moonshot: endpoint đúng và model ID. Article summary: Dùng Kimi K2.6 qua API Moonshot bằng OpenAI SDK với base url https://api.moonshot.ai/v1, rồi gọi /chat/completions; điểm cần kiểm chứng là model ID, nên gọi /models trong tài khoản thay vì đoán.. Topic tags: ai, kimi, moonshot ai, llm, api. Reference image context from search candidates: Reference image 1: visual subject "# Moonshot AI (Kimi K2.6). ## Step 1: Create a Moonshot API account. Go to and create a new Moonshot API account. ## Step 2: Set up Moonshot API account. To use the model via API," source context "Moonshot AI (Kimi K2.6)" Reference image 2: visual subject "Connect and use Kimi K2.6 from Moonshot AI with API Key - Featured image. # How to use Kimi K2.6 from Moonshot AI with API Key on TypingMind. Learn how to access and

openai.com

接入 Kimi K2.6 时,最容易出错的往往不是端点地址,而是 model 填错。Kimi 开放平台文档说明,它提供与 OpenAI 格式兼容的 HTTP API,可以直接使用 OpenAI SDK;用 SDK 时把 base_url 设为 https://api.moonshot.ai/v1,如果直接发 HTTP 请求,Chat Completions 的完整路径是 https://api.moonshot.ai/v1/chat/completions[13]

真正需要先核对的是模型 ID。List Models 页面提示 Kimi K2.6 已发布,但文档示例里的返回 id 仍以 kimi-k2.5 演示。因此,不要凭产品名猜 model,也不要直接复制第三方网关的写法;先在自己的 Moonshot 账号下调用

GET /models
,再使用 API 返回的 id[17]

先认准 Moonshot 端点

场景配置或 endpoint说明
使用 OpenAI SDK
base_url = https://api.moonshot.ai/v1
Kimi 文档说明 API 兼容 OpenAI,可直接使用 OpenAI SDK。[13]
实时聊天补全
POST https://api.moonshot.ai/v1/chat/completions
API overview 给出完整路径;Chat API 文档展示了 model + messages 的请求结构。[13][14]
列出可用模型
GET https://api.moonshot.ai/v1/models
返回模型列表,示例响应包含 id 字段;这个 id 才是应传给 model 的值。[17]
检查账户余额
GET https://api.moonshot.ai/v1/users/me/balance
Check Balance 文档用
Authorization: Bearer ...
进行认证。[15]
创建 batch
POST https://api.moonshot.ai/v1/batches
Batch API 文档给出创建 batch 的 endpoint。[16]

推荐接入流程

  1. 准备 Moonshot API key。 Kimi 的 API 示例使用
    Authorization: Bearer ...
    ;TypingMind 的 Kimi K2.6 集成文档也把流程写成创建 Moonshot API 账号、添加余额并获取 API key。[2][15][17]
  2. 把客户端指向 Moonshot。 如果使用 OpenAI SDK,关键不是换一套 SDK,而是把 base_url 改成 https://api.moonshot.ai/v1[13]
  3. 先调用 /models List Models endpoint 用来列出当前可用模型,并在响应中提供 id;将这个值填入后续请求的 model 字段。[17]
  4. 再发送聊天请求。 Chat Completions 的请求按 modelmessages 组织,HTTP 直连则发到 /chat/completions[13][14]
  5. 按需查余额或跑批处理。 余额可用 /users/me/balance 检查,batch 任务可通过 /batches 创建。[15][16]

Python 示例:OpenAI SDK

下面示例固定的是 Kimi 文档给出的 base_urlKIMI_MODEL_ID 应来自

GET /models
返回的 id,不要手写猜测,也不要从别的网关复制。[13][17]

python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ['MOONSHOT_API_KEY'],
    base_url='https://api.moonshot.ai/v1',
)

response = client.chat.completions.create(
    model=os.environ['KIMI_MODEL_ID'],
    messages=[
        {'role': 'user', 'content': '你好,请用一句话介绍一下自己。'}
    ],
)

print(response)

cURL 示例:先拿 model ID,再发聊天请求

第一步建议先列出你自己账号可用的模型,因为 /models 的响应会给出可直接使用的 id[17]

bash
curl -sS https://api.moonshot.ai/v1/models \
  -H "Authorization: Bearer $MOONSHOT_API_KEY"

选定响应里的 id 后,再调用 Chat Completions。Kimi 文档确认了 /chat/completions 的完整路径,以及 modelmessages 这种请求结构。[13][14]

bash
curl -sS https://api.moonshot.ai/v1/chat/completions \
  -H "Authorization: Bearer $MOONSHOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "PASTE_MODEL_ID_FROM_MODELS",
    "messages": [
      {"role": "user", "content": "请用一句话介绍 Kimi K2.6。"}
    ]
  }'

检查 API 余额

如果请求失败像是 billing 问题,或你想在接入前确认账户状态,可以调用 Kimi 的余额接口 /users/me/balance;文档示例同样使用 Bearer token。[15]

bash
curl -sS https://api.moonshot.ai/v1/users/me/balance \
  -H "Authorization: Bearer $MOONSHOT_API_KEY"

不要混用第三方网关的 model ID

有些中间服务会为 Kimi K2.6 使用自己的模型 ID 和入口。AIMLAPI 的示例 endpoint 是 https://api.aimlapi.com/v1/chat/completions,model 写作 moonshot/kimi-k2-6[1] OpenRouter 的 Kimi K2.6 API 页面显示的模型名是 moonshotai/kimi-k2.6[5]

这些写法只应在调用对应平台时使用。回到 Moonshot 的 https://api.moonshot.ai/v1/chat/completions,更稳妥的做法始终是先请求

GET https://api.moonshot.ai/v1/models
,再把 Moonshot 返回的 id 填入 model[13][17]

一句话结论

最稳的接入顺序是:拿到 API key,设置 OpenAI SDK 的 base_urlhttps://api.moonshot.ai/v1,调用 /models 核准 Kimi K2.6 的模型 ID,然后向 /chat/completions 发送带 modelmessages 的请求。这样既符合 Kimi 的 OpenAI-compatible 文档,也能避开把 AIMLAPI 或 OpenRouter 的 model ID 误填到 Moonshot 端点里的常见错误。[1][5][13][14][17]

Studio Global AI

Search, cite, and publish your own answer

Use this topic as a starting point for a fresh source-backed answer, then compare citations before you share it.

使用 Studio Global AI 搜索并核查事实

要点

  • Moonshot API 的 base url 是 https://api.moonshot.ai/v1;HTTP 直连聊天接口时使用 /chat/completions。
  • 不要凭产品名猜 model,也不要把 OpenRouter、AIMLAPI 的 ID 直接搬到 Moonshot;先调用 GET /models,使用返回的 id。
  • 常用端点包括 /models、/chat/completions、/users/me/balance 和 /batches,可分别用于列模型、聊天、查余额和创建 batch。

人们还问

“Kimi K2.6 API 怎么用:Moonshot 端点、model ID 与快速示例”的简短答案是什么?

Moonshot API 的 base url 是 https://api.moonshot.ai/v1;HTTP 直连聊天接口时使用 /chat/completions。

首先要验证的关键点是什么?

Moonshot API 的 base url 是 https://api.moonshot.ai/v1;HTTP 直连聊天接口时使用 /chat/completions。 不要凭产品名猜 model,也不要把 OpenRouter、AIMLAPI 的 ID 直接搬到 Moonshot;先调用 GET /models,使用返回的 id。

接下来在实践中我应该做什么?

常用端点包括 /models、/chat/completions、/users/me/balance 和 /batches,可分别用于列模型、聊天、查余额和创建 batch。

接下来我应该探索哪个相关主题?

继续“Claude Security 公测版详解:Anthropic 的 AI 代码漏洞扫描工具”以获得另一个角度和额外的引用。

打开相关页面

我应该将其与什么进行比较?

对照“Grok 4.3 API 解读:1M 上下文、低 token 价与语音平台野心”交叉检查此答案。

打开相关页面

继续你的研究

研究对话

研究问题

Tìm kiếm và kiểm chứng thông tin: Cách dùng Kimi K2.6 qua API như thế nào?

Studio Global AI19 来源

引用的答案

Có thể dùng Kimi K2.6 qua API theo cách gần giống OpenAI API, nhưng từ bằng chứng hiện có, phần chắc chắn nhất là cách kết nối vào nền tảng Kimi/Moonshot và các endpoint chính; còn ví dụ payload đầy đủ riêng cho đúng model ID của Kimi K2.6 thì bằng chứng hiện tại chưa hiển thị rõ. [3][7][8]

Cách dùng qua API chính thức của Kimi/Moonshot

  • Kimi Open Platform cung cấp HTTP API tương thích OpenAI, nên có thể dùng trực tiếp OpenAI SDK. [3]
  • Khi dùng SDK, cần đặt base_urlhttps://api.moonshot.ai/v1. [3]
  • Nếu gọi HTTP trực tiếp, endpoint gốc cũng là https://api.moonshot.ai/v1. [3]
  • API chat có tài liệu “Basic Information”, cho thấy cách gọi theo kiểu chat.completions.create(...) với modelmessages, tức cùng kiểu request body như OpenAI Chat Completions. [4]
  • Có endpoint kiểm tra số dư tại
    GET https://api.moonshot.ai/v1/users/me/balance
    và xác thực bằng header
    Authorization: Bearer ...
    . [5]
  • Có endpoint liệt kê model tại
    GET https://api.moonshot.ai/v1/models
    , và tài liệu model list xác nhận Kimi K2.6 đã được phát hành. [8]
  • Ngoài gọi realtime, nền tảng còn có Batch API tại
    POST https://api.moonshot.ai/v1/batches
    . [6]

Các bước thực tế nên làm

  1. Tạo tài khoản API và lấy API key. [2]
  2. Nạp số dư vào tài khoản nếu muốn dùng model qua API. [2]
  3. Cấu hình client/SDK với
    base_url = https://api.moonshot.ai/v1
    . [3]
  4. Gọi API chat theo chuẩn OpenAI-compatible, truyền modelmessages. [3][4]
  5. Nếu chưa chắc model ID chính xác của Kimi K2.6, gọi endpoint /models để kiểm tra danh sách model khả dụng trước. [8]

Mẫu gọi API tối thiểu

Ví dụ theo đúng hướng dẫn tổng quan của Kimi là dùng OpenAI SDK với base_url của Moonshot. [3]

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_KIMI_API_KEY",
    base_url="https://api.moonshot.ai/v1"
)

resp = client.chat.completions.create(
    model="KIMI_K2_6_MODEL_ID",
    messages=[
        {"role": "user", "content": "Xin chào, hãy tự giới thiệu."}
    ]
)
print(resp)
  • Phần model="KIMI_K2_6_MODEL_ID" ở trên chỉ là chỗ điền model ID thực tế; trong bằng chứng hiện có, tôi không thấy snippet nào hiển thị trực tiếp tên model ID chính xác của Kimi K2.6 trong request mẫu. [7][8]
  • Nếu cần kiểm tra khả năng truy cập và billing trước, có thể gọi endpoint balance bằng Bearer token. [5]

Nếu dùng bên trung gian thay vì API chính thức

  • Có tài liệu bên thứ ba từ AIMLAPI cho model kimi-k2-6, và ví dụ của họ gọi
    POST https://api.aimlapi.com/v1/chat/completions
    . [1]
  • Điều này cho thấy Kimi K2.6 cũng có thể được truy cập qua nhà cung cấp trung gian, nhưng đây không phải endpoint chính thức của Kimi/Moonshot. [1][3]

Điều đã kiểm chứng được và điều chưa chắc

  • Đã kiểm chứng được rằng Kimi API là OpenAI-compatible và dùng base URL https://api.moonshot.ai/v1. [3]
  • Đã kiểm chứng được rằng có tài liệu riêng cho Kimi K2.6 và tài liệu model list xác nhận Kimi K2.6 đã phát hành. [7][8]
  • Đã kiểm chứng được rằng nền tảng có các endpoint cho chat, list models, balance, và batch. [4][5][6][8]
  • Chưa kiểm chứng được từ bằng chứng hiện có tên model ID chính xác cần điền khi gọi Kimi K2.6 trong request body. Insufficient evidence. [7][8]

Nếu bạn muốn, tôi có thể viết tiếp cho bạn một mẫu hoàn chỉnh bằng curl, Python, hoặc JavaScript theo đúng kiểu OpenAI-compatible, với chỗ nào chưa xác minh được tôi sẽ đánh dấu rõ.

来源

  • [1] kimi-k2-6 | AI/ML API Documentationdocs.aimlapi.com

    import requests import requests import json for getting a structured output with indentation import json for getting a structured output with indentation response = requests.post( response = requests.post( " " headers={ headers={ Insert your AIML API Key in...

  • [2] Moonshot AI (Kimi K2.6) - TypingMind Docsdocs.typingmind.com

    Moonshot AI (Kimi K2.6). Step 1: Create a Moonshot API account. Go to and create a new Moonshot API account. Step 2: Set up Moonshot API account. To use the model via API, you’ll need to add balance to your account. Step 3: Get your Moonshot API key. Be sur...

  • [5] MoonshotAI: Kimi K2.6 – API Quickstart | OpenRouteropenrouter.ai

    MoonshotAI: Kimi K2.6. moonshotai/kimi-k2.6. Kimi K2.6 is Moonshot AI's next-generation multimodal model, designed for long-horizon coding, coding-driven UI/UX generation, and multi-agent orchestration. It handles complex end-to-end coding tasks across Pyth...

  • [13] API Overview - Kimi API Platformplatform.kimi.ai

    Using the API. API Reference. Batch API. API Overview. Kimi Open Platform provides OpenAI-compatible HTTP APIs. You can use the OpenAI SDK directly. When using SDKs, set base url to When calling HTTP endpoints directly, use the full path such as ​ OpenAI Co...

  • [14] Basic Information - Kimi API Platformplatform.kimi.ai

    create( model = "kimi-k2.5", model = "kimi-k2.5", messages = [ messages = [ {"role": "system", "content": "You are Kimi, an AI assistant provided by Moonshot AI. {{ "id": "cmpl-04ea926191a14749b7f2c7a48a68abc6", "id": "cmpl-04ea926191a14749b7f2c7a48a68abc6"...

  • [15] Check Balance - Kimi API Platformplatform.kimi.ai

    Kimi API Platform home pagelight logodark logo. Using the API. API Reference. Batch API. curl --request GET \ curl --request GET \ --url \ --url \ --header 'Authorization: Bearer ' --header 'Authorization: Bearer '. {{ "code": 123, "code": 123, "data": { "d...

  • [16] Create Batch - Kimi API Platformplatform.kimi.ai

    curl --request POST \ curl --request POST \ --url \ --url \ --header 'Authorization: Bearer ' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \ --data ' --data '{{ "input file id":...

  • [17] List Models - Kimi API Platformplatform.kimi.ai

    🎉 Kimi K2.6 has been released with improved long-context coding stability. Top-up bonus event in progress 🔗. Kimi API Platform home pagelight logodark logo. Using the API. Capabilities. API Reference. Files. Batch API. curl --request GET \ --url \ --heade...