diff --git a/docs/core_docs/docs/integrations/chat/anthropic.ipynb b/docs/core_docs/docs/integrations/chat/anthropic.ipynb index 4786d1f68a9b..9fafc787406e 100644 --- a/docs/core_docs/docs/integrations/chat/anthropic.ipynb +++ b/docs/core_docs/docs/integrations/chat/anthropic.ipynb @@ -953,7 +953,7 @@ "const customClient = new AnthropicVertex();\n", "\n", "const modelWithCustomClient = new ChatAnthropic({\n", - " modelName: \"claude-3-sonnet-20240229\",\n", + " modelName: \"claude-3-sonnet@20240229\",\n", " maxRetries: 0,\n", " createClient: () => customClient,\n", "});\n", diff --git a/libs/langchain-anthropic/src/chat_models.ts b/libs/langchain-anthropic/src/chat_models.ts index c8edf3c17d0d..1e8853ff5b8a 100644 --- a/libs/langchain-anthropic/src/chat_models.ts +++ b/libs/langchain-anthropic/src/chat_models.ts @@ -633,7 +633,7 @@ export class ChatAnthropicMessages< fields?.anthropicApiKey ?? getEnvironmentVariable("ANTHROPIC_API_KEY"); - if (!this.anthropicApiKey) { + if (!this.anthropicApiKey && !fields?.createClient) { throw new Error("Anthropic API key not found"); } this.clientOptions = fields?.clientOptions ?? {}; @@ -949,9 +949,6 @@ export class ChatAnthropicMessages< ): Promise { if (!this.batchClient) { const options = this.apiUrl ? { baseURL: this.apiUrl } : undefined; - if (!this.apiKey) { - throw new Error("Missing Anthropic API key."); - } this.batchClient = this.createClient({ ...this.clientOptions, ...options,