# Moonshot AI (Kimi) API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/moonshot
Last checked: 2026-11-08

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Kimi API Platform API key | — | 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

1. Sign in to the Kimi API Platform at `platform.kimi.ai`.
2. Choose or create the project the key should belong to; project administrators and members can both create keys.
3. Open **API Keys** (`platform.kimi.ai/console/api-keys`) and create a key.
4. Copy the Kimi key and store it in `MOONSHOT_API_KEY`, as the Kimi docs recommend.

## 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

1. Create a new key in the same Kimi project.
2. Replace `MOONSHOT_API_KEY` wherever the old key is deployed.
3. Confirm requests succeed, then delete the old key on the API Keys page.

## How to revoke a Moonshot AI (Kimi) key

1. Delete the key on the API Keys page of the Kimi API Platform.
2. To cut off everything one person created, remove them from the project; all keys they created are invalidated.

## If the key leaked

1. Delete the exposed Kimi key.
2. Create a replacement in the same project and deploy it.
3. Set or lower the project's daily and monthly budgets so a future leak is capped.
4. Add an IP whitelist for the organization if your servers have fixed addresses.

## Environment variables

- `MOONSHOT_API_KEY`

## Gotchas

- Keys from `platform.kimi.ai` do 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.

## Using this key with AI agents (BotPassword)

- `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.

## FAQ

### 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.

## Sources

- https://platform.kimi.ai/docs/guide/start-using-kimi-api
- https://platform.kimi.ai/docs/api/errors
- https://platform.kimi.ai/docs/guide/org-best-practice
