| Nhu cầu |
|---|
| Cấu hình hoặc endpoint |
|---|
| Ghi chú |
|---|
| Dùng OpenAI SDK | | Kimi mô tả API là OpenAI-compatible và cho phép dùng OpenAI SDK trực tiếp. [ |
| Gọi chat realtime | | API overview nêu full path này; tài liệu Chat API dùng request theo kiểu model và messages. [ |
| Liệt kê model | | Endpoint trả danh sách model và mẫu phản hồi có trường id. [ |
| Kiểm tra số dư | | Tài liệu Check Balance dùng header |
| Tạo batch | | Tài liệu Batch API có endpoint tạo batch. [ |
Authorization: Bearer ...base_url sang https://api.moonshot.ai/v1. [/models trước khi gửi request thật. Endpoint List Models được thiết kế để liệt kê các model hiện có và mẫu phản hồi có trường id; đây là giá trị nên truyền vào tham số model. [model và messages. Tài liệu Chat API thể hiện request theo cấu trúc có model và messages, còn API overview nêu endpoint /chat/completions. [Đoạn dưới dùng đúng base_url do Kimi công bố cho OpenAI SDK. [13] Biến
KIMI_MODEL_ID phải là id lấy từ GET /models17]
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": "Xin chào, hãy tự giới thiệu ngắn gọn."}
],
)
print(response)Bước đầu tiên nên là liệt kê model trong tài khoản Moonshot/Kimi của bạn, vì endpoint này trả danh sách model cùng trường id. [17]
curl -sS https://api.moonshot.ai/v1/models \
-H "Authorization: Bearer $MOONSHOT_API_KEY"Sau khi chọn đúng id từ phản hồi, gửi request tới Chat Completions. Full path /chat/completions và cấu trúc request model + messages đều được mô tả trong tài liệu Kimi. [13][
14]
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": "Viết một đoạn giới thiệu ngắn về Kimi K2.6."}
]
}'Nếu request lỗi do billing hoặc bạn muốn kiểm tra tài khoản trước khi tích hợp, Kimi có endpoint balance tại /users/me/balance và ví dụ tài liệu dùng Bearer token. [15]
curl -sS https://api.moonshot.ai/v1/users/me/balance \
-H "Authorization: Bearer $MOONSHOT_API_KEY"Một số nhà cung cấp trung gian đặt model ID riêng cho Kimi K2.6. AIMLAPI dùng endpoint https://api.aimlapi.com/v1/chat/completions với model moonshot/kimi-k2-6. [1] OpenRouter hiển thị model
moonshotai/kimi-k2.6 trên trang API của họ. [5]
Các ID đó chỉ nên dùng khi bạn gọi qua đúng gateway tương ứng. Khi gọi endpoint chính thức https://api.moonshot.ai/v1/chat/completions, cách ít rủi ro nhất là gọi GET https://api.moonshot.ai/v1/modelsid mà Moonshot trả về cho tài khoản của bạn. [13][
17]
Luồng triển khai gọn nhất là: lấy API key, đặt OpenAI SDK base_url thành https://api.moonshot.ai/v1, gọi /models để xác minh model ID Kimi K2.6, rồi gửi request tới /chat/completions với model và messages. Cách này bám sát tài liệu OpenAI-compatible của Kimi và tránh lỗi phổ biến là copy model ID của AIMLAPI hoặc OpenRouter sang endpoint Moonshot chính thức. [1][
5][
13][
14][
17]
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"...
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...
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":...
🎉 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...
Comments
0 comments