Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/opencode/src/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,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,
Expand Down
48 changes: 48 additions & 0 deletions packages/web/src/content/docs/providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading