Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(vertex):gemini pass token to avoid npe
  • Loading branch information
artem-obukhov committed Jun 29, 2025
commit 633d2d619ffc5b06d713f9460ff464d3e196dcc9
9 changes: 9 additions & 0 deletions internal/llm/provider/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"cloud.google.com/go/auth"
"github.com/google/uuid"
"github.com/opencode-ai/opencode/internal/config"
"github.com/opencode-ai/opencode/internal/llm/tools"
Expand All @@ -31,6 +32,14 @@ type geminiClient struct {

type GeminiClient ProviderClient

type tokenProvider struct {
value string
}

func (p *tokenProvider) Token(context.Context) (*auth.Token, error) {
return &auth.Token{Value: p.value}, nil
}

func newGeminiClient(opts providerClientOptions) GeminiClient {
geminiOpts := geminiOptions{}
for _, o := range opts.geminiOptions {
Expand Down
11 changes: 6 additions & 5 deletions internal/llm/provider/vertexai.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ func newVertexAIClient(opts providerClientOptions) VertexAIClient {
if opts.baseURL != "" {
if opts.headers != nil {
header := opts.asHeader()
// HACK: assume litellm proxy, provide an excplicit way to define proxy-type
if h := header.Get("x-litellm-api-key"); h != "" {
// has to be empty to pass genai validation check with empty creds, auth handled by LiteLLM
genaiConfig.Credentials = &auth.Credentials{}
}
genaiConfig.HTTPOptions = genai.HTTPOptions{
BaseURL: opts.baseURL,
Headers: *header,
Expand All @@ -67,6 +62,12 @@ func newVertexAIClient(opts providerClientOptions) VertexAIClient {
}
}

if opts.apiKey != "" {
genaiConfig.Credentials = &auth.Credentials{
TokenProvider: &tokenProvider{value: opts.apiKey},
}
}

client, err := genai.NewClient(context.Background(), genaiConfig)
if err != nil {
logging.Error("Failed to create VertexAI client", "error", err)
Expand Down