feat(provider): add Cloudflare Workers AI integration (#1100)#1178
feat(provider): add Cloudflare Workers AI integration (#1100)#11780xfandom wants to merge 1 commit into
Conversation
Adds Cloudflare Workers AI as a first-class OpenAI-compatible provider
preset, modeled on the Venice / Xiaomi MiMo descriptors.
- New `src/integrations/vendors/cloudflare.ts` descriptor:
- `classification: 'openai-compatible'`
- Default base URL with literal `<ACCOUNT_ID>` placeholder — users
substitute via `/provider` baseUrl edit, same shape as the Azure
OpenAI example already in `docs/advanced-setup.md`
- `CLOUDFLARE_API_TOKEN` env, with `OPENAI_API_KEY` as fallback
- `removeBodyFields: ['store']` since Workers AI rejects unknown
OpenAI body fields (mirrors Mistral / Gemini / Cerebras strip)
- Static catalog with current Workers AI chat models
(`@cf/meta/llama-3.3-70b-instruct-fp8-fast`,
`@cf/meta/llama-3.1-8b-instruct`,
`@cf/deepseek-ai/deepseek-r1-distill-qwen-32b`,
`@cf/qwen/qwen2.5-coder-32b-instruct`)
- Validation routing on `api.cloudflare.com` /
`gateway.ai.cloudflare.com` hosts so an env-pasted URL maps back
to the preset
- Env mirror sites in `src/utils/providerProfiles.ts`: mirror api key
into `CLOUDFLARE_API_TOKEN` when baseUrl contains a Cloudflare host
(3 sites: same-env check, openAIProfileEnv build, applyEnv).
- `CLOUDFLARE_API_TOKEN` added to `PROFILE_ENV_KEYS` / `SECRET_ENV_KEYS` /
`ProfileEnv` / `SecretValueSource` in `src/utils/providerProfile.ts`
so the profile-clean and secret-redact paths know about it.
- `src/utils/providerFlag.ts` `--provider <name>` startup flag now
detects a Cloudflare profile from `OPENAI_API_KEY ===
CLOUDFLARE_API_TOKEN` (mirrors how the other host-key mirrors are
reverse-mapped to their preset id).
- `bun run scripts/generate-integrations-artifacts.ts` regenerated
`integrationArtifacts.generated.ts` to include the cloudflare preset
+ route + vendor.
- Tests: `compatibility.test.ts` PRESETS list, new
`buildProfileSaveMessage` Cloudflare case in `provider.test.tsx`,
new `applyProviderProfileToProcessEnv` Cloudflare case in
`providerProfiles.test.ts`.
- Docs: README providers table row + `docs/advanced-setup.md` section
matching the MiMo / Mistral entries.
## Out of scope (clean follow-ups)
- Dedicated AI Gateway integration with `gateway_id` URL templating.
Today users can still paste a full Gateway URL into `OPENAI_BASE_URL`
and the preset's `matchBaseUrlHosts` picks `gateway.ai.cloudflare.com`
up.
- Dynamic `/models` discovery on the Groq Gitlawb#1143 / `mapModel` pattern —
Cloudflare's `/v1/models` returns the runnable model list and the
hybrid catalog path drops in cleanly. Left as a separate PR so this
one stays a focused preset add.
Closes Gitlawb#1100
jatmn
left a comment
There was a problem hiding this comment.
Findings
- [P2] Narrow Cloudflare gateway URL matching to Workers AI routes
src/integrations/vendors/cloudflare.ts:52
Addinggateway.ai.cloudflare.comtomatchBaseUrlHostsmakes every Cloudflare AI Gateway URL resolve to the newcloudflareroute, becauseresolveRouteIdFromBaseUrl()matches these entries by hostname only. That includes non-Workers-AI Gateway URLs such ashttps://gateway.ai.cloudflare.com/v1/<account>/<gateway>/openai, which now get Workers-AI-specific runtime metadata and credential precedence (max_tokens,removeBodyFields: ['store'], no Responses format selection, andCLOUDFLARE_API_TOKENbeforeOPENAI_API_KEY). Please either remove the broad gateway host match or add path-aware matching that only classifies Workers AI/compat Gateway paths as this preset, with coverage that another provider's Cloudflare AI Gateway URL remains custom/OpenAI-compatible.
Blockers
Non-Blocking
Looks Good
Verdict: Changes Requested — gateway URL matching needs to be narrowed to Workers AI routes. |
|
please rebase from main, this should fix your smoke issues |
|
Confirmed @jatmn's point against the code: |
Summary
Adds Cloudflare Workers AI as a first-class OpenAI-compatible provider preset, mirroring the Venice (#1109) / Xiaomi MiMo (#1152) descriptor pattern.
src/integrations/vendors/cloudflare.tsdescriptor:classification: 'openai-compatible'<ACCOUNT_ID>placeholder — users substitute via/providerbaseUrl edit, same shapedocs/advanced-setup.mdalready uses for Azure OpenAI (https://your-resource.openai.azure.com/...)CLOUDFLARE_API_TOKENenv var (OPENAI_API_KEYfallback per the Mistral / MiMo precedent)removeBodyFields: ['store']— Workers AI rejects unknown OpenAI body fields; mirrors the Mistral / Gemini / Cerebras strip pattern@cf/meta/llama-3.3-70b-instruct-fp8-fast,@cf/meta/llama-3.1-8b-instruct,@cf/deepseek-ai/deepseek-r1-distill-qwen-32b,@cf/qwen/qwen2.5-coder-32b-instruct)api.cloudflare.com/gateway.ai.cloudflare.comhosts so a user-edited URL maps back to this presetsrc/utils/providerProfiles.tsandsrc/utils/providerProfile.tssoCLOUDFLARE_API_TOKENflows through the same code pathsVENICE_API_KEY/MIMO_API_KEYalready use (3 mirror sites +PROFILE_ENV_KEYS/SECRET_ENV_KEYS/ProfileEnv/SecretValueSource)src/utils/providerFlag.ts--provider <name>startup flag now reverse-maps a profile fromOPENAI_API_KEY === CLOUDFLARE_API_TOKEN(matches how the other mirrored providers are detected)bun run scripts/generate-integrations-artifacts.tsregeneratedintegrationArtifacts.generated.tsto include thecloudflarepreset / route / vendor entries.compatibility.test.ts(PRESETS list),provider.test.tsx(buildProfileSaveMessageCloudflare case),providerProfiles.test.ts(applyProviderProfileToProcessEnvCloudflare case).docs/advanced-setup.mdsection.Impact
/providernow offers a Cloudflare Workers AI preset. Users with a Cloudflare account get a guided onboarding path instead of having to construct the OpenAI-compatible env vars by hand. Existing users on other providers see no change.providerProfiles.ts+ 1 reverse-map branch inproviderFlag.ts. Pattern is byte-for-byte parallel to the recent Venice and Xiaomi MiMo merges.What this does NOT do (clean follow-ups)
gateway_idURL templating. Today users can paste a full Gateway URL intoOPENAI_BASE_URLand the preset'smatchBaseUrlHostspicksgateway.ai.cloudflare.comup — but there's no first-class onboarding for it./modelsdiscovery on the Groq feat(groq): dynamic model discovery with mapModel filtering and hybrid catalog #1143 /mapModelpattern. Cloudflare's/v1/modelsreturns the runnable model list; switching the catalog tosource: 'hybrid'is a clean drop-in change. Left as a separate PR so this one stays a focused preset add.Testing
bun run build— greenbun test src/integrations/ src/commands/provider/ src/utils/providerProfiles.test.ts src/utils/providerFlag.test.ts src/utils/providerProfile.test.ts— 303/303 passbun run smoke— fails on this checkout withCannot find package '@orama/orama'; reproduces on clean upstreammainHEAD94e8ff3(pre-existing local env issue, unrelated to this change)Notes
removeBodyFields: ['store']. No new transport, no new auth shape.<ACCOUNT_ID>placeholder URL is intentional — Cloudflare's Workers AI endpoint is account-scoped and there's no way to derive the id from credentials alone. The provider description (Replace <ACCOUNT_ID> in the base URL with your Cloudflare account id.) surfaces the substitution requirement in setup.bun run scripts/generate-integrations-artifacts.ts --checksucceeds against the regenerated file.Closes #1100