cmd/sketch: look up openai keys via envvars in resolveModel
We ignored their existence, thereby treating them an Anthropic.
diff --git a/cmd/sketch/main.go b/cmd/sketch/main.go
index a85594b..4d2423b 100644
--- a/cmd/sketch/main.go
+++ b/cmd/sketch/main.go
@@ -582,9 +582,9 @@
if flags.skabandAddr == "" {
// When not using skaband, get API key from environment or flag
- envName := ant.APIKeyEnv
- if flags.modelName == "gemini" {
- envName = gem.GeminiAPIKeyEnv
+ envName := envNameForModel(flags.modelName)
+ if envName == "" {
+ return modelSpec{}, "", fmt.Errorf("unknown model '%s', use -list-models to see available models", flags.modelName)
}
apiKey = cmp.Or(os.Getenv(envName), flags.llmAPIKey)
if apiKey == "" {
@@ -899,7 +899,7 @@
func selectLLMService(client *http.Client, flags CLIFlags, modelURL, apiKey string) (llm.Service, error) {
if ant.IsClaudeModel(flags.modelName) {
if apiKey == "" {
- return nil, fmt.Errorf("missing ANTHROPIC_API_KEY")
+ return nil, fmt.Errorf("no anthropic api key provided, set %s", ant.APIKeyEnv)
}
return &ant.Service{
HTTPC: client,
@@ -912,7 +912,7 @@
if flags.modelName == "gemini" {
if apiKey == "" {
- return nil, fmt.Errorf("missing %s", gem.GeminiAPIKeyEnv)
+ return nil, fmt.Errorf("no gemini api key provided, set %s", gem.GeminiAPIKeyEnv)
}
return &gem.Service{
HTTPC: client,
@@ -929,8 +929,8 @@
}
// Verify we have an API key, if necessary.
- apiKey = os.Getenv(model.APIKeyEnv)
- if model.APIKeyEnv != "" && apiKey == "" {
+ apiKey = cmp.Or(os.Getenv(model.APIKeyEnv), flags.llmAPIKey)
+ if apiKey == "" {
return nil, fmt.Errorf("missing API key for %s model, set %s environment variable", model.UserName, model.APIKeyEnv)
}
@@ -942,6 +942,21 @@
}, nil
}
+func envNameForModel(modelName string) string {
+ switch {
+ case ant.IsClaudeModel(modelName):
+ return ant.APIKeyEnv
+ case modelName == "gemini":
+ return gem.GeminiAPIKeyEnv
+ default:
+ model := oai.ModelByUserName(modelName)
+ if model.IsZero() {
+ return ""
+ }
+ return model.APIKeyEnv
+ }
+}
+
// dumpDistFilesystem dumps the embedded /dist/ filesystem to the specified directory
func dumpDistFilesystem(outputDir string) error {
// Build the embedded filesystem