{"record":{"id":"e8e382c049ac1b8a","repo":"gitbutlerapp/gitbutler","slug":"when-using-gitbutler-s-api-to-summarize-code-you","errorCode":null,"errorMessage":"When using GitButler's API to summarize code, you must be logged in","messagePattern":"When using GitButler's API to summarize code, you must be logged in","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/desktop/src/lib/ai/service.ts","lineNumber":314,"sourceCode":"\n\tasync validateGitButlerAPIConfiguration(): Promise<boolean> {\n\t\tif (!(await this.usingGitButlerAPI())) {\n\t\t\treturn false;\n\t\t}\n\t\treturn !!get(this.tokenMemoryService.token);\n\t}\n\n\t// This optionally returns a summarizer. There are a few conditions for how this may occur\n\t// Firstly, if the user has opted to use the GB API and isn't logged in, it will return undefined\n\t// Secondly, if the user has opted to bring their own key but hasn't provided one, it will return undefined\n\tasync buildClient(): Promise<AIClient | undefined> {\n\t\tconst modelKind = await this.getModelKind();\n\n\t\tif (await this.usingGitButlerAPI()) {\n\t\t\t// TODO(CTO): Once @estib has landed the new auth, it would be good to\n\t\t\t// about a good way of checking whether the user is authenticated.\n\t\t\tif (!get(this.tokenMemoryService.token)) {\n\t\t\t\tthrow new Error(\"When using GitButler's API to summarize code, you must be logged in\");\n\t\t\t}\n\n\t\t\treturn new ButlerAIClient(this.cloud, modelKind);\n\t\t}\n\n\t\tif (modelKind === ModelKind.Ollama) {\n\t\t\tconst ollamaEndpoint = await this.getOllamaEndpoint();\n\t\t\tconst ollamaModelName = await this.getOllamaModelName();\n\t\t\treturn new OllamaClient(ollamaEndpoint, ollamaModelName);\n\t\t}\n\n\t\tif (modelKind === ModelKind.LMStudio) {\n\t\t\tconst lmStudioEndpoint = await this.getLMStudioEndpoint();\n\t\t\tconst lmStudioModelName = await this.getLMStudioModelName();\n\n\t\t\tif (!lmStudioEndpoint) {\n\t\t\t\tthrow new Error(\"When using LM Studio, you must provide a valid endpoint\");\n\t\t\t}","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/apps/desktop/src/lib/ai/service.ts#L296-L332","documentation":"AIService.buildClient() requires an authenticated GitButler token when the model kind is set to use GitButler's cloud API. If no token is stored in the token memory service, this error is thrown instead of constructing a ButlerAIClient.","triggerScenarios":"AI model setting is GitButler API while the user is not logged in to GitButler (token absent) at the time aiClient is requested.","commonSituations":"User enabled AI summarization but never signed in; token expired/cleared after a restart; account logout while AI settings still point at the cloud model.","solutions":["Log in to GitButler so a token is available.","Switch the AI model setting to a local provider (Ollama/LM Studio) or BYO-key provider if you don't want to log in.","Re-authenticate if the token was cleared or expired."],"exampleFix":"// before (app state)\nmodelKind: GitButlerAPI, token: null\n// after\nsign in via the GitButler UI, then keep modelKind: GitButlerAPI // token now present","handlingStrategy":"validation","validationCode":"const token = get(tokenMemoryService.token);\nif (!token && modelKind === ModelKind.GitButlerAPI) {\n  // prompt user to log in or switch to a local/BYO-key model before calling\n}","typeGuard":null,"tryCatchPattern":"try {\n  await aiService.summarize(...);\n} catch (e) {\n  if (e.message.includes('you must be logged in')) {\n    // trigger the login flow or offer provider switch in the UI\n  } else {\n    throw e;\n  }\n}","preventionTips":["Check login state before enabling GitButler-API AI features in the UI.","Re-authenticate after token expiry instead of retrying blindly.","Default to a local model when the user is not logged in."],"tags":["auth","configuration","cloud"],"backgroundTag":"authentication-required","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}