Skip to content

fix(provider): honor AI Gateway control options on the Cloudflare REST route - #45319

Open
aniruddhaadak80 wants to merge 1 commit into
anomalyco:devfrom
aniruddhaadak80:cf-gateway-rest-options
Open

fix(provider): honor AI Gateway control options on the Cloudflare REST route#45319
aniruddhaadak80 wants to merge 1 commit into
anomalyco:devfrom
aniruddhaadak80:cf-gateway-rest-options

Conversation

@aniruddhaadak80

Copy link
Copy Markdown

Issue for this PR

Fixes #45295

Type of change

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

What does this PR do?

When OpenCode is routed through Cloudflare's AI Gateway using the REST (/workers/ai/v1/...) route, AI Gateway control options (cacheTtl, cacheKey, metadata, etc.) configured via provider.cloudflare.options were dropped. The OpenAI-compatible chat route applied them, but the REST branch constructed its request without forwarding the gateway control headers, so caching/metadata policies were silently ignored on that path. This adds an aiGatewayRestHeaders helper (mirroring the existing OpenAI-compatible aiGateway helper) and wires it into the REST branch so the same options are honored on both routes.

How did you verify your code works?

  • bun test --timeout 30000 test/provider/cf-ai-gateway-rest-options.test.ts → 3/3 pass
  • bun typecheck (packages/opencode) → clean
  • oxlint on changed files → 0 errors

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

…T route

The anomalyco#44828 routing change sends third-party models (google, xai, deepseek,
...) through Cloudflare's catalog REST API with a bare OpenAI-compatible
client carrying only cf-aig-gateway-id. The aigateway wrapper's options bag
- user-configured cacheTtl, cacheKey, skipCache, collectLog, and
cf-aig-metadata - is only attached to the openai/, anthropic/, and
workers-ai/ routes, so those controls silently stopped applying to every
other provider after the switch.

The REST API accepts the same per-request controls as gateway headers:
cf-aig-cache-ttl, cf-aig-cache-key, cf-aig-skip-cache, cf-aig-collect-log,
and cf-aig-metadata. The new aiGatewayRestHeaders helper maps the existing
opts onto those headers for the REST branch, so caching/metadata/log
settings behave identically across all four route families.

Adds unit coverage for the header mapping, including that explicitly false
booleans serialize (skipCache: false re-enables caching) while unset
options produce no header.
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.

Cloudflare REST route ignores AI Gateway control options

1 participant