Skip to content

fix(provider): route non-native Cloudflare AI Gateway providers via the REST API - #44828

Merged
rekram1-node merged 2 commits into
anomalyco:devfrom
superhighfives:gateway-rest-routing
Aug 25, 2026
Merged

fix(provider): route non-native Cloudflare AI Gateway providers via the REST API#44828
rekram1-node merged 2 commits into
anomalyco:devfrom
superhighfives:gateway-rest-routing

Conversation

@superhighfives

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes#44827

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Non-OpenAI/Anthropic models on the cloudflare-ai-gateway provider all failed with Bad Request: Invalid provider — Google, xAI, Alibaba, DeepSeek, Moonshot, every model.

The loader routes anything that isn't openai/, anthropic/, or workers-ai/ through ai-gateway-provider's unified (compat) route. That posts to the gateway's universal compat endpoint, which only fronts a handful of upstreams — the rest come back "Invalid provider".

This routes those providers through Cloudflare's catalog-aware REST API (/accounts/{id}/ai/v1/chat/completions) instead, and binds the request to the configured gateway with the cf-aig-gateway-id header so it stays gateway-routed (analytics/caching/BYOK), not a bypass. OpenAI/Anthropic native passthrough and Workers AI are untouched. models.dev ids pass through unchanged.

Pairs with the models.dev catalog rework that lists these providers: anomalyco/models.dev#4922.

How did you verify your code works?

Built the branch and ran every affected model through it against a live Cloudflare gateway (opencode run --model cloudflare-ai-gateway/<provider>/<model>), base call plus each reasoning-effort variant — all 5 providers route and return content (Alibaba, DeepSeek, Moonshot, xAI fully green; Google works but Cloudflare intermittently returns "Failed to parse model output" on its gemini flash models regardless of routing — a non-deterministic upstream flake, not this change). Confirmed the requests appear in the gateway dashboard (so they're gateway-routed, not bypassing it).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…he REST API
The cloudflare-ai-gateway loader sent every non-OpenAI/Anthropic provider through
ai-gateway-provider's unified (compat) route, which posts to the gateway's universal
compat endpoint. That endpoint only fronts a handful of upstreams, so Google, xAI,
Alibaba, DeepSeek, Moonshot, etc. all failed with 'Bad Request: Invalid provider'.
Route those providers through Cloudflare's catalog-aware REST API instead
(/accounts/{id}/ai/v1/chat/completions), binding the request to the gateway with the
cf-aig-gateway-id header so it stays gateway-routed (analytics, caching, BYOK) rather
than bypassing it. models.dev ids (provider/model, dotted) pass through unchanged.
OpenAI/Anthropic native passthrough and Workers AI are unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rekram1-node
rekram1-node merged commit 3ef72fe into anomalyco:devAug 25, 2026
8 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudflare-ai-gateway: non-OpenAI/Anthropic providers fail with 'Invalid provider'

2 participants

@superhighfives@rekram1-node