feat(ai-gateway): add generic provider proxy for 11 OpenAI-compatible providers#8
Open
theredspoon wants to merge 10 commits intosimple10:mainfrom
Open
feat(ai-gateway): add generic provider proxy for 11 OpenAI-compatible providers#8theredspoon wants to merge 10 commits intosimple10:mainfrom
theredspoon wants to merge 10 commits intosimple10:mainfrom
Conversation
cf-connecting-ip, cf-ipcountry, cf-ray, cf-visitor were forwarded to upstream in direct mode. Also prevents sending a request body on GET /v1/models requests.
… providers
Generalize the AI Gateway Worker from 3 hardcoded providers to support
11 additional OpenAI-compatible providers (DeepSeek, Groq, Mistral,
Together, xAI, OpenRouter, Perplexity, Cohere, Fireworks, MiniMax,
Moonshot) via /proxy/{provider}/v1/... routes.
- routing: GENERIC_PROVIDERS whitelist, GENERIC_ENDPOINTS whitelist,
matchGenericRoute() parser
- config: PROVIDER_DEFAULTS with verified base URLs,
getGenericProviderConfig() lookup
- keys: getGenericApiKey() reads from creds.providers[provider].apiKey
- providers/generic: OpenAI-compatible passthrough proxy
- index: generic route handling with auth, key lookup, llemtry telemetry
- admin: mergeCredentials/maskCredentials extended for providers field
- config-ui: collapsible Additional Providers section with 11 API key
fields, 3-segment data-field path support in buildUpdate()
- llemtry: widen ReportOptions.provider to string for generic names
- types: LegacyProvider alias, GenericRouteMatch, providers on
UserCredentials
… generic provider - generic.ts: preserve all request headers (matching openai.ts pattern), only rewrite Authorization; support ProviderConfig with egress proxy URL wrapping and CF header stripping - config.ts: getGenericProviderConfig returns full ProviderConfig with egressProxyUrl and proxy auth headers when configured - index.ts: pass ProviderConfig to proxyGeneric; fix error code for missing API key from 500 to 401 (consistency with generic route)
…ndant log - config.ts: getGenericProviderConfig no longer inherits EGRESS_PROXY_URL; the egress sidecar is a chatgpt.com WAF workaround scoped to openai-codex and should not add an extra hop for generic providers - index.ts: remove redundant console.error on missing API key (already logged by getProviderApiKey via log.warn)
…ove dead code
- config.ts: getGenericProviderConfig now returns CF AI Gateway config
when CF_AI_GATEWAY_* env vars are set, matching legacy provider behavior
- index.ts: compute gateway path for generic routes ({provider}/chat/completions
format, stripping v1/ prefix)
- generic.ts: remove dead egress proxy URL wrapping and CF header stripping
(egress proxy is scoped to openai-codex only); keep config.headers
handling for CF AI Gateway auth header
- generic.ts: strip Cloudflare-injected metadata headers (cf-*) before forwarding to upstream providers (defense in depth) - config-ui.ts: convert early return in buildUpdate to if/else for clarity - README.md: document generic provider routes and 14-provider support - AI-GATEWAY-CONFIG.md: add generic provider credential types, route pattern, and verification example
…gle provider list - Remove unused LegacyProvider type and GenericRouteMatch re-export from types.ts - Extract shared loadCredentials() helper in keys.ts, eliminating duplicate KV read/parse boilerplate - Derive GENERIC_PROVIDERS from exported PROVIDER_DEFAULTS so the provider list is defined once
CF Access headers were silently dropped when EGRESS_PROXY_AUTH_TOKEN was unset because the entire headers object was gated on that var. Extract buildCodexHeaders() that builds each header set independently. Also fix buildUpdate() in config-ui: a parse error in the forEach callback only exited that iteration, allowing a partial update to be submitted. Add hasError flag to abort the entire build and null guard in save().
buildCodexHeaders() used a non-null assertion for CF_ACCESS_CLIENT_SECRET when only CF_ACCESS_CLIENT_ID was checked. Now both must be set or neither Access header is emitted.
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.
Summary
/proxy/{provider}/v1/...routesproviders.*, managed via the Config UIBug fixes (added during review)
buildCodexHeaders()now builds proxy auth and CF Access headers independently. Previously CF Access headers were silently dropped whenEGRESS_PROXY_AUTH_TOKENwas unset.CF_ACCESS_CLIENT_IDandCF_ACCESS_CLIENT_SECRETmust be set or neither Access header is emitted. Previously a missing secret produced a broken header value.buildUpdate()now uses ahasErrorflag to abort on Codex OAuth parse failure instead of submitting a partial update.save()guards against the resultingnullreturn.Depends on #7 (
fix/openai-proxy-headers) — that commit is included in this branch. Once #7 merges, rebasing this branch will drop it cleanly.Test plan
POST /proxy/deepseek/v1/chat/completionswith valid key — successPOST /proxy/unknown/v1/chat/completions— 404 (unknown provider)POST /proxy/deepseek/v1/responses— 404 (non-whitelisted endpoint)POST /proxy/groq/v1/chat/completionswithout key — 401PUT /auth/credswith{ "providers": { "deepseek": { "apiKey": "..." } } }— savesGET /auth/creds— shows maskedproviders.*keysPUT /auth/credswith{ "providers": { "deepseek": null } }— deletes/anthropic/v1/messages,/openai/v1/chat/completions) — still workbuildCodexHeaders({})returnsundefinedbuildCodexHeaderswith only CF Access vars (no proxy auth) returns Access headersbuildCodexHeaderswith onlyCF_ACCESS_CLIENT_ID(no secret) returnsundefined