Service Address
base_url to https://api.moonshot.ai/v1. When calling HTTP endpoints directly, use the full path such as https://api.moonshot.ai/v1/chat/completions.
OpenAI Compatibility
Our API is compatible with the OpenAI Chat Completions API in request/response format. This means:- You can use the official OpenAI SDKs (Python / Node.js) directly
- Most OpenAI-compatible third-party tools and frameworks (LangChain, Dify, Coze, etc.) are supported
- Simply point
base_urltohttps://api.moonshot.ai/v1to switch
Some parameters are Kimi-specific extensions: the
thinking parameter needs to be passed via the SDK’s extra_body; partial is a field on assistant messages within the messages array ("partial": true), not a top-level request parameter. See Tool Use and Partial Mode for details.Authentication
All API requests require an API Key in the HTTP header:SDK Installation
Python version ≥ 3.7.1, Node.js version ≥ 18, OpenAI SDK version ≥ 1.0.0.
Common Request Headers
| Header | Value | Description |
|---|---|---|
Content-Type | application/json | Request body format |
Authorization | Bearer $MOONSHOT_API_KEY | Authentication token |
Error Handling
When a request fails, the API returns a JSON error response containingerror.type and error.message fields. Common HTTP status codes include 400 (bad request), 401 (authentication failure), 429 (rate limit), 500 (server error), etc.
For the full list of error types, messages, and troubleshooting tips, see Errors.
API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/chat/completions | POST | Create Chat Completion |
/v1/models | GET | List Models |
/v1/tokenizers/estimate-token-count | POST | Estimate Tokens |
/v1/users/me/balance | GET | Check Balance |
/v1/files | POST | Upload File |
/v1/files | GET | List Files |
/v1/files/{file_id} | GET | Get File Info |
/v1/files/{file_id} | DELETE | Delete File |
/v1/files/{file_id}/content | GET | Get File Content |
Next Steps
Quickstart
Send your first API request
Models Overview
Compare model capabilities and parameters
Tool Use
Enable function calling
Create Chat Completion
Full endpoint parameter reference