Skip to content

Commit 1e1d8d1

Browse files
rxliulijacoblee93
andauthored
fix(anthropic): Do not check for apiKey existence when createClient parameters are present (#6716)
Co-authored-by: Jacob Lee <[email protected]>
1 parent e00236d commit 1e1d8d1

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

docs/core_docs/docs/integrations/chat/anthropic.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@
953953
"const customClient = new AnthropicVertex();\n",
954954
"\n",
955955
"const modelWithCustomClient = new ChatAnthropic({\n",
956-
" modelName: \"claude-3-sonnet-20240229\",\n",
956+
" modelName: \"claude-3-sonnet@20240229\",\n",
957957
" maxRetries: 0,\n",
958958
" createClient: () => customClient,\n",
959959
"});\n",

libs/langchain-anthropic/src/chat_models.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ export class ChatAnthropicMessages<
633633
fields?.anthropicApiKey ??
634634
getEnvironmentVariable("ANTHROPIC_API_KEY");
635635

636-
if (!this.anthropicApiKey) {
636+
if (!this.anthropicApiKey && !fields?.createClient) {
637637
throw new Error("Anthropic API key not found");
638638
}
639639
this.clientOptions = fields?.clientOptions ?? {};
@@ -949,9 +949,6 @@ export class ChatAnthropicMessages<
949949
): Promise<Anthropic.Message> {
950950
if (!this.batchClient) {
951951
const options = this.apiUrl ? { baseURL: this.apiUrl } : undefined;
952-
if (!this.apiKey) {
953-
throw new Error("Missing Anthropic API key.");
954-
}
955952
this.batchClient = this.createClient({
956953
...this.clientOptions,
957954
...options,

0 commit comments

Comments
 (0)