MoonshotAI / MoonshotAI/kimi-code
`/login` duplicates platform API key into `managed:kimi-code` provider where it always fails — confusing startup error
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Problem
When a user runs /login and enters a Kimi Platform API key (platform.kimi.ai / api.moonshot.ai), the CLI writes it to TWO places in config.toml:
[providers.moonshot-ai].api_key— where it works correctly[providers."managed:kimi-code"].api_key— which points athttps://api.kimi.com/coding/v1, a different realm that only accepts Kimi Code subscription credentials
At startup, the model-list refresh for managed:kimi-code hits api.kimi.com/coding/v1/models with the platform key and gets rejected. The user sees:
Skipped refreshing managed:kimi-code: Kimi Code models endpoint https://api.kimi.com/coding/v1 rejected the API key: The API Key appears to be invalid or may have expired.
This is confusing because:
- The key just worked moments ago in
/login - The error doesn't say which key or which endpoint failed
- The user has no way to know the platform key was duplicated into a wrong provider
Additionally, if the user previously logged in via Kimi Code OAuth, an expired OAuth token stays in ~/.kimi-code/credentials/kimi-code.json forever — never cleaned up or flagged for re-login.
Reproduction
- Start Kimi Code CLI fresh
- Run
/login, enter a platform.kimi.ai API key - See the startup banner with the "rejected the API key" warning
Expected behavior
/loginshould only write the key to the matching provider (e.g.moonshot-aifor platform keys,managed:kimi-codefor Kimi Code subscription)- The startup warning should include the provider name that failed, not a generic "the API Key"
- Expired OAuth credentials should be cleaned up or the user prompted to re-authenticate
Environment
- Kimi Code v0.41.0
- Config:
~/.kimi-code/config.toml - Credentials:
~/.kimi-code/credentials/kimi-code.json
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the /login flow and startup model-list refresh, using ~/.kimi-code/config.toml and ~/.kimi-code/credentials/kimi-code.json as the affected persistence points. Verify provider-specific key handling, make the startup warning identify the failed provider, and define how expired OAuth credentials trigger cleanup or re-authentication.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100