feat: add GLM (z.ai) provider#34
Open
antonioacg wants to merge 1 commit into
Open
Conversation
z.ai exposes an Anthropic-compatible Messages API, so the GLM provider is a thin pass-through: it forwards the Anthropic request verbatim (after stripping the local [1m] compaction hint), authenticates with a static API key, and pipes the upstream Anthropic SSE/JSON reply back to Claude Code unchanged. No format translation, no OAuth.
- providers/glm/{auth,client,mod}.rs: provider + API-key auth (CCP_GLM_API_KEY / GLM_API_KEY env, or 'glm auth login' stdin prompt) via the shared KeychainFileAuthStore
- registry: register glm-4.7 / glm-5.2, routed by model id
- config: glm.baseUrl (CCP_GLM_BASE_URL, default https://api.z.ai/api/anthropic)
- main: glm auth login|status|logout subcommands
- README: provider section, model table, env/config rows, auth commands
count_tokens uses a rough local estimate (like the cursor provider) to avoid an upstream round-trip. Responses are buffered before forwarding, matching the existing codex/kimi providers. Smoke-tested end-to-end against z.ai.
Owner
|
Hi, I'm not sure this is needed because z.ai has an Anthropic compatible API directly. |
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.
What
Adds a GLM (z.ai) provider exposing
glm-4.7andglm-5.2.Why
z.ai speaks the Anthropic Messages API natively (
https://api.z.ai/api/anthropic), so unlike the Codex/Kimi/Grok/Cursor providers it needs no request/response translation. The provider is a thin pass-through: it forwards the Anthropic request verbatim (after stripping the local[1m]compaction hint), authenticates with a static API key, and pipes the upstream Anthropic SSE/JSON reply back to Claude Code unchanged. This lets GLM users route through the same localserveprocess as the other providers (unified monitoring, model routing, traffic capture).How
src/providers/glm/{auth,client,mod}.rs— provider + API-key auth.CCP_GLM_API_KEY(aliasGLM_API_KEY) env takes precedence; otherwiseglm auth loginreads the key from stdin. Stored via the existingKeychainFileAuthStore(Keychain serviceclaude-code-proxy.glm, with the same file fallback the other providers use).src/registry.rs— registerglm-4.7/glm-5.2, routed by model id (consistent with codex/kimi).src/config.rs—glm.baseUrl(CCP_GLM_BASE_URL, defaulthttps://api.z.ai/api/anthropic).src/main.rs—glm auth login|status|logoutsubcommands; listed inmodels/banner.README.md— provider section, model routing, env/config rows, auth commands, limitations.handle_count_tokensuses a rough local estimate (like the cursor provider) to avoid an upstream round-trip. Streaming responses are buffered before forwarding, matching the existing codex/kimi providers.Verification
cargo build,cargo fmt --all --check,cargo test --all(incl. new registry routing + auth round-trip tests) pass.serve+ a streamingPOST /v1/messageswithmodel: glm-5.2returns a well-formed Anthropic SSE stream (message_start->content_block_delta->message_stop) with genuine usage.main(which landed Grok in the meantime); the GLM provider coexists cleanly with the other providers.Notes
deviceprints guidance pointing at the env var /login.[1m]suffix is stripped before forwarding (consistent with codex/kimi).Related: #4 (routing to an Anthropic-native backend).