feat: cfGateway config for per-provider AI Gateway passthrough#99
Merged
Conversation
…rough (closes #97) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
stackbilt-admin
commented
Jun 22, 2026
stackbilt-admin
left a comment
Member
Author
There was a problem hiding this comment.
Review: cfGateway per-provider AI Gateway passthrough — APPROVED
Reviewed against the locked contract; all constraints hold. Diff is CRLF-inflated (749/+320) but the semantic change is ~120 lines, fully additive.
Verified
- URL derivation — base
https://gateway.ai.cloudflare.com/v1/{accountId}/{gatewayId}/correct; all 5 suffixes match: openai→openai/v1, anthropic→anthropic, cerebras→cerebras/v1, groq→groq/openai/v1, nvidia→nvidia-nim/v1(base.ts:69, per-provider constructors). Anthropic correctly versionless, with/v1/messagesappended at the endpoint. - Precedence — explicit
baseUrlreturns early withcfGatewayActive=false(base.ts:63); since the constructor stores only the explicitconfig.baseUrl, the derived URL never leaks intogetAIGatewayHeaders(which readsthis.config.baseUrl), so the two header paths don't double-fire. Tested (cf-gateway.test.ts:127). - Header wire types —
cf-aig-skip-cacheserialized viaString(boolean)→ "true"/"false" (base.ts:408);cf-aig-cache-ttlnumeric string viaString(number)(base.ts:402). Each header gated ontypeofof its source field, so undefined fields are omitted. Tested. - Constructor throw — empty accountId/gatewayId throws
CfGatewayInvalidConfigErrorsynchronously inresolveCfGatewaybefore URL derivation (base.ts:54-61). Tested for both fields and both throw-styles. - Error shape —
code: 'CF_GATEWAY_INVALID_CONFIG',field: 'accountId'|'gatewayId',providerall present (errors.ts:100). Tested. - Workers AI isolation —
src/providers/cloudflare.tsuntouched (confirmed via git diff);CloudflareConfigkeeps itsaibinding +gatewayoptions, nocfGateway. - skipCache field —
GatewayMetadata.skipCache?: boolean(types.ts:31), serialized to string on the wire. - Test coverage — 13 new tests cover URL derivation (all 5), constructor validation (both fields), header injection/omission, skipCache true|false, baseUrl override, and gateway-inactive. Full suite 487 passing locally.
- Public API —
CfGatewayConfigandCfGatewayInvalidConfigErrorexported from index.ts; both exercised in tests. - README + CHANGELOG — both updated per OSS policy; README wire-value table matches implementation.
Clean, contract-faithful, additive-only. LGTM (non-blocking comment review).
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.
Closes #97
Implemented via constellation-loop.
What
cfGateway?: { accountId, gatewayId }to 5 HTTP provider configs (OpenAI, Anthropic, Cerebras, Groq, NVIDIA)baseUrlautomatically per-provider when set (suffixes:openai/v1,anthropic,cerebras/v1,groq/openai/v1,nvidia-nim/v1)cf-aig-cache-ttl/cf-aig-cache-key/cf-aig-skip-cacheheaders fromrequest.gatewayMetadatawhen the gateway is active (each only if its field is defined)baseUrloverride disables gateway-active mode entirely (no header injection)CfGatewayInvalidConfigError(CF_GATEWAY_INVALID_CONFIG) synchronously in constructor on empty accountId/gatewayIdGatewayMetadata.skipCachefield; exportedCfGatewayConfigtypeTests
Note for reviewer
Several edited files (errors.ts, index.ts, types.ts, base.ts) had pre-existing mixed CRLF/LF line endings; the editor normalized them to the file's dominant CRLF, which inflates the line-change count. The semantic diff is small — verify with
git diff -wor by stripping CR.