From 183531320706a4829500032618c6f257a75bbde3 Mon Sep 17 00:00:00 2001 From: Zhengda Lu Date: Sun, 22 Mar 2026 17:52:18 -0400 Subject: [PATCH] Respect Anthropic proxy base URL --- tradingagents/llm_clients/anthropic_client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tradingagents/llm_clients/anthropic_client.py b/tradingagents/llm_clients/anthropic_client.py index 8539c752..ad7b167d 100644 --- a/tradingagents/llm_clients/anthropic_client.py +++ b/tradingagents/llm_clients/anthropic_client.py @@ -1,3 +1,4 @@ +import os from typing import Any, Optional from langchain_anthropic import ChatAnthropic @@ -9,6 +10,8 @@ from .validators import validate_model class AnthropicClient(BaseLLMClient): """Client for Anthropic Claude models.""" + _DEFAULT_API_URL = "https://api.anthropic.com" + def __init__(self, model: str, base_url: Optional[str] = None, **kwargs): super().__init__(model, base_url, **kwargs) @@ -16,6 +19,13 @@ class AnthropicClient(BaseLLMClient): """Return configured ChatAnthropic instance.""" llm_kwargs = {"model": self.model} + env_base_url = os.getenv("ANTHROPIC_BASE_URL") + if self.base_url and not ( + env_base_url + and self.base_url.rstrip("/") == self._DEFAULT_API_URL + ): + llm_kwargs["anthropic_api_url"] = self.base_url + for key in ("timeout", "max_retries", "api_key", "max_tokens", "callbacks", "http_client", "http_async_client"): if key in self.kwargs: llm_kwargs[key] = self.kwargs[key]