hsliuping/TradingAgents-CN · error · ValueError
Unsupported LLM provider: {provider}
Error message
Unsupported LLM provider: {provider} What it means
Raised by create_llm_client when the requested LLM provider string does not match any of the supported providers after lowercasing. The factory only recognizes a fixed set (e.g. 'anthropic', plus other handled branches above line 53); anything else falls through to this ValueError. It exists to fail fast on typos or unsupported backends before client construction.
Source
Thrown at tradingagents/llm_clients/factory.py:53
provider_lower = normalize_provider_key(provider)
provider_lower = _PROVIDER_ALIASES.get(provider_lower, provider_lower)
if provider_lower in _OPENAI_COMPATIBLE:
from .openai_client import OpenAIClient
return OpenAIClient(model, base_url, provider=provider_lower, **kwargs)
if provider_lower == "google":
from .google_client import GoogleClient
return GoogleClient(model, base_url, **kwargs)
if provider_lower == "anthropic":
from .anthropic_client import AnthropicClient
return AnthropicClient(model, base_url, **kwargs)
raise ValueError(f"Unsupported LLM provider: {provider}")
View on GitHub (pinned to 74783e8817)
Solutions
- Check the factory's if/elif chain above line 53 for the exact supported provider strings and correct the argument to one of them (e.g. 'anthropic').
- Print/inspect the exact value being passed (including whitespace and case) at the call site or from config before invoking the factory.
- If you need a new backend, add a matching branch that imports and returns the corresponding client class instead of bypassing the factory.
- Upgrade the package if the provider was added in a newer release.
Example fix
// before client = create_llm_client(provider="Anthropic ", model="claude-3-5-sonnet") # after client = create_llm_client(provider="anthropic", model="claude-3-5-sonnet")
Defensive patterns
Strategy: validation
Validate before calling
from tradingagents.llm_clients.factory import create_llm_client
SUPPORTED_PROVIDERS = {"anthropic", "openai", "deepseek", "google", "ollama"} # mirror factory branches
provider = (provider or "").strip().lower()
if provider not in SUPPORTED_PROVIDERS:
raise ConfigError(f"bad provider {provider!r}; expected one of {sorted(SUPPORTED_PROVIDERS)}")
client = create_llm_client(provider, model, base_url, **kwargs) Type guard
def is_supported_provider(p: str) -> bool:
"""Check against the factory's if/elif branches (see factory.py)."""
return isinstance(p, str) and p.strip().lower() in {"anthropic", "openai", "deepseek", "google", "ollama"} Try / catch
try:
client = create_llm_client(provider, model, base_url, **kwargs)
except ValueError as e:
if "Unsupported LLM provider" in str(e):
raise ConfigError(f"Fix provider setting: {provider!r}") from e
raise Prevention
- Centralize provider selection in config and validate it at startup, not per request.
- Normalize with .strip().lower() before calling the factory.
- Keep the allowed provider list in sync with factory.py when upgrading.
When it happens
Trigger: Calling create_llm_client(model, base_url) or create_llm_client('openai', ...) with a provider string like 'OpenAI ', 'gpt', 'azure-openai', 'googl', or an unimplemented backend — any value whose lowercased form has no matching if-branch in the factory.
Common situations: Typo in the provider name from config/env (LLM_PROVIDER=opanai), passing a model name instead of a provider name, using a provider the installed version doesn't support (azure, bedrock, ollama), or trailing whitespace/case differences if not normalized upstream.
Related errors
- 使用Google需要设置GOOGLE_API_KEY环境变量或在数据库中配置API Key
- 使用SiliconFlow需要设置SILICONFLOW_API_KEY环境变量
- 使用OpenRouter需要设置OPENROUTER_API_KEY或OPENAI_API_KEY环境变量
- 使用AiHubMix需要设置AIHUBMIX_API_KEY环境变量
- 使用Google AI需要在数据库中配置API Key或设置GOOGLE_API_KEY环境变量
AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28).
Data as JSON: /api/errors/51f4439aabec1d74.
Report an issue: GitHub.