{"record":{"id":"bf79dd3fb6ff7724","repo":"gitbutlerapp/gitbutler","slug":"please-provide-a-valid-api-key-for-your-selected-a","errorCode":null,"errorMessage":"Please provide a valid API key for your selected AI service","messagePattern":"Please provide a valid API key for your selected AI service","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/desktop/src/components/settings/AiCredentialCheck.svelte","lineNumber":79,"sourceCode":"\t\ttry {\n\t\t\t// Get current model kind\n\t\t\tmodelKind = await aiService.getModelKind();\n\t\t\tdebugInfo = `Model kind: ${modelKind}`;\n\n\t\t\t// Check if using GitButler API\n\t\t\tisUsingButlerAPI = await aiService.usingGitButlerAPI();\n\t\t\tdebugInfo += `, Using GB API: ${isUsingButlerAPI}`;\n\n\t\t\t// Check if configuration is valid\n\t\t\tconst isConfigValid = await aiService.validateConfiguration();\n\t\t\tdebugInfo += `, Config valid: ${isConfigValid}`;\n\n\t\t\tif (!isConfigValid) {\n\t\t\t\tif (modelKind === ModelKind.OpenAI || modelKind === ModelKind.Anthropic) {\n\t\t\t\t\tif (isUsingButlerAPI && !userService.user) {\n\t\t\t\t\t\tthrow new Error(\"Please sign in to use GitButler's AI API\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\"Please provide a valid API key for your selected AI service\");\n\t\t\t\t\t}\n\t\t\t\t} else if (modelKind === ModelKind.Ollama) {\n\t\t\t\t\t// Get Ollama configuration for more detailed error\n\t\t\t\t\tconst endpoint = await aiService.getOllamaEndpoint();\n\t\t\t\t\tconst model = await aiService.getOllamaModelName();\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Please check Ollama configuration: endpoint=${endpoint}, model=${model}`,\n\t\t\t\t\t);\n\t\t\t\t} else if (modelKind === ModelKind.LMStudio) {\n\t\t\t\t\t// Get LM Studio configuration for more detailed error\n\t\t\t\t\tconst endpoint = await aiService.getLMStudioEndpoint();\n\t\t\t\t\tthrow new Error(`Please check LM Studio configuration: endpoint=${endpoint}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdebugInfo += `, Testing commit message generation`;\n\n\t\t\t// Set a timeout to fail if the streaming doesn't start or complete","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/apps/desktop/src/components/settings/AiCredentialCheck.svelte#L61-L97","documentation":"Thrown by the AI settings credential check when validateConfiguration() is false for a user-supplied OpenAI/Anthropic key configuration (usingGitButlerAPI() false). The stored API key for the selected service is missing, empty, or rejected as malformed before any network test runs.","triggerScenarios":"Selecting OpenAI or Anthropic in AI settings and running the check with no key saved, a whitespace-only key, or a key string that fails the provider's format validation.","commonSituations":"Key was pasted with trailing newline/quotes; key field cleared by a settings reset; switched provider (OpenAI→Anthropic) without entering the new provider's key; key revoked/deleted on the provider side and validation now fails.","solutions":["Re-enter the API key in Settings, paste without surrounding quotes or whitespace, and save before testing.","Confirm the key is active on the provider dashboard (OpenAI/Anthropic) and has not been revoked.","Verify the key with a direct provider call, e.g. curl https://api.openai.com/v1/models -H \"Authorization: Bearer $KEY\"."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const key = await aiService.getApiKey(modelKind);\nif (!key || key.trim().length < 20) {\n  error = \"Enter the API key for your selected AI service first\";\n  return;\n}\n// run the credential check","typeGuard":"function looksLikeProviderKey(kind: ModelKind, key: string | undefined): boolean {\n  if (!key) return false;\n  if (kind === ModelKind.Anthropic) return key.startsWith(\"sk-ant-\");\n  if (kind === ModelKind.OpenAI) return key.startsWith(\"sk-\");\n  return key.trim().length > 0;\n}","tryCatchPattern":"try {\n  await runCheck();\n} catch (e) {\n  error = e instanceof Error ? e.message : \"Unknown error occurred\";\n}","preventionTips":["Trim pasted keys and reject empty input before saving.","Clear the stored key when the provider selector changes so a stale key cannot pass as 'configured'.","Verify keys against the provider's models endpoint before trusting them."],"tags":["gitbutler","ai","api-key","settings","svelte"],"backgroundTag":"missing-api-key","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}