fix: read API key from environment in host mode when not using skaband
When running sketch in the default container mode with -skaband-addr=,
the system was failing with 'x-api-key header is required' because the
runInHostMode function wasn't reading the ANTHROPIC_API_KEY environment
variable when skaband wasn't being used.
This change adds the missing logic to read the API key from environment
variables (ANTHROPIC_API_KEY for claude, or GEMINI_API_KEY for gemini)
when skabandAddr is empty, matching the behavior in runInUnsafeMode.
The fix ensures that commands like:
envdir /path/to/env go run ./cmd/sketch -skaband-addr= -prompt 'task'
now work correctly by passing the API key to the Docker container's
dockerfile creation process.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s592f0c893cafc931k
diff --git a/cmd/sketch/main.go b/cmd/sketch/main.go
index 656b7f8..775da54 100644
--- a/cmd/sketch/main.go
+++ b/cmd/sketch/main.go
@@ -284,6 +284,16 @@
if err != nil {
return err
}
+ } else {
+ // When not using skaband, get API key from environment or flag
+ envName := "ANTHROPIC_API_KEY"
+ if flags.modelName == "gemini" {
+ envName = gem.GeminiAPIKeyEnv
+ }
+ apiKey = cmp.Or(os.Getenv(envName), flags.llmAPIKey)
+ if apiKey == "" {
+ return fmt.Errorf("%s environment variable is not set, -llm-api-key flag not provided", envName)
+ }
}
// Get current working directory