Add Kimi Code API usage source#1424
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed June 11, 2026, 3:28 AM ET / 07:28 UTC. Summary Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Review detailsBest possible solution: Retry the Codex review after fixing the execution failure. Do we have a high-confidence way to reproduce the issue? Unclear. The review failed before ClawSweeper could establish a reproduction path. Is this the best way to solve the issue? Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 9015e94901c4. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 966b807b0c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| func shouldFallback(on error: Error, context: ProviderFetchContext) -> Bool { | ||
| guard context.sourceMode == .auto else { return false } | ||
| if case KimiAPIError.missingToken = error { return true } | ||
| if case KimiAPIError.apiError = error { return true } | ||
| if error is URLError { return true } | ||
| return false |
There was a problem hiding this comment.
Fall back from invalid API keys in auto mode
In Auto mode, any stale or non-Code KIMI_API_KEY/saved apiKey makes the API strategy available, but a 401/403 is converted to KimiAPIError.invalidToken and this branch returns false, so the pipeline stops before trying valid manual/browser cookies. This especially affects users who already had KIMI_API_KEY for another Kimi/Moonshot integration and rely on the existing web-cookie Kimi provider; Auto no longer behaves as an API-then-web fallback unless the API failure is one of these narrower cases.
Useful? React with 👍 / 👎.
| throw KimiAPIError.missingToken | ||
| } | ||
|
|
||
| let endpoint = baseURL.appendingPathComponent("coding/v1/usages") |
There was a problem hiding this comment.
Avoid duplicating the Kimi coding path
When KIMI_CODE_BASE_URL or providers[].enterpriseHost is set to the documented Kimi Code base URL (https://api.kimi.com/coding/v1) or to a proxy that already exposes that base path, this appends another coding/v1/usages and requests /coding/v1/coding/v1/usages, so the API source fails only for configured/custom base URLs. Either normalize a full base URL or append only usages when the path already ends in /coding/v1.
Useful? React with 👍 / 👎.
Fixes #1412
Summary
.apisource mode that readsKIMI_API_KEY,KIMI_CODE_API_KEY, orproviders[].apiKeyand callsGET /coding/v1/usages..autouser-friendly by trying the Kimi Code API key first, then falling back to the existing Kimi web cookie strategy.Test plan
swift test --filter KimiProviderTests --skip-updateswift test --filter ProviderConfigEnvironmentTests --skip-updateswift test --filter CLIConfigCommandTests --skip-updateswift test --filter ProviderSettingsDescriptorTests --skip-updatemake checkgit diff --checkswift test --skip-updateran the full suite and hit an unrelatedStatusMenuSwitcherClickTestskeyboard-navigation failure in the full-suite order; immediate isolated rerun passed withswift test --filter StatusMenuSwitcherClickTests --skip-update(19 tests passed).No live Kimi account probe or browser/Keychain prompt was run; coverage is parser/config/settings/fetch-strategy level.