Skip to content

[Feature] Add Cloudflare AI Gateway and Workers AI as separate providers - #1276

Open
pridemusvaire wants to merge 7 commits into
RooCodeInc:developfrom
pridemusvaire:feat/cloudflare-inference-providers
Open

[Feature] Add Cloudflare AI Gateway and Workers AI as separate providers#1276
pridemusvaire wants to merge 7 commits into
RooCodeInc:developfrom
pridemusvaire:feat/cloudflare-inference-providers

Conversation

@pridemusvaire

Copy link
Copy Markdown
Contributor

Summary

  • Add Cloudflare AI Gateway and Cloudflare Workers AI as two independent inference providers in Setup and Settings, not one combined Cloudflare provider.
  • AI Gateway collects an API token, account ID, and gateway ID, then offers multi-vendor models under cloudflare-ai-gateway/. Workers AI collects an API token and account ID only, then offers hosted @cf/ models under cloudflare-workers-ai/.
  • Connecting one does not mark the other connected. Both stay on the existing key-provider / control-plane inference-gateway path, with separate public docs and setup help.

Test Plan

  • Catalog and connectedness tests in @roomote/types (model-provider-config, task-models, inference-gateway)
  • Inference forwarding tests in @roomote/api for chat/embeddings, bearer auth, gateway header vs no gateway header, and rejected account-admin paths
  • Setup docs mapping test for both provider ids
  • Targeted suites re-run twice with consistent pass
  • Confirm Setup/Settings show both providers and switch help when each is selected

Treat them as independent inference connections with distinct credentials, model prefixes, and docs so one Cloudflare token cannot satisfy both.
@roomote-community

roomote-community Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

1 issue outstanding. See task

  • Direct task execution now applies the Cloudflare provider configuration before gateway rebasing, so namespaced credentials work in self-hosted/direct tasks. (apps/worker/src/run-task/agent-home.ts:1793)
  • Custom OPENCODE_CONFIG_CONTENT skips Cloudflare provider registration, so control-plane helpers use the wrong credential names. (packages/cloud-agents/src/server/opencode-runtime.ts:13)

Reviewed 549d4fe

Comment thread packages/types/src/model-provider-config.ts
OpenCode would otherwise load models.dev's ai-gateway-provider and skip Roomote's /v1/chat/completions path. Token help now requires Workers AI, which the /ai/v1 REST surface actually checks.
Helper inference now uses namespaced tokens, account ids, and gateway ids instead of models.dev CLOUDFLARE_ACCOUNT_ID. Also rewrite workers-ai/@cf slugs for /ai/v1 and accept underscore gateway ids.
Direct tasks skipped the Roomote Cloudflare provider merge, so self-hosted runs used models.dev env names. Keep tokens on the control plane in SELF_HOSTING and allow Workers AI /v1/responses.
The setup command already loads non-secret Cloudflare account and gateway ids. The web test still expected the pre-Cloudflare field list and failed CI.
Gateway-mode tasks and control-plane prompts still sent models.dev workers-ai/@cf slugs. Register the rewritten @cf id even when the token is withheld, and rewrite before structured OpenCode SDK calls.
@pridemusvaire

Copy link
Copy Markdown
Contributor Author

Reviewed every thread on this PR.

Roomote's original finding (direct-mode OpenCode never bound namespaced Cloudflare env vars) is fixed in 557dfb0. The later Roomote pass on b023ab2 reported no remaining code issues.

Two extra gaps found while re-checking that review:

  • Gateway-mode OpenCode did not register the rewritten @cf model once the token was withheld.
  • Control-plane structured prompts still sent models.dev workers-ai/@cf slugs.

Both are fixed in 4a644b0. CI test list for non-secret Cloudflare identity fields is in b023ab2.

@pridemusvaire
pridemusvaire marked this pull request as draft August 13, 2026 02:36
@pridemusvaire

Copy link
Copy Markdown
Contributor Author

@roomote please review again

@roomote-community

Copy link
Copy Markdown
Contributor

I started a PR review task for this request. See task

@pridemusvaire
pridemusvaire marked this pull request as ready for review August 13, 2026 03:09
…ference-providers

# Conflicts:
#	apps/worker/src/run-task/agent-home.ts
#	packages/cloud-agents/src/server/__tests__/non-task-provider-usage.test.ts
#	packages/cloud-agents/src/server/non-task-provider-usage.ts
#	packages/cloud-agents/src/server/opencode-runtime.ts
mergeAmazonBedrockProviderConfig,
mergeBedrockMantleOpenAiProviderConfig,
mergeBedrockMantleProviderConfig,
mergeCloudflareOpenCodeProviderConfig,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPENCODE_CONFIG_CONTENT bypasses buildModelBackedOpenCodeConfigContent, but its else branch only adds the Bedrock registrations. Therefore helper inference with a custom config and R_MODEL=cloudflare-ai-gateway/... or cloudflare-workers-ai/... never calls mergeCloudflareOpenCodeProviderConfig, so it falls back to models.dev's shared Cloudflare env names instead of Roomote's namespaced credentials. Merge the Cloudflare provider registration into the custom-config path too.

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