feat(ai): add Kimi Code subscription OAuth login (#6935)

Add a device authorization grant flow (RFC 8628) for the kimi-coding
provider, mirroring the official Kimi Code CLI: device authorization and
token polling against https://auth.kimi.com, refresh-token rotation with
retry/backoff, and Bearer auth via toAuth headers. The provider now
offers 'Sign in with Kimi Code' alongside the existing KIMI_API_KEY
auth. Host is overridable via KIMI_CODE_OAUTH_HOST / KIMI_OAUTH_HOST.

Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
This commit is contained in:
zay
2026-07-22 02:35:03 -04:00
committed by GitHub
parent 1ae064099c
commit a5afc3f171
6 changed files with 581 additions and 2 deletions
+10 -2
View File
@@ -1,5 +1,6 @@
import { anthropicMessagesApi } from "../api/anthropic-messages.lazy.ts";
import { envApiKeyAuth } from "../auth/helpers.ts";
import { envApiKeyAuth, lazyOAuth } from "../auth/helpers.ts";
import { loadKimiCodingOAuth } from "../auth/oauth/load.ts";
import { createProvider, type Provider } from "../models.ts";
import { KIMI_CODING_MODELS } from "./kimi-coding.models.ts";
@@ -8,7 +9,14 @@ export function kimiCodingProvider(): Provider<"anthropic-messages"> {
id: "kimi-coding",
name: "Kimi For Coding",
baseUrl: "https://api.kimi.com/coding",
auth: { apiKey: envApiKeyAuth("Kimi API key", ["KIMI_API_KEY"]) },
auth: {
apiKey: envApiKeyAuth("Kimi API key", ["KIMI_API_KEY"]),
oauth: lazyOAuth({
name: "Kimi Code (subscription)",
loginLabel: "Sign in with Kimi Code",
load: loadKimiCodingOAuth,
}),
},
models: Object.values(KIMI_CODING_MODELS),
api: anthropicMessagesApi(),
});