Add CF_AI_GATEWAY_MODEL for arbitrary AI Gateway model selection#187
Merged
andreasjansson merged 8 commits intomainfrom Feb 6, 2026
Merged
Add CF_AI_GATEWAY_MODEL for arbitrary AI Gateway model selection#187andreasjansson merged 8 commits intomainfrom
CF_AI_GATEWAY_MODEL for arbitrary AI Gateway model selection#187andreasjansson merged 8 commits intomainfrom
Conversation
added 4 commits
February 6, 2026 19:09
- Quick Start: replace legacy AI_GATEWAY_* with new env vars - AI Gateway section: rewrite with explanation of how the gateway proxies requests and what each secret actually is - Clarify that CLOUDFLARE_AI_GATEWAY_API_KEY is your provider's API key (e.g. Anthropic key), not a Cloudflare-specific key — it's forwarded through the gateway to the upstream provider - All three secrets (API key + account ID + gateway ID) are required - Secrets table: add new vars, deprecate old AI_GATEWAY_* vars - Add legacy deprecation note
Add CF_AI_GATEWAY_MODEL env var (format: provider/model-id) that lets users choose any model through Cloudflare AI Gateway. The startup script parses the provider slug, constructs the correct gateway URL, picks the API type (anthropic-messages or openai-completions), and patches the OpenClaw config. Examples: workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast openai/gpt-4o anthropic/claude-sonnet-4-5 groq/llama-3.3-70b For Workers AI without an AI Gateway, falls back to the direct Cloudflare API using CF_ACCOUNT_ID. Changes: - types.ts: add CF_AI_GATEWAY_MODEL to MoltbotEnv - env.ts: pass CF_AI_GATEWAY_MODEL and CF_ACCOUNT_ID to container - env.test.ts: tests for new passthrough - start-openclaw.sh: config patch for provider + default model - README.md: document model selection, provider table, secrets ref - .dev.vars.example: add CF_AI_GATEWAY_MODEL
- Add new secrets: CLOUDFLARE_AI_GATEWAY_API_KEY, CF_AI_GATEWAY_ACCOUNT_ID, CF_AI_GATEWAY_GATEWAY_ID (keep legacy AI_GATEWAY_* for compat) - Pass CF_AI_GATEWAY_MODEL from matrix to env - Add 'workers-ai' matrix entry with CF_AI_GATEWAY_MODEL=workers-ai/@cf/openai/gpt-oss-120b
- Remove legacy ANTHROPIC_BASE_URL provider patching that creates a provider entry without a models array, breaking OpenClaw v2026.2.3 config validation. The Anthropic SDK picks up ANTHROPIC_BASE_URL from the environment natively. - Remove console.log that dumps the full config (including API keys and gateway tokens) to stdout.
f01affa to
1a3c118
Compare
added 4 commits
February 6, 2026 19:23
The deploy script was only pushing legacy AI_GATEWAY_* secrets. Add CLOUDFLARE_AI_GATEWAY_API_KEY, CF_AI_GATEWAY_ACCOUNT_ID, CF_AI_GATEWAY_GATEWAY_ID, and CF_AI_GATEWAY_MODEL.
OpenClaw v2026.2.3 requires explicit credentials when using --url override. All openclaw devices CLI invocations (list, approve, approve-all) now pass --token from MOLTBOT_GATEWAY_TOKEN. This was the root cause of 'Container service disconnected' errors and missing devices in the admin UI — the devices list CLI command was failing with 'gateway url override requires explicit credentials'.
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
CF_AI_GATEWAY_MODELenv var that lets users choose any model through Cloudflare AI Gateway — not just Anthropic. This enables Workers AI, OpenAI, Groq, and any other AI Gateway provider with a single env var.OpenClaw's built-in
cloudflare-ai-gatewayprovider hardcodes the/anthropicendpoint. This PR works around that by patching the config at startup to add a provider entry for whatever gateway provider the user specifies.Usage
npx wrangler secret put CF_AI_GATEWAY_MODEL # Enter: workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fastFormat is
provider/model-id. Works with any AI Gateway provider:workers-ai/@cf/openai/gpt-oss-120bopenai/gpt-4oanthropic/claude-sonnet-4-5groq/llama-3.3-70bRequires
CLOUDFLARE_AI_GATEWAY_API_KEY,CF_AI_GATEWAY_ACCOUNT_ID, andCF_AI_GATEWAY_GATEWAY_IDto be set. WhenCF_AI_GATEWAY_MODELis not set, existing behavior is unchanged (defaults to Anthropic Claude Sonnet 4.5).Changes
start-openclaw.sh: Config patch parsesprovider/model-id, constructs the gateway URL, picks the API type, and sets it as default modelsrc/types.ts,src/gateway/env.ts: PassCF_AI_GATEWAY_MODELandCF_ACCOUNT_IDthrough to containerREADME.md: Rewrite AI Gateway section with setup instructions, model selection docs, provider table, Unified Billing note, and legacy deprecation notice.dev.vars.example: AddCF_AI_GATEWAY_MODEL.github/workflows/test.yml: Add new AI Gateway secrets, addworkers-aimatrix entry