windmill-labs/windmill · error

Anthropic not initialized

Error message

Anthropic not initialized

What it means

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.

Source

Thrown at frontend/src/lib/components/copilot/lib.ts:557

	createOpenaiClient(workspace: string): OpenAI {
		return createOpenAIProxyClient(getAiProxyBaseURL(workspace))
	}

	createAnthropicClient(workspace: string): Anthropic {
		return createAnthropicProxyClient(getAiProxyBaseURL(workspace))
	}

	getOpenaiClient() {
		if (!this.openaiClient) {
			throw new Error('OpenAI not initialized')
		}
		return this.openaiClient
	}

	getAnthropicClient() {
		if (!this.anthropicClient) {
			throw new Error('Anthropic not initialized')
		}
		return this.anthropicClient
	}
}

export const workspaceAIClients = new WorkspacedAIClients()

export async function testKey({
	apiKey,
	workspace,
	resourcePath,
	model,
	abortController,
	messages,
	aiProvider
}: {
	apiKey?: string
	workspace?: string

View on GitHub (pinned to e474e8803c)

Solutions

  1. Call workspaceAIClients.createAnthropicClient(workspace) before using getAnthropicClient().
  2. Verify the workspace argument matches the active workspace; re-create on workspace switch.
  3. Route through AIChatManager's clients.anthropic so initialization is handled centrally.
  4. If only OpenAI models are intended, ensure the selected model does not route to the Anthropic client.

Example fix

// before
const anthropic = workspaceAIClients.getAnthropicClient()
// after
workspaceAIClients.createAnthropicClient(workspace)
const anthropic = workspaceAIClients.getAnthropicClient()
Defensive patterns

Strategy: validation

Validate before calling

function needsAnthropic(model: string): boolean {
  return /claude/i.test(model)
}

Try / catch

try {
  const anthropic = workspaceAIClients.getAnthropicClient()
  // use anthropic
} catch (e) {
  if (e.message === 'Anthropic not initialized') {
    workspaceAIClients.createAnthropicClient(workspace)
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/c0b015b771d9c1af. Report an issue: GitHub.