Skip to content

fix(config): honor configured api_key for the Vertex AI provider#3111

Open
kypkk wants to merge 2 commits into
charmbracelet:mainfrom
kypkk:fix/vertexai-apikey-ignored
Open

fix(config): honor configured api_key for the Vertex AI provider#3111
kypkk wants to merge 2 commits into
charmbracelet:mainfrom
kypkk:fix/vertexai-apikey-ignored

Conversation

@kypkk

@kypkk kypkk commented Jun 12, 2026

Copy link
Copy Markdown

Fixes #3074

Problem

A Vertex AI provider configured with an api_key (and optionally a custom
base_url pointing at a proxy) was dropped during config load. The
vertexai case in configureProviders only checked the VERTEXAI_PROJECT
/ VERTEXAI_LOCATION env vars and ignored the configured api_key
entirely — so Crush treated the provider as unconfigured and prompted for
an API key, even though the identical config style works for the openai
and anthropic providers.

Fix

Two changes, both on the Crush side (fantasy's google provider already
exposes everything needed — WithGeminiAPIKey, WithBaseURL,
WithVertex — so no upstream change is required):

  1. internal/config/load.go — when VERTEXAI_PROJECT/VERTEXAI_LOCATION
    are absent, resolve the configured api_key like the generic provider
    branch does (including $VAR / $(cmd) templates) and keep the
    provider when it resolves. The provider is only dropped when neither
    native GCP credentials nor an api_key are available.
  2. internal/agent/coordinator.gobuildGoogleVertexProvider now
    receives the resolved api_key and base_url. When project/location
    are present the native WithVertex path is unchanged (and still takes
    precedence); otherwise the provider is built with
    WithGeminiAPIKey(apiKey). A configured base_url is wired through in
    both cases.

Behavior

Config Before After
VERTEXAI_PROJECT + VERTEXAI_LOCATION set Vertex backend (ADC) unchanged
api_key only (no env vars) provider dropped, key prompt kept; Gemini-API auth, base_url honored
neither provider dropped unchanged

Design note

I interpreted "api_key + custom base_url" as a Gemini-API-compatible
endpoint/proxy (WithGeminiAPIKey + WithBaseURL), since that matches
what the reporter's proxy expects and how the other providers behave. If
you'd rather keep the Vertex backend and route through the proxy with
skip-auth, happy to adjust.

Testing

  • New regression test TestConfig_configureProvidersVertexAIWithAPIKey
    (fails on main, passes here): provider with an api_key and no GCP
    env vars is kept, with api_key/base_url intact and no
    project/location extra params.
  • Existing VertexAIWithCredentials / WithoutCredentials /
    MissingProject tests still pass (env-var behavior unchanged).
  • go test ./internal/config ./internal/agent — 336 passed.
  • golangci-lint run clean on the touched packages.

kypkk added 2 commits June 12, 2026 13:41
…api_key

Reproduction for charmbracelet#3074: a vertexai provider configured
with an api_key (and a custom base_url) is dropped by configureProviders
because the vertexai branch only checks VERTEXAI_PROJECT/VERTEXAI_LOCATION
env vars and ignores the api_key. The test documents the current buggy
behavior (provider count == 0); flip the assertion to 1 once fixed.
The vertexai branch in configureProviders only checked the
VERTEXAI_PROJECT/VERTEXAI_LOCATION env vars and dropped the provider
when they were unset, ignoring a configured api_key entirely. Crush
then treated the provider as unconfigured and prompted for an API key,
even though the same api_key config works for openai/anthropic.

Now, when the GCP env vars are absent, the api_key is resolved like any
other provider and keeps the provider alive. buildGoogleVertexProvider
wires the api_key (via WithGeminiAPIKey) and the configured base_url
through to the google provider; the native WithVertex path is unchanged
and still takes precedence when project/location are set.

Fixes charmbracelet#3074
Copilot AI review requested due to automatic review settings June 12, 2026 05:50
@charmcli

charmcli commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for keeping a Vertex AI provider configured via api_key (and optional proxy base_url) even when VERTEXAI_PROJECT / VERTEXAI_LOCATION env vars are absent, plus a regression test for the previously dropped-provider behavior.

Changes:

  • Update Vertex AI provider configuration logic to only require project/location when using native Vertex auth; otherwise allow API-key auth.
  • Add regression test covering API-key + proxy config path for Vertex AI (issue #3074).
  • Extend the coordinator’s Google Vertex provider builder to accept baseURL and apiKey, selecting Vertex vs API-key auth based on provided options.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/config/load_test.go Adds regression test ensuring VertexAI provider isn’t dropped when configured with api_key only.
internal/config/load.go Adjusts credential checks so VertexAI provider is retained when API key is present even without project/location env vars.
internal/agent/coordinator.go Updates Vertex provider construction to allow API-key + baseURL proxy mode when project/location are missing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +577 to +582
cfg := &Config{}
cfg.setDefaults("/tmp", "")
// No VERTEXAI_PROJECT / VERTEXAI_LOCATION on purpose: the user is
// authenticating via api_key + proxy, not native GCP credentials.
env := env.NewFromMap(map[string]string{})
resolver := NewShellVariableResolver(env)
Comment thread internal/config/load.go
Comment on lines +290 to 296
} else if v, err := resolver.ResolveValue(p.APIKey); v == "" || err != nil {
// Without native GCP credentials an API key works like any
// other provider (e.g. against a Gemini-API-compatible
// proxy); only drop the provider when neither is available.
if configExists {
slog.Warn("Skipping Vertex AI provider due to missing credentials")
c.Providers.Del(string(p.ID))
Comment on lines +964 to +973
if project != "" && location != "" {
opts = append(opts, google.WithVertex(project, location))
} else {
// Without native GCP credentials, authenticate with the configured
// API key (e.g. against a Gemini-API-compatible proxy).
opts = append(opts, google.WithGeminiAPIKey(apiKey))
}
if baseURL != "" {
opts = append(opts, google.WithBaseURL(baseURL))
}
@kypkk

kypkk commented Jun 12, 2026

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crush asking for Vertex key despite config

3 participants