Skip to content

fix(cli): recognize all providers in install and improve missing key error#1716

Merged
EItanya merged 1 commit into
kagent-dev:mainfrom
mesutoezdil:fix/install-provider-api-key-check
Apr 30, 2026
Merged

fix(cli): recognize all providers in install and improve missing key error#1716
EItanya merged 1 commit into
kagent-dev:mainfrom
mesutoezdil:fix/install-provider-api-key-check

Conversation

@mesutoezdil
Copy link
Copy Markdown
Contributor

Closes #1622.

GetModelProvider was missing Gemini, GeminiVertexAI, AnthropicVertexAI and Bedrock from its switch. Any of those values in KAGENT_DEFAULT_MODEL_PROVIDER fell through to the default and came back as OpenAI, which then required OPENAI_API_KEY even though the user had no intention of using OpenAI.

GetProviderAPIKey now also covers Gemini (GOOGLE_API_KEY). Providers that rely on cloud credentials rather than an API key (Ollama, Bedrock, VertexAI variants) already returned empty string and are left as is.

The error message now mentions KAGENT_DEFAULT_MODEL_PROVIDER so users know they can switch providers instead of being stuck.

Copilot AI review requested due to automatic review settings April 20, 2026 15:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes kagent install incorrectly defaulting unknown KAGENT_DEFAULT_MODEL_PROVIDER values to OpenAI (and therefore requiring OPENAI_API_KEY), by expanding provider recognition and improving the missing-key guidance.

Changes:

  • Extend GetModelProvider to recognize Gemini, GeminiVertexAI, AnthropicVertexAI, and Bedrock provider values.
  • Update GetProviderAPIKey to require GOOGLE_API_KEY for the Gemini provider.
  • Improve install-time error output to mention KAGENT_DEFAULT_MODEL_PROVIDER as an alternative path when an API key is missing.

Reviewed changes

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

File Description
go/core/cli/internal/cli/agent/install.go Adds an extra hint in the “missing API key” error output pointing users to KAGENT_DEFAULT_MODEL_PROVIDER.
go/core/cli/internal/cli/agent/const.go Expands provider parsing to include additional providers and adds Gemini API key env-var mapping.

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

Comment thread go/core/cli/internal/cli/agent/const.go
Comment on lines 56 to 66
@@ -51,7 +61,11 @@ func GetProviderAPIKey(provider v1alpha2.ModelProvider) string {
return env.AnthropicAPIKey.Name()
case v1alpha2.ModelProviderAzureOpenAI:
return env.AzureOpenAIAPIKey.Name()
case v1alpha2.ModelProviderGemini:
return env.GoogleAPIKey.Name()
default:
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

GetProviderAPIKey only matches exact enum values (e.g., ModelProviderAnthropic == "Anthropic"). Elsewhere the CLI commonly uses helm-key/lowercase provider strings (e.g., modelProvider: anthropic in manifests/tests), and ValidateAPIKey passes that string through as v1alpha2.ModelProvider(modelProvider), which will currently fall into the default branch and skip required API-key validation. Consider normalizing the input inside GetProviderAPIKey (e.g., accept both enum values and GetModelProviderHelmValuesKey(...) strings, or downcase/translate before switching) so it works with both representations.

Copilot uses AI. Check for mistakes.
@mesutoezdil mesutoezdil force-pushed the fix/install-provider-api-key-check branch 2 times, most recently from 60f4293 to cd3e54b Compare April 23, 2026 10:05
Copy link
Copy Markdown
Contributor

@jmhbh jmhbh left a comment

Choose a reason for hiding this comment

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

LGTM, but the copilot feedback above regarding support for GEMINI_API_KEY makes sense to me and should be addressed

@mesutoezdil mesutoezdil force-pushed the fix/install-provider-api-key-check branch from b002528 to c0782e3 Compare April 23, 2026 22:18
…error

GetModelProvider was missing Gemini, GeminiVertexAI, AnthropicVertexAI
and Bedrock from its switch statement so any of those values in
KAGENT_DEFAULT_MODEL_PROVIDER fell through to the default and came back
as OpenAI, which then required OPENAI_API_KEY to be set.

GetProviderAPIKey now covers Gemini with the same fallback logic used
in the runtime (go/adk/pkg/agent/agent.go): prefer GOOGLE_API_KEY, fall
back to GEMINI_API_KEY if the former is not set.

The error message now tells the user about KAGENT_DEFAULT_MODEL_PROVIDER
so they know how to switch to a different provider.

Closes kagent-dev#1622

Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
@mesutoezdil mesutoezdil force-pushed the fix/install-provider-api-key-check branch from c0782e3 to 8effec5 Compare April 23, 2026 22:18
@mesutoezdil
Copy link
Copy Markdown
Contributor Author

mesutoezdil commented Apr 23, 2026

Good point. @jmhbh Updated GetProviderAPIKey for Gemini to mirror the exact fallback logic in the runtime (go/adk/pkg/agent/agent.go): prefer GOOGLE_API_KEY, fall back to GEMINI_API_KEY if the former is not set. Branch also rebased onto current main.

@EItanya EItanya merged commit 6da271a into kagent-dev:main Apr 30, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] kagent install hard-requires OPENAI_API_KEY even when not using OpenAI

4 participants