Skip to content

Commit 8b3d0d0

Browse files
committed
providers: add Cloudflare AI Gateway
1 parent 8e816a9 commit 8b3d0d0

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

packages/opencode/src/provider/provider.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,25 @@ export namespace Provider {
310310
},
311311
}
312312
},
313+
"cloudflare-ai-gateway": async () => {
314+
const accountId = Env.get("CLOUDFLARE_ACCOUNT_ID")
315+
const gateway = Env.get("CLOUDFLARE_GATEWAY_NAME")
316+
const apiKey = Env.get("CLOUDFLARE_API_TOKEN")
317+
318+
if (!accountId || !gateway) return { autoload: false }
319+
320+
return {
321+
autoload: true,
322+
options: {
323+
baseURL: `https://gateway.ai.cloudflare.com/v1/${accountId}/${gateway}/openai`,
324+
apiKey,
325+
headers: {
326+
"HTTP-Referer": "https://opencode.ai/",
327+
"X-Title": "opencode",
328+
},
329+
},
330+
}
331+
},
313332
}
314333

315334
export const Model = z

packages/web/src/content/docs/providers.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,54 @@ Or if you already have an API key, you can select **Manually enter API Key** and
319319

320320
---
321321

322+
### Cloudflare AI Gateway
323+
324+
Cloudflare AI Gateway lets you proxy requests to AI providers through Cloudflare's infrastructure with caching, rate limiting, and analytics.
325+
326+
1. Head over to the [Cloudflare dashboard](https://dash.cloudflare.com/), navigate to **AI** > **AI Gateway**, and create a new gateway.
327+
328+
2. Set your Account ID and Gateway name as environment variables:
329+
330+
```bash
331+
CLOUDFLARE_ACCOUNT_ID=your-account-id CLOUDFLARE_GATEWAY_NAME=your-gateway-name opencode
332+
```
333+
334+
Or add them to your bash profile:
335+
336+
```bash title="~/.bash_profile"
337+
export CLOUDFLARE_ACCOUNT_ID=your-account-id
338+
export CLOUDFLARE_GATEWAY_NAME=your-gateway-name
339+
```
340+
341+
3. If your gateway has authentication enabled, also set your API token:
342+
343+
```bash title="~/.bash_profile"
344+
export CLOUDFLARE_API_TOKEN=your-api-token
345+
```
346+
347+
4. Many Cloudflare AI Gateway models are preloaded by default, run the `/models` command to select the one you want.
348+
349+
```txt
350+
/models
351+
```
352+
353+
You can also add additional models through your opencode config.
354+
355+
```json title="opencode.json" {6}
356+
{
357+
"$schema": "https://opencode.ai/config.json",
358+
"provider": {
359+
"cloudflare-ai-gateway": {
360+
"models": {
361+
"some-other-model": {}
362+
}
363+
}
364+
}
365+
}
366+
```
367+
368+
---
369+
322370
### Cortecs
323371

324372
1. Head over to the [Cortecs console](https://cortecs.ai/), create an account, and generate an API key.

0 commit comments

Comments
 (0)