Skip to main content

Service Address

https://api.moonshot.ai
Kimi Open Platform provides OpenAI-compatible HTTP APIs. You can use the OpenAI SDK directly. When using SDKs, set 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_url to https://api.moonshot.ai/v1 to 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:
Authorization: Bearer $MOONSHOT_API_KEY
API Keys can be created and managed in the Kimi Open Platform Console.
Your API Key is sensitive. Do not expose it in client-side code, public repositories, or logs. Use environment variables to manage it.

SDK Installation

pip install --upgrade 'openai>=1.0'
Initialize the client:
from openai import OpenAI

client = OpenAI(
    api_key="$MOONSHOT_API_KEY",
    base_url="https://api.moonshot.ai/v1",
)
Python version ≥ 3.7.1, Node.js version ≥ 18, OpenAI SDK version ≥ 1.0.0.
python -c 'import openai; print("version =", openai.__version__)'

Common Request Headers

HeaderValueDescription
Content-Typeapplication/jsonRequest body format
AuthorizationBearer $MOONSHOT_API_KEYAuthentication token

Error Handling

When a request fails, the API returns a JSON error response containing error.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

EndpointMethodDescription
/v1/chat/completionsPOSTCreate Chat Completion
/v1/modelsGETList Models
/v1/tokenizers/estimate-token-countPOSTEstimate Tokens
/v1/users/me/balanceGETCheck Balance
/v1/filesPOSTUpload File
/v1/filesGETList Files
/v1/files/{file_id}GETGet File Info
/v1/files/{file_id}DELETEDelete File
/v1/files/{file_id}/contentGETGet 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