Visitar URL original
support: vertexai · opencode-ai/opencode@3a8f497 · GitHub
Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 3a8f497

Browse files
committed
support: vertexai
fix fix
1 parent 9345830 commit 3a8f497

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ You can configure OpenCode using environment variables:
7171
| `ANTHROPIC_API_KEY` | For Claude models |
7272
| `OPENAI_API_KEY` | For OpenAI models |
7373
| `GEMINI_API_KEY` | For Google Gemini models |
74+
| `VERTEXAI_PROJECT` | For Google Cloud VertexAI (Gemini) |
75+
| `VERTEXAI_LOCATION` | For Google Cloud VertexAI (Gemini) |
7476
| `GROQ_API_KEY` | For Groq models |
7577
| `AWS_ACCESS_KEY_ID` | For AWS Bedrock (Claude) |
7678
| `AWS_SECRET_ACCESS_KEY` | For AWS Bedrock (Claude) |

‎internal/llm/models/vertexai.go‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package models
2+
3+
const (
4+
ProviderVertexAI ModelProvider = "vertexai"
5+
6+
// Models
7+
VertexAIGemini25Flash ModelID = "vertexai.gemini-2.5-flash"
8+
VertexAIGemini25 ModelID = "vertexai.gemini-2.5"
9+
)
10+
11+
var VertexAIGeminiModels = map[ModelID]Model{
12+
VertexAIGemini25Flash: {
13+
ID: VertexAIGemini25Flash,
14+
Name: "VertexAI: Gemini 2.5 Flash",
15+
Provider: ProviderVertexAI,
16+
APIModel: "gemini-2.5-flash-preview-04-17",
17+
CostPer1MIn: GeminiModels[Gemini25Flash].CostPer1MIn,
18+
CostPer1MInCached: GeminiModels[Gemini25Flash].CostPer1MInCached,
19+
CostPer1MOut: GeminiModels[Gemini25Flash].CostPer1MOut,
20+
CostPer1MOutCached: GeminiModels[Gemini25Flash].CostPer1MOutCached,
21+
ContextWindow: GeminiModels[Gemini25Flash].ContextWindow,
22+
DefaultMaxTokens: GeminiModels[Gemini25Flash].DefaultMaxTokens,
23+
SupportsAttachments: true,
24+
},
25+
VertexAIGemini25: {
26+
ID: VertexAIGemini25,
27+
Name: "VertexAI: Gemini 2.5 Pro",
28+
Provider: ProviderVertexAI,
29+
APIModel: "gemini-2.5-pro-preview-03-25",
30+
CostPer1MIn: GeminiModels[Gemini25].CostPer1MIn,
31+
CostPer1MInCached: GeminiModels[Gemini25].CostPer1MInCached,
32+
CostPer1MOut: GeminiModels[Gemini25].CostPer1MOut,
33+
CostPer1MOutCached: GeminiModels[Gemini25].CostPer1MOutCached,
34+
ContextWindow: GeminiModels[Gemini25].ContextWindow,
35+
DefaultMaxTokens: GeminiModels[Gemini25].DefaultMaxTokens,
36+
SupportsAttachments: true,
37+
},
38+
}

‎internal/llm/provider/provider.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ func NewProvider(providerName models.ModelProvider, opts ...ProviderClientOption
102102
options: clientOptions,
103103
client: newGeminiClient(clientOptions),
104104
}, nil
105+
case models.ProviderVertexAI:
106+
return &baseProvider[VertexAIClient]{
107+
options: clientOptions,
108+
client: newVertexAIClient(clientOptions),
109+
}, nil
105110
case models.ProviderBedrock:
106111
return &baseProvider[BedrockClient]{
107112
options: clientOptions,

‎internal/llm/provider/vertexai.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"os"
6+
7+
"github.com/opencode-ai/opencode/internal/logging"
8+
"google.golang.org/genai"
9+
)
10+
11+
type VertexAIClient ProviderClient
12+
13+
func newVertexAIClient(opts providerClientOptions) VertexAIClient {
14+
geminiOpts := geminiOptions{}
15+
for _, o := range opts.geminiOptions {
16+
o(&geminiOpts)
17+
}
18+
19+
client, err := genai.NewClient(context.Background(), &genai.ClientConfig{
20+
Project: os.Getenv("VERTEXAI_PROJECT"),
21+
Location: os.Getenv("VERTEXAI_LOCATION"),
22+
Backend: genai.BackendVertexAI,
23+
})
24+
if err != nil {
25+
logging.Error("Failed to create Gemini client", "error", err)
26+
return nil
27+
}
28+
29+
return &geminiClient{
30+
providerOptions: opts,
31+
options: geminiOpts,
32+
client: client,
33+
}
34+
}

0 commit comments

Comments
 (0)