chenhg5/cc-connect · error
no API key or env found
Error message
no API key or env found
What it means
After extracting the API key and any extra env vars from a claude provider's settings_config, convertClaudeProvider verifies at least one usable credential was found. If p.APIKey is empty AND p.Env is empty, the row carries no authentication information at all, so the conversion fails with this error. Importing such a provider would yield a config entry that cannot authenticate.
Source
Thrown at cmd/cc-connect/provider.go:398
p.Model = model
}
// Carry over any extra env vars (e.g. ANTHROPIC_DEFAULT_HAIKU_MODEL)
extra := make(map[string]string)
known := map[string]bool{"ANTHROPIC_AUTH_TOKEN": true, "ANTHROPIC_BASE_URL": true, "ANTHROPIC_MODEL": true}
for k, v := range env {
if !known[k] {
if s, ok := v.(string); ok && s != "" {
extra[k] = s
}
}
}
if len(extra) > 0 {
p.Env = extra
}
if p.APIKey == "" && len(p.Env) == 0 {
return p, fmt.Errorf("no API key or env found")
}
return p, nil
}
func convertCodexProvider(p config.ProviderConfig, sc map[string]any) (config.ProviderConfig, error) {
// API key from auth.OPENAI_API_KEY
if auth, ok := sc["auth"].(map[string]any); ok {
if key, ok := auth["OPENAI_API_KEY"].(string); ok && key != "" {
p.APIKey = key
}
}
// base_url and model from config TOML string
if cfgStr, ok := sc["config"].(string); ok && cfgStr != "" {
p.BaseURL, p.Model = parseCodexConfigTOML(cfgStr)
}
if p.APIKey == "" {View on GitHub (pinned to 4000b2338a)
Solutions
- Set ANTHROPIC_AUTH_TOKEN in the row's env object (or ANTHROPIC_API_KEY if your cc-switch uses it).
- Verify the env object is non-empty and the key name matches exactly what the converter reads.
- Re-enter the API key in the cc-switch UI and re-import.
- Skip rows with no credentials instead of failing the whole import.
Example fix
// before
{"env": {}}
// error: no API key or env found
// after
{"env": {"ANTHROPIC_AUTH_TOKEN": "sk-ant-..."}} Defensive patterns
Strategy: validation
Validate before calling
func hasClaudeCredentials(settingsJSON string) bool {
var sc struct { Env map[string]string `json:"env"` }
if json.Unmarshal([]byte(settingsJSON), &sc) != nil { return false }
return sc.Env["ANTHROPIC_AUTH_TOKEN"] != "" || sc.Env["ANTHROPIC_API_KEY"] != ""
} Type guard
if p.APIKey == "" && len(p.Env) == 0 {
return p, fmt.Errorf("no API key or env found")
} Try / catch
p, err := convertCCSwitchProvider(row)
if err != nil && strings.Contains(err.Error(), "no API key or env found") {
slog.Warn("provider row carries no credentials; skipping", "name", row.Name)
continue
} Prevention
- Fill in ANTHROPIC_AUTH_TOKEN in cc-switch before importing providers.
- Verify the env object contains at least one recognized auth variable.
- Re-enter keys in the cc-switch UI if a sanitized export stripped them.
- Skip credential-less rows so one bad provider does not block the batch.
When it happens
Trigger: settings_config has an `env` object but it contains neither ANTHROPIC_AUTH_TOKEN (empty or absent) nor any other recognized env entries — e.g. {"env":{"OTHER_VAR":"x"}} or {"env":{}}.
Common situations: Placeholder tokens left empty in cc-switch; provider rows where the token was stored under a differently-named env var; redacted/stripped settings after a sanitizing export.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- no env in settings_config
- open cc-switch db: %w
- invalid settings_config JSON: %w
- unsupported app_type %q (only claude and codex are supported
- cc-switch database not found
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/329addb4f021c99c.
Report an issue: GitHub.