Add Cloudflare Workers AI provider with Zhipu GLM-5.2#18
Merged
Conversation
Adds a "cloudflare" provider that talks to Cloudflare Workers AI's OpenAI-compatible endpoint, with GLM-5.2 (@cf/zai-org/glm-5.2) in the catalog. Generalizes the existing OpenAI adapter so it can serve any OpenAI-compatible host under its own provider id without colliding with real OpenAI. - OpenAIProvider gains an optional provider_id and resolves its model catalog/capabilities from that id (was hardcoded to "openai") - catalog.py: cloudflare capabilities + GLM-5.2 entry (262k context, $1.40/$4.40 per Mtok, per the Workers AI model page) - _setup_providers: generic branch registers any base_url+key provider as an OpenAI-compatible adapter under its config name - loader: CLOUDFLARE_ACCOUNT_ID + CLOUDFLARE_WORKERS_AI_TOKEN env vars configure the provider and build the account's Workers AI base URL - .env.example documents both vars Validated end-to-end against live Cloudflare: text generation, JSON mode (used by COMMIT/follow-ups), token accounting, and `duh models` listing. 1672 Python tests pass, mypy + ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EkrekgzMAQko92UkjnXhHL
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.
Adds a
cloudflareprovider backed by Cloudflare Workers AI's OpenAI-compatible endpoint, with GLM-5.2 (@cf/zai-org/glm-5.2) in the catalog.Design
Rather than a bespoke adapter, this generalizes the existing OpenAI adapter so it can serve any OpenAI-compatible host (Workers AI, Groq, Together, OpenRouter, AI Gateway) under its own provider id:
OpenAIProvidergains an optionalprovider_idand resolves its catalog/capabilities from that id (was hardcoded to"openai"), so it can run alongside real OpenAI without colliding._setup_providersregisters any enabled provider that has abase_url+ key as an OpenAI-compatible adapter under its config name.Cloudflare wiring (env-driven)
Set both in
.env:The loader builds the account's Workers AI base URL and configures the provider. Missing either var → no provider (graceful).
Catalog
@cf/zai-org/glm-5.2— 262,144 context, $1.40 / $4.40 per Mtok (from the Workers AI model page; max-output not published, conservative 32,768).Validation
Smoke-tested end-to-end against live Cloudflare:
.env;@cf/zai-org/glm-5.2appears induh modelsfinish_reason=stop, token accounting correct)response_formatmax_tokens(duh uses 32k budgets, so fine)1672 Python tests pass (9 new), mypy clean (63 files), ruff clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EkrekgzMAQko92UkjnXhHL