{"record":{"id":"c0b015b771d9c1af","repo":"windmill-labs/windmill","slug":"anthropic-not-initialized","errorCode":null,"errorMessage":"Anthropic not initialized","messagePattern":"Anthropic not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/copilot/lib.ts","lineNumber":557,"sourceCode":"\n\tcreateOpenaiClient(workspace: string): OpenAI {\n\t\treturn createOpenAIProxyClient(getAiProxyBaseURL(workspace))\n\t}\n\n\tcreateAnthropicClient(workspace: string): Anthropic {\n\t\treturn createAnthropicProxyClient(getAiProxyBaseURL(workspace))\n\t}\n\n\tgetOpenaiClient() {\n\t\tif (!this.openaiClient) {\n\t\t\tthrow new Error('OpenAI not initialized')\n\t\t}\n\t\treturn this.openaiClient\n\t}\n\n\tgetAnthropicClient() {\n\t\tif (!this.anthropicClient) {\n\t\t\tthrow new Error('Anthropic not initialized')\n\t\t}\n\t\treturn this.anthropicClient\n\t}\n}\n\nexport const workspaceAIClients = new WorkspacedAIClients()\n\nexport async function testKey({\n\tapiKey,\n\tworkspace,\n\tresourcePath,\n\tmodel,\n\tabortController,\n\tmessages,\n\taiProvider\n}: {\n\tapiKey?: string\n\tworkspace?: string","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/copilot/lib.ts#L539-L575","documentation":"Same guard as the OpenAI variant but for the Anthropic SDK client cached on WorkspacedAIClients. getAnthropicClient() throws 'Anthropic not initialized' when anthropicClient is undefined — createAnthropicClient(workspace) (which builds a client against the AI proxy base URL) has not run for the current workspace.","triggerScenarios":"Calling workspaceAIClients.getAnthropicClient() before createAnthropicClient(workspace) was called for the active workspace; accessing Anthropic-only features (Claude models, Anthropic-Messages-API completions) on a path that only initialized the OpenAI client.","commonSituations":"Selecting a Claude model in a flow that only ran OpenAI setup; workspace switch without re-init; fresh module instance in tests or after HMR missing the initialization call.","solutions":["Call workspaceAIClients.createAnthropicClient(workspace) before using getAnthropicClient().","Verify the workspace argument matches the active workspace; re-create on workspace switch.","Route through AIChatManager's clients.anthropic so initialization is handled centrally.","If only OpenAI models are intended, ensure the selected model does not route to the Anthropic client."],"exampleFix":"// before\nconst anthropic = workspaceAIClients.getAnthropicClient()\n// after\nworkspaceAIClients.createAnthropicClient(workspace)\nconst anthropic = workspaceAIClients.getAnthropicClient()","handlingStrategy":"validation","validationCode":"function needsAnthropic(model: string): boolean {\n  return /claude/i.test(model)\n}","typeGuard":null,"tryCatchPattern":"try {\n  const anthropic = workspaceAIClients.getAnthropicClient()\n  // use anthropic\n} catch (e) {\n  if (e.message === 'Anthropic not initialized') {\n    workspaceAIClients.createAnthropicClient(workspace)\n  } else throw e\n}","preventionTips":["Initialize both OpenAI and Anthropic clients together at workspace setup.","Gate Anthropic-only code paths on model selection (Claude models) and initialize lazily there.","Re-run initialization after HMR or workspace changes in dev."],"tags":["frontend","initialization","copilot","anthropic"],"backgroundTag":"client-not-initialized","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}