Repository navigation
Fix Kimi K2.5 401: add Moonshot Platform provider, trim pasted keys - #308
zwanski-start wants to merge 1 commit into
Conversation
…als (AutoForgeAI#188) The existing Kimi provider points at the Kimi Code subscription endpoint (api.kimi.com/coding), which rejects pay-as-you-go keys from platform.moonshot.ai with a 401. Add a separate Moonshot Platform provider (api.moonshot.ai/anthropic, ANTHROPIC_AUTH_TOKEN), relabel the existing one as Kimi Code, and explain the difference in the Settings UI. Also strip whitespace from saved API keys/base URLs and reset the base URL when switching providers so a stale URL is never paired with a new provider's key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🔍 QA report: ✅ PassedTester: Ada (cubefarm agent, in a fresh session) · Round: 1 · Author: Ken The PR adds a separate 'Moonshot Platform' provider (api.moonshot.ai/anthropic, ANTHROPIC_AUTH_TOKEN) next to the renamed 'Kimi Code' provider, whose ID, URL and auth variable are unchanged. This fixes the likely cause of #188: a platform.moonshot.ai key being sent to the Kimi Code endpoint. Pasted keys and base URLs are now trimmed, and switching provider resets the base URL to the new provider's default; both were confirmed against the running server. Tests, ruff, UI lint/build pass and mypy reports nothing in the changed files. Non-blocking: the Moonshot help text tells mainland-China users to set the base URL, but the Settings UI has no base-URL field for this provider.
🧪 Commands run
No browser screenshots were taken in this round. Posted by cubefarm · merges automatically once GitHub's checks pass |
… keys and URLs Adaptations: - manual merge with AutoForgeAI#241/AutoForgeAI#272 (provider lists, test file, Settings texts); - the Base URL field now shows for Moonshot too (its help text asks China users to change the URL, which the UI did not allow); - a provider switch also clears the saved auth token: base URL and token are global settings shared by every provider, so the previous provider's secret key was sent to the new provider's server (and the UI showed it as set). test_settings_provider_switch covers the router. Integrates AutoForgeAI#308 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeH26pcsqoxPb3CDs8g1VN
Problem
The "Kimi K2.5 (Moonshot)" provider is hardcoded to
https://api.kimi.com/coding/, the Kimi Code subscription endpoint. That endpoint only accepts Kimi Code keys (sk-kimi-...from kimi.com). Pay-as-you-go keys from the Moonshot open platform (platform.moonshot.ai) get rejected there with401 authentication_error ... API Key appears to be invalid, which is the error in the issue. Those keys needhttps://api.moonshot.ai/anthropic(or.cnin mainland China), sent asANTHROPIC_AUTH_TOKEN.Changes
registry.pykimiprovider to "Kimi Code (kimi.com subscription)". Its ID, URL and auth var are unchanged, so existing setups keep working.moonshotprovider, "Moonshot Platform (Kimi K2.5 API)": base URLhttps://api.moonshot.ai/anthropic, auth viaANTHROPIC_AUTH_TOKEN, modelskimi-k2.5(default) andkimi-k2-turbo-preview.get_effective_sdk_env()strips whitespace from the stored key and base URL. A trailing space or newline from copy-paste also causes opaque 401s. A blank base URL now falls back to the provider default.server/routers/settings.py: keys and base URLs are trimmed when saved. When you switch provider, the base URL is reset to the new provider's default (or empty for Custom/Azure). Before, the previous provider's URL could stay and be sent with the new provider's key.SettingsView.tsx,SettingsModal.tsx): help text says which kind of key each Kimi option takes and points to the other option. Buttons now show "Kimi Code" and "Moonshot Platform".test_api_providers.py(5 tests) covering the env built for each provider, the base URL override, and trimming.Verification
pytest test_api_providers.py: 5 passed.ruff check .clean.test_security.pyall pass. mypy shows no new errors in the changed files; the existing errors are in other modules.ui:npm run lint(0 errors) andnpm run buildsucceed./api/settings/providerslists the new provider.PATCH /api/settings {"api_provider":"moonshot"}sets the base URL tohttps://api.moonshot.ai/anthropicand the model tokimi-k2.5. In the Settings page, the Kimi Code and Moonshot Platform buttons show the correct help text and models.Assumptions
api.kimi.com/coding/withANTHROPIC_API_KEY, and Moonshot Platform usesapi.moonshot.ai/anthropicwithANTHROPIC_AUTH_TOKEN.Closes #188
🤖 Generated with Claude Code