Repository navigation
Sign in to a Z.ai or BigModel account - #112
Merged
Merged
Conversation
The sign-in ends with an ordinary API key on the account, so the upstream it writes is a plain `anthropic` provider with a `key` — no `oauth` block, no refresh, no rotation. Z.ai's own client works the same way: a Coding Plan request carries nothing but that key, which is why the plan's quota follows the key and a direct call to the documented endpoint is enough. Three things about their protocol that the code has to know: - The authorization page belongs to their own client, because Z.ai does not let third parties register an OAuth app. The half we control is honest: our own User-Agent, a polling token we generate ourselves, and no field in the request where a client could claim to be someone else. - The browser lands on their page, not ours, so there is no callback server and no port to bind. Polling is the only way to learn the outcome. - Their business API answers HTTP 200 with a business error code in the body. Every call checks that code; otherwise a failure reads as a success and the real reason surfaces several steps later as something unrelated. Getting the key creates one on the account if there is none named `thinkwatch` — an existing one is reused. The UI has to say so before the sign-in starts. Also: GLM prices exist in the dataset only under a `zai/` prefix, so a bare `glm-5.2` resolved to nothing and every request through these upstreams had no cost at all. The prefixed key is now the last pricing candidate. `user_agent()` and `ORIGINATOR` move from the chatgpt module to the gateway root, since they are what we say about ourselves to any account API. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
fylorn
force-pushed
the
feat/zai-login
branch
from
September 23, 2026 04:09
bc73cd2 to
a9df71a
Compare
fylorn
added a commit
to ThinkWatchProject/ThinkWatch-Lite
that referenced
this pull request
Sep 23, 2026
A new entry in the service-type list, next to the ChatGPT account. The sign-in ends with an ordinary API key on the account, so what it writes is a plain anthropic upstream — everything after the sign-in is the same as any other upstream. Two differences from the ChatGPT dialog, both forced by their protocol: - There is no code-on-another-device path. Their platform only offers the browser flow. - The browser ends up on their page, not one of ours, so nothing hands the app back the focus and the dialog learns the outcome by polling. The dialog says two things before the sign-in can start: the authorization page belongs to their own client, because the service does not let third parties register an authorization app; and signing in creates an API key named thinkwatch on the account, or reuses the one already there. Requires the core release that carries ThinkWatchProject/ThinkWatch-Core#112. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
fylorn
added a commit
to ThinkWatchProject/ThinkWatch-Lite
that referenced
this pull request
Sep 23, 2026
A new entry in the service-type list, next to the ChatGPT account. The sign-in ends with an ordinary API key on the account, so what it writes is a plain anthropic upstream — everything after the sign-in is the same as any other upstream. Two differences from the ChatGPT dialog, both forced by their protocol: - There is no code-on-another-device path. Their platform only offers the browser flow. - The browser ends up on their page, not one of ours, so nothing hands the app back the focus and the dialog learns the outcome by polling. The dialog says two things before the sign-in can start: the authorization page belongs to their own client, because the service does not let third parties register an authorization app; and signing in creates an API key named thinkwatch on the account, or reuses the one already there. Requires the core release that carries ThinkWatchProject/ThinkWatch-Core#112. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.
Signing in to a Z.ai or BigModel account, the way the Z.ai client itself does it: the flow ends with an ordinary API key on the account, so what lands in
config.yamlis a plainanthropicupstream with akey. Nooauthblock, no refresh, no rotation —tw_gateway::oauthis not involved at all.The plan's quota follows the key: their own Coding Plan requests carry nothing but that key, and the documented endpoint for an Anthropic-compatible client is the same
https://api.z.ai/api/anthropicthis writes.What it adds
POST /zai/login→{id, authorize_url, expires_in_secs},GET /zai/login/{id},DELETE /zai/login/{id}. One sign-in at a time; a new one voids the one still running.Bearerprefix), find the account's organization and project, reuse or create an API key namedthinkwatch, read its secret half, write the upstream.Three protocol facts worth stating
client_idin the address they hand us is theirs. The half we control is honest: our own User-Agent on every call, a polling token we generate ourselves, and no field anywhere in the request where a client could claim to be someone else. The UI has to say whose page the user is looking at.{"code":401,...}, measured). Every call checks that code. Without it a failure reads as a success and the real reason resurfaces several steps later as something unrelated — there is a test for exactly that.Side effect the UI must disclose
Getting the key creates one on the user's account when there is no key named
thinkwatchyet; an existing one is reused. Not the name their client uses — a key's owner has to be recognizable in the user's own console.Pricing, which was broken for these models anyway
GLM prices exist in the dataset only under a
zai/prefix, so a bareglm-5.2resolved to nothing and every request through such an upstream had no cost at all. The prefixed key is now the last pricing candidate — after the exact name and the stripped ones, since a reseller's price is not the official one.Also
user_agent()andORIGINATORmove from the chatgpt module to the gateway root: they are what we say about ourselves to any account API, not something specific to Codex.Tests
crates/tw-control/tests/zai.rs, against a fake Z.ai on loopback — the write, waiting throughpending, the 200-with-a-business-error case, re-login keeping the user's settings, a name that belongs to another service being a conflict, BigModel's different auth and its key without a secret half, an unknown family or proxy refused before anything is started, and cancel/replace.cargo clippy --workspace --all-targetsandcargo test --workspaceare clean.🤖 Generated with Claude Code