Moonshot AI's Kimi API keys are created on the API Keys page of the Kimi API Platform (platform.kimi.ai/console/api-keys) and sent as Authorization: Bearer <key> to https://api.moonshot.ai/v1. Kimi's documentation stores the key in MOONSHOT_API_KEY and uses the OpenAI SDKs unchanged apart from the base URL. Keys live inside projects, and a key from one regional Kimi platform returns 401 on another.
Moonshot AI (Kimi) key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Kimi API Platform API key Moonshot does not document a key prefix or expiry. Removing a member from a project invalidates every key that member created. Kimi Code subscription keys are a separate product and are not interchangeable. | — | Yes | Every Kimi model in one project, spending the organization's balance within the project's budget and rate limits | — |
How to create a Moonshot AI (Kimi) key
- Sign in to the Kimi API Platform at
platform.kimi.ai. - Choose or create the project the key should belong to; project administrators and members can both create keys.
- Open API Keys (
platform.kimi.ai/console/api-keys) and create a key. - Copy the Kimi key and store it in
MOONSHOT_API_KEY, as the Kimi docs recommend.
Open Moonshot AI (Kimi)'s key settings
Limiting what the key can do
Kimi keys have no per-model permissions; the limits sit on the project and organization. A project can have a daily or monthly budget, and once spending reaches a budget above zero, later requests for that project are rejected, though Kimi warns enforcement can lag and charges during the delay still apply. Each project's tokens-per-minute limit cannot exceed the organization's. An organization-wide IP whitelist of up to 20 public IPv4 addresses or CIDR ranges blocks requests from anywhere else with a 403; saving the list replaces it, and an empty list removes the restriction. Default organizations can hold 20 projects and 50 keys, enterprise-verified ones 50 projects and 100 keys.
How to rotate a Moonshot AI (Kimi) key
- Create a new key in the same Kimi project.
- Replace
MOONSHOT_API_KEYwherever the old key is deployed. - Confirm requests succeed, then delete the old key on the API Keys page.
Kimi does not document an in-place regenerate, so rotation is create, deploy, delete. Because a project can hold several keys, the old and new keys can run side by side during the switch.
How to revoke a Moonshot AI (Kimi) key
- Delete the key on the API Keys page of the Kimi API Platform.
- To cut off everything one person created, remove them from the project; all keys they created are invalidated.
If your Moonshot AI (Kimi) key leaked
- Delete the exposed Kimi key.
- Create a replacement in the same project and deploy it.
- Set or lower the project's daily and monthly budgets so a future leak is capped.
- Add an IP whitelist for the organization if your servers have fixed addresses.
Environment variables and CLI
Moonshot AI (Kimi)'s SDKs and docs read the key from MOONSHOT_API_KEY.
Things that catch people out
- Keys from
platform.kimi.aido not work on other regional Kimi platforms; mixing a key and an endpoint from different regions returns 401. exceeded_current_quota_error(HTTP 429) means the balance is too low, the account is disabled or token quota is used up, not that the key is wrong.- Removing a project member silently invalidates every key they created, which can break shared services that used one of those keys.
Common Moonshot AI (Kimi) authentication errors
invalid_authentication_error - Invalid Authentication
HTTP 401. The Kimi key is invalid or badly formatted, or it was created on a different regional Kimi platform from the endpoint being called.
incorrect_api_key_error - Incorrect API key provided
HTTP 401. No key was sent, or the key is wrong.
permission_denied_error - Your IP is not allowed to access this organization
HTTP 403. The calling IP address is not on the organization's IP whitelist.
Using your Moonshot AI (Kimi) key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Moonshot AI (Kimi) key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I get a Kimi API key?
Sign in to the Kimi API Platform and open API Keys at platform.kimi.ai/console/api-keys to create and copy a key.
What is the Moonshot API base URL?
https://api.moonshot.ai/v1. Kimi says its API is compatible with the OpenAI format, so set this as the OpenAI SDK's base_url and pass the Kimi key.
What environment variable should hold a Kimi API key?
Kimi's quickstart recommends an environment variable and uses MOONSHOT_API_KEY in its examples.
Why does my Kimi API key return 401?
Either the key is wrong or missing, or it was created on a different regional Kimi platform from the endpoint you are calling. Match the endpoint to the platform where the key was made.
Can I use a Kimi API key with a coding agent?
Yes, through any agent that accepts an OpenAI-compatible base URL. Put the agent's key in its own project with a daily budget, so a runaway session stops at the budget instead of draining the balance.
Can an AI agent use my Moonshot AI (Kimi) key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, so the agent gets the result and never the value.