Skip to content

Add Cloudflare Workers AI provider with Zhipu GLM-5.2#18

Merged
msitarzewski merged 1 commit into
mainfrom
feat/cloudflare-glm-provider
Jun 22, 2026
Merged

Add Cloudflare Workers AI provider with Zhipu GLM-5.2#18
msitarzewski merged 1 commit into
mainfrom
feat/cloudflare-glm-provider

Conversation

@msitarzewski

Copy link
Copy Markdown
Owner

Adds a cloudflare provider 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:

  • OpenAIProvider gains an optional provider_id and resolves its catalog/capabilities from that id (was hardcoded to "openai"), so it can run alongside real OpenAI without colliding.
  • _setup_providers registers any enabled provider that has a base_url + key as an OpenAI-compatible adapter under its config name.

Cloudflare wiring (env-driven)

Set both in .env:

CLOUDFLARE_ACCOUNT_ID=...        # identifier (goes in the URL)
CLOUDFLARE_WORKERS_AI_TOKEN=...  # Workers AI API token (Run permission)

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:

  • Provider wires up from .env; @cf/zai-org/glm-5.2 appears in duh models
  • Plain text generation works (finish_reason=stop, token accounting correct)
  • JSON mode works — important since COMMIT and follow-up generation use response_format
  • Note: GLM-5.2 spends reasoning tokens, so it needs adequate max_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

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
@msitarzewski msitarzewski merged commit bc99eea into main Jun 22, 2026
3 checks passed
@msitarzewski msitarzewski deleted the feat/cloudflare-glm-provider branch June 22, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant