| Need | Configuration or endpoint | Notes |
|---|---|---|
| OpenAI SDK setup | base_url = https://api.moonshot.ai/v1 | Kimi describes the API as OpenAI-compatible and says the OpenAI SDK can be used directly. |
| Chat completions | POST https://api.moonshot.ai/v1/chat/completions | The API overview gives this full path; the Chat API uses the familiar model plus messages request shape. |
| List available models | GET https://api.moonshot.ai/v1/models | Returns the model list, including an id field you should pass as model. |
| Check balance | GET https://api.moonshot.ai/v1/users/me/balance | Kimi’s balance endpoint uses Authorization: Bearer .... |
| Create a batch job | POST https://api.moonshot.ai/v1/batches | Kimi also documents a batch creation endpoint. |
base_url to https://api.moonshot.ai/v1. /models before your real request. The List Models endpoint is designed to return available models and includes an id field; that is the value to pass into model. model and messages. Kimi’s Chat API follows the Chat Completions-style request structure, while the API overview documents /chat/completions as the direct HTTP path. This example uses the base_url Kimi publishes for OpenAI SDK usage. Set KIMI_MODEL_ID to the id returned by GET /models; do not guess it from the product name or copy it from another provider’s gateway.
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": "Hello, please introduce yourself briefly."}
],
)
print(response)
Start by listing the models available in your Moonshot/Kimi account, because this endpoint returns the model list with each model’s id.
curl -sS https://api.moonshot.ai/v1/models \
-H "Authorization: Bearer $MOONSHOT_API_KEY"
After you choose the correct id from the response, send a Chat Completions request. Kimi documents the full /chat/completions path and the model + messages request structure.
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": "Write a short introduction to Kimi K2.6."}
]
}'
If a request fails for billing reasons, or you simply want to verify the account before integrating, Kimi provides a balance endpoint at /users/me/balance and shows Bearer-token authentication in its example.
curl -sS https://api.moonshot.ai/v1/users/me/balance \
-H "Authorization: Bearer $MOONSHOT_API_KEY"
Some third-party gateways use their own model IDs for Kimi K2.6. AIMLAPI’s documentation shows calls to https://api.aimlapi.com/v1/chat/completions with model moonshot/kimi-k2-6. OpenRouter lists the model as moonshotai/kimi-k2.6 on its API page.
Those IDs belong to those providers’ routing layers. Use them only when you are calling the matching gateway. When you call Moonshot’s official https://api.moonshot.ai/v1/chat/completions endpoint, the lower-risk path is to call GET https://api.moonshot.ai/v1/models and use the exact id Moonshot returns for your account.
The clean Moonshot flow is: get an API key, set the OpenAI SDK base_url to https://api.moonshot.ai/v1, call /models to confirm the Kimi K2.6 model ID, then send your request to /chat/completions with model and messages. That keeps your implementation aligned with Kimi’s OpenAI-compatible API and avoids a common integration bug: pasting an AIMLAPI or OpenRouter model ID into Moonshot’s official endpoint.