fix(provider): honor AI Gateway control options on the Cloudflare REST route - #45319
Open
aniruddhaadak80 wants to merge 1 commit into
Open
fix(provider): honor AI Gateway control options on the Cloudflare REST route#45319aniruddhaadak80 wants to merge 1 commit into
aniruddhaadak80 wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Fixes #45295
Type of change
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 viaprovider.cloudflare.optionswere 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 anaiGatewayRestHeadershelper (mirroring the existing OpenAI-compatibleaiGatewayhelper) and wires it into the REST branch so the sameoptionsare 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 passbun typecheck(packages/opencode) → cleanoxlinton changed files → 0 errorsScreenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist