Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(kimi-coding): surface an OAuth refresh failure instead of an empty key

Jack Rudenko95d17a83aaa1
diff --git a/packages/cli/src/auth/kimi-oauth.ts b/packages/cli/src/auth/kimi-oauth.ts
index d8d4c016..d4098ff3 100644
--- a/packages/cli/src/auth/kimi-oauth.ts
+++ b/packages/cli/src/auth/kimi-oauth.ts
@@ -558,7 +558,11 @@ export class KimiOAuth {
this.credentials = null;
// FIX H4: Check for API key fallback (FR5 priority)
- if (process.env.MOONSHOT_API_KEY || process.env.KIMI_API_KEY) {
+ if (
+ process.env.MOONSHOT_API_KEY ||
+ process.env.KIMI_API_KEY ||
+ process.env.KIMI_CODING_API_KEY
+ ) {
log("[KimiOAuth] Falling back to API key mode");
// Return empty string to signal fallback to handler
// Handler will detect API key and use it instead
diff --git a/packages/cli/src/providers/transport/anthropic-compat.ts b/packages/cli/src/providers/transport/anthropic-compat.ts
index 811caed4..2d45a393 100644
--- a/packages/cli/src/providers/transport/anthropic-compat.ts
+++ b/packages/cli/src/providers/transport/anthropic-compat.ts
@@ -7,6 +7,8 @@
*/
import { credentials } from "../../auth/credentials/authority.js";
+import { isTransientCredentialError } from "../../auth/credentials/credential-error.js";
+import { classifyConnectionError } from "../../handlers/shared/connection-error.js";
import type { RemoteProvider } from "../../handlers/shared/remote-provider-types.js";
import { log } from "../../logger.js";
import { getProviderByName } from "../provider-definitions.js";
@@ -89,6 +91,15 @@ export class AnthropicProviderTransport implements ProviderTransport {
}
Object.assign(headers, auth.headers);
} catch (e: any) {
+ // Swallowing everything here was the transport-catch bug (CLAUDE.md):
+ // the producer's structured error never reached ComposedHandler, and the
+ // request went out with `x-api-key: ""`, whose 401 became a terminal
+ // 400. Rethrow what the auth site must classify: a network fault (it
+ // recovers), a token host's 429/5xx (it retries), and any failure when
+ // there is no coding-plan key to fall back to (a dead login then says
+ // `claudish login kimi`). Only with a KIMI_CODING_API_KEY — the same
+ // flat-rate plan — does the request fall back to it.
+ if (classifyConnectionError(e) || isTransientCredentialError(e) || !this.apiKey) throw e;
log(`[${this.displayName}] OAuth path failed, falling back to API key: ${e.message}`);
}
}