Repository navigation
Add Kimi logins to the Workers-only install - #26
Merged
Merged
Conversation
Kimi's OAuth device flow, as in CPA: the dashboard's auth-url opens Kimi's page and each status poll asks Kimi once, no sooner than its interval. Logins (kimi.com and kimi.ai, CPA's kimi and kimi-ai auth files) are refreshed by the Durable Object and serve Claude Code, OpenAI Chat and Responses clients untranslated, with CPA's model name mapping. Requests identify as sub2api; the API host comes from the domain, never from a file's base_url.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by PlaygrndLabs · project thread
Third of the "more providers" PRs (phase 3) for
free/.What changes
oauth/auth-url?provider=kimi(orkimi-ai, or&domain=kimi.ai) asks Kimi for a device code and answers in CPA's shape:{status, url, state, flow: "device", user_code, expires_in}. Eachoauth/statuspoll from the dashboard asks Kimi once, and never sooner than the interval Kimi sets, includingslow_down. The sign-in finishes on that poll. No background loop is needed on Workers.kimi-*.jsonandkimi-ai-*.jsonauth files and refreshed by the Durable Object. When Kimi refuses a refresh token, the file is marked "token expired"./v1/messages), OpenAI Chat and OpenAI Responses clients all reach Kimi untranslated, atapi.kimi.com/coding/v1/...(orapi.kimi.ai). Model names follow CPA's mapping (kimi-k3→k3,kimi-k2.8→kimi-for-coding,[1m]dropped). A 401 gets the token refreshed.kimicatalog channel is added and listed while a Kimi login is on.Not impersonating
Requests carry
User-Agent: sub2apiandX-Msh-Platform: sub2api, with a random device id per login. That matches how CPA identifies itself to Kimi (asCLIProxyAPI). Nothing poses as Kimi's own CLI. As with the Claude and Codex logins, the OAuth client id is Kimi Code's.Security and safety check
kimi.comorkimi.ai). A file'sbase_urlis ignored, so an uploaded auth file can't send its token anywhere else. Auth hosts are fixed too.https://.authorizationis replaced with the login token, andx-api-keyisn't forwarded.Tests
vitest: 188 passed, including the newkimi.test.ts(device flow, slow polling, kimi.ai, refusal, refresh, base_url ignored, model mapping) and Kimi routing tests.tscandeslintare clean. Not yet tried against Kimi's live servers.Generated by Claude Code