Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit 86d0d1f

Browse files
[feature/openrouter-provider] Add OpenRouter provider support and integrate new models
- Updated README.md to include OpenRouter as a supported provider and its configuration details. - Added `OPENROUTER_API_KEY` to environment variable configuration. - Introduced OpenRouter-specific models in `internal/llm/models/openrouter.go` with mappings to existing cost and token configurations. - Updated `internal/config/config.go` to set default models for OpenRouter agents. - Extended `opencode-schema.json` to include OpenRouter models in the schema definitions. - Refactored model IDs and names to align with OpenRouter naming conventions.
1 parent 3925818 commit 86d0d1f

File tree

4 files changed

+216
-159
lines changed

4 files changed

+216
-159
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ OpenCode is a Go-based CLI application that brings AI assistance to your termina
1111
## Features
1212

1313
- **Interactive TUI**: Built with [Bubble Tea](https://github.com/charmbracelet/bubbletea) for a smooth terminal experience
14-
- **Multiple AI Providers**: Support for OpenAI, Anthropic Claude, Google Gemini, AWS Bedrock, and Groq
14+
- **Multiple AI Providers**: Support for OpenAI, Anthropic Claude, Google Gemini, AWS Bedrock, Groq, and OpenRouter
1515
- **Session Management**: Save and manage multiple conversation sessions
1616
- **Tool Integration**: AI can execute commands, search files, and modify code
1717
- **Vim-like Editor**: Integrated editor with text input capabilities
@@ -75,6 +75,7 @@ You can configure OpenCode using environment variables:
7575
| `AWS_ACCESS_KEY_ID` | For AWS Bedrock (Claude) |
7676
| `AWS_SECRET_ACCESS_KEY` | For AWS Bedrock (Claude) |
7777
| `AWS_REGION` | For AWS Bedrock (Claude) |
78+
| `OPENROUTER_API_KEY` | For OpenRouter |
7879

7980
### Configuration File Structure
8081

@@ -93,8 +94,12 @@ You can configure OpenCode using environment variables:
9394
"disabled": false
9495
},
9596
"groq": {
96-
"apiKey": "your-api-key",
97-
"disabled": false
97+
"apiKey": "your-api-key",
98+
"disabled": false
99+
},
100+
"openrouter": {
101+
"apiKey": "your-api-key",
102+
"disabled": false
98103
}
99104
},
100105
"agents": {
@@ -164,12 +169,18 @@ OpenCode supports a variety of AI models from different providers:
164169

165170
### Groq
166171

167-
- Llama 4 Maverick (17b-128e-instruct)
172+
- Llama 4 Maverick (17b-128e-instruct)
168173
- Llama 4 Scout (17b-16e-instruct)
169174
- QWEN QWQ-32b
170175
- Deepseek R1 distill Llama 70b
171176
- Llama 3.3 70b Versatile
172177

178+
### OpenRouter
179+
180+
- Deepseek (Chat, R1)
181+
- Gemini (2.5 Pro, 2.5 Flash)
182+
- OpenAI
183+
173184
## Usage
174185

175186
```bash

internal/config/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ func setProviderDefaults() {
268268
// OpenRouter configuration
269269
if apiKey := os.Getenv("OPENROUTER_API_KEY"); apiKey != "" {
270270
viper.SetDefault("providers.openrouter.apiKey", apiKey)
271-
viper.SetDefault("agents.coder.model", models.GPT41)
272-
viper.SetDefault("agents.task.model", models.GPT41Mini)
273-
viper.SetDefault("agents.title.model", models.GPT41Mini)
271+
viper.SetDefault("agents.coder.model", models.OpenRouterGPT41)
272+
viper.SetDefault("agents.task.model", models.OpenRouterGPT41Mini)
273+
viper.SetDefault("agents.title.model", models.OpenRouterGPT41Mini)
274274
return
275275
}
276276

@@ -575,12 +575,12 @@ func setDefaultModelForAgent(agent AgentName) bool {
575575

576576
switch agent {
577577
case AgentTitle:
578-
model = models.GPT41Mini
578+
model = models.OpenRouterGPT41Mini
579579
maxTokens = 80
580580
case AgentTask:
581-
model = models.GPT41Mini
581+
model = models.OpenRouterGPT41Mini
582582
default:
583-
model = models.GPT41
583+
model = models.OpenRouterGPT41
584584
}
585585

586586
// Check if model supports reasoning

0 commit comments

Comments
 (0)