Skip to content

Conversation

@kylecarbs
Copy link
Member

Add support for routing AI requests through Cloudflare AI Gateway for caching, analytics, rate limiting, and cost control.

Implementation

  • Added cloudflareGateway config to ProviderConfig type with accountId and gatewayName fields
  • Updated aiService.ts to construct gateway URL when configured
  • Updated workspaceTitleGenerator.ts to use gateway baseURL
  • Gateway URL construction: https://gateway.ai.cloudflare.com/v1/{accountId}/{gatewayName}/{provider}
  • cloudflareGateway takes precedence over baseUrl when both present
  • Added helper function buildCloudflareGatewayURL() for URL construction
  • Updated providers.jsonc example comments with gateway configuration

Documentation

  • Created comprehensive docs/cloudflare-ai-gateway.md with setup, configuration, troubleshooting, and benefits
  • Added to docs/SUMMARY.md under Advanced section

Configuration Example

{
  "anthropic": {
    "apiKey": "sk-ant-...",
    "cloudflareGateway": {
      "accountId": "your-account-id",
      "gatewayName": "your-gateway-name"
    }
  }
}

All providers (Anthropic, OpenAI, Google, etc.) are supported. Gateway is optional - omit config for direct connections.

Benefits

  • Cost optimization: Caching reduces API calls, rate limiting prevents bill spikes
  • Observability: Detailed logs and analytics in Cloudflare dashboard
  • Performance: Global edge network and intelligent caching

Generated with mux

Add support for routing AI requests through Cloudflare AI Gateway
for caching, analytics, rate limiting, and cost control.

Implementation:
- Added cloudflareGateway config to ProviderConfig type with
  accountId and gatewayName fields
- Updated aiService.ts to construct gateway URL when configured
- Updated workspaceTitleGenerator.ts to use gateway baseURL
- Gateway URL construction: https://gateway.ai.cloudflare.com/v1/{accountId}/{gatewayName}/{provider}
- cloudflareGateway takes precedence over baseUrl when both present
- Added helper function buildCloudflareGatewayURL() for URL construction
- Updated providers.jsonc example comments with gateway configuration

Documentation:
- Created comprehensive docs/cloudflare-ai-gateway.md with setup,
  configuration, troubleshooting, and benefits
- Added to docs/SUMMARY.md under Advanced section

Configuration Example:
{
  "anthropic": {
    "apiKey": "sk-ant-...",
    "cloudflareGateway": {
      "accountId": "your-account-id",
      "gatewayName": "your-gateway-name"
    }
  }
}

All providers (Anthropic, OpenAI, Google, etc.) are supported.
Gateway is optional - omit config for direct connections.

_Generated with `mux`_
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Updated regex to match /responses anywhere in path, not just /v1/responses.
This ensures truncation: auto is applied when routing through Cloudflare
gateway which uses paths like /v1/{account}/{gateway}/openai/responses.

Without this fix, large messages routed through Cloudflare gateway would
fail with 413 errors due to missing automatic truncation.

_Generated with `mux`_
@kylecarbs
Copy link
Member Author

This was just for a demo.

@kylecarbs kylecarbs closed this Nov 19, 2025
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.

1 participant