Skip to content

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

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

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

Conversation

@aniruddhaadak80

@aniruddhaadak80 aniruddhaadak80 commented Aug 26, 2026

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.
@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 26, 2026
@github-actions github-actions Bot closed this Aug 26, 2026
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