{"record":{"id":"f9abd2eab1184704","repo":"charmbracelet/crush","slug":"invalid-api-key-format-for-provider-s","errorCode":null,"errorMessage":"invalid API key format for provider %s","messagePattern":"invalid API key format for provider (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/config.go","lineNumber":961,"sourceCode":"}\n\nfunc (c *ProviderConfig) TestConnection(resolver VariableResolver) error {\n\tvar (\n\t\tproviderID = catwalk.InferenceProvider(c.ID)\n\t\ttestURL    = \"\"\n\t\theaders    = make(map[string]string)\n\t\tapiKey, _  = resolver.ResolveValue(c.APIKey)\n\t)\n\n\tswitch providerID {\n\tcase catwalk.InferenceProviderMiniMax, catwalk.InferenceProviderMiniMaxChina:\n\t\t// NOTE: MiniMax has no good endpoint we can use to validate the API key.\n\t\treturn nil\n\tcase catwalk.InferenceProviderAlibabaSingapore:\n\t\t// NOTE: Alibaba has no good endpoint we can use to validate the API key.\n\t\t// Let's at least check the pattern.\n\t\tif !strings.HasPrefix(apiKey, \"sk-\") {\n\t\t\treturn fmt.Errorf(\"invalid API key format for provider %s\", c.ID)\n\t\t}\n\t\treturn nil\n\t}\n\n\tswitch c.Type {\n\tcase catwalk.TypeOpenAI, catwalk.TypeOpenAICompat, catwalk.TypeOpenRouter:\n\t\tbaseURL, _ := resolver.ResolveValue(c.BaseURL)\n\t\tbaseURL = cmp.Or(baseURL, \"https://api.openai.com/v1\")\n\n\t\tswitch providerID {\n\t\tcase catwalk.InferenceProviderOpenRouter:\n\t\t\ttestURL = baseURL + \"/credits\"\n\t\tcase catwalk.InferenceProviderOpenCodeGo:\n\t\t\ttestURL = strings.Replace(baseURL, \"/go\", \"\", 1) + \"/models\"\n\t\tdefault:\n\t\t\ttestURL = baseURL + \"/models\"\n\t\t}\n","sourceCodeStart":943,"sourceCodeEnd":979,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/config/config.go#L943-L979","documentation":"Returned by the API-key validation routine in internal/config/config.go for the Alibaba (Singapore) inference provider. Alibaba exposes no endpoint to validate keys, so Crush performs an offline pattern check: the key must start with \"sk-\". A key failing this prefix check means it was copied incorrectly or belongs to a different provider.","triggerScenarios":"Calling provider API-key validation (e.g. during config setup or `crush models`/login flows) with InferenceProviderAlibabaSingapore whose apiKey does not begin with \"sk-\".","commonSituations":"Pasting a DashScope key without its \"sk-\" prefix; using an Alibaba international key on the Singapore endpoint or vice versa; accidentally using a key from another provider (OpenAI-style keys differ); trailing whitespace trimming the prefix visually but a different string entirely.","solutions":["Re-copy the API key from the Alibaba DashScope console, ensuring it starts with \"sk-\".","Verify the key belongs to the Alibaba Singapore endpoint you configured.","Strip surrounding quotes/whitespace when pasting the key into crushrc or the prompt.","If you believe the key is valid, bypass pattern validation expectations by confirming the provider ID matches the key's region."],"exampleFix":"// before\nc.ID = \"alibaba\"\napiKey = \"a1b2c3d4\" // missing sk- prefix\n// after\napiKey = \"sk-a1b2c3d4eff5...\" // full key copied from DashScope console","handlingStrategy":"validation","validationCode":"if provider == \"alibaba\" && !strings.HasPrefix(apiKey, \"sk-\") {\n    return errors.New(\"alibaba API keys must start with sk-; re-copy from DashScope console\")\n}","typeGuard":"func isValidAlibabaKey(key string) bool {\n    return strings.HasPrefix(strings.TrimSpace(key), \"sk-\")\n}","tryCatchPattern":"if err := cfg.ValidateAPIKeys(ctx); err != nil {\n    if strings.Contains(err.Error(), \"invalid API key format\") {\n        promptUserToReenterKey()\n        return nil // retry after correction\n    }\n    return err\n}","preventionTips":["Copy keys directly from the provider console, never retyped.","Trim whitespace/quotes before storing keys.","Keep keys per-provider and per-region to avoid cross-provider paste mistakes."],"tags":["config","api-key","alibaba","validation"],"backgroundTag":"invalid-api-key-format","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}