diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index b11ca9368..50f92c30f 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -338,6 +338,25 @@ export namespace Provider { }, } }, + "cloudflare-ai-gateway": async () => { + const accountId = Env.get("CLOUDFLARE_ACCOUNT_ID") + const gateway = Env.get("CLOUDFLARE_GATEWAY_ID") + const apiKey = Env.get("CLOUDFLARE_API_TOKEN") + + if (!accountId || !gateway) return { autoload: false } + + return { + autoload: true, + options: { + baseURL: `https://gateway.ai.cloudflare.com/v1/${accountId}/${gateway}/compat`, + apiKey, + headers: { + "HTTP-Referer": "https://opencode.ai/", + "X-Title": "opencode", + } + } + } + }, cerebras: async () => { return { autoload: false, diff --git a/packages/web/src/content/docs/providers.mdx b/packages/web/src/content/docs/providers.mdx index 5f9b040d4..4c36d561f 100644 --- a/packages/web/src/content/docs/providers.mdx +++ b/packages/web/src/content/docs/providers.mdx @@ -323,6 +323,54 @@ If you encounter "I'm sorry, but I cannot assist with that request" errors, try --- +### Cloudflare AI Gateway + +Cloudflare AI Gateway lets you proxy requests to AI providers through Cloudflare's infrastructure with caching, rate limiting, and analytics. + +1. Head over to the [Cloudflare dashboard](https://dash.cloudflare.com/), navigate to **AI** > **AI Gateway**, and create a new gateway. + +2. Set your Account ID and Gateway ID as environment variables: + + ```bash + export CLOUDFLARE_ACCOUNT_ID=your-32-character-account-id && export CLOUDFLARE_GATEWAY_ID=your-gateway-id + ``` + + Or add them to your bash profile: + + ```bash title="~/.bash_profile" + export CLOUDFLARE_ACCOUNT_ID=your-32-character-account-id + export CLOUDFLARE_GATEWAY_ID=your-gateway-id + ``` + +3. If your gateway has authentication enabled, also set your API token: + + ```bash title="~/.bash_profile" + export CLOUDFLARE_API_TOKEN=your-api-token + ``` + +4. Many Cloudflare AI Gateway models are preloaded by default, run the `/models` command to select the one you want. + + ```txt + /models + ``` + + You can also add additional models through your opencode config. + + ```json title="opencode.json" {6} + { + "$schema": "https://opencode.ai/config.json", + "provider": { + "cloudflare-ai-gateway": { + "models": { + "some-other-model": {} + } + } + } + } + ``` + +--- + ### Cortecs 1. Head over to the [Cortecs console](https://cortecs.ai/), create an account, and generate an API key.