Skip to content

fix(llm): wire base_url into AnthropicLLM and ZaiLLM clients - #968

Merged
wayyoungboy merged 2 commits into
oceanbase:mainfrom
lightzt99:fix/llm-base-url-anthropic-zai
Jun 5, 2026
Merged

fix(llm): wire base_url into AnthropicLLM and ZaiLLM clients#968
wayyoungboy merged 2 commits into
oceanbase:mainfrom
lightzt99:fix/llm-base-url-anthropic-zai

Conversation

@lightzt99

Copy link
Copy Markdown
Collaborator

Summary

  • AnthropicConfig already declares anthropic_base_url (env: ANTHROPIC_LLM_BASE_URL) but
    AnthropicLLM.__init__ never forwarded it to the anthropic.Anthropic() constructor — the field
    was silently ignored.
  • Added a secondary fallback to ANTHROPIC_BASE_URL so users whose Claude Code sets that variable
    automatically get the correct endpoint without extra .env config.
  • ZaiConfig already declares zai_base_url (env: ZAI_BASE_URL, default
    https://open.bigmodel.cn/api/paas/v4/) but ZaiLLM.__init__ never forwarded it either.
  • Replaced the ZhipuAiClient (from the zai SDK) with openai.OpenAI since Zhipu AI exposes
    an OpenAI-compatible endpoint — base_url is then passed directly, and a separate SDK
    dependency is removed with no behaviour change.
  • Added unit tests for both providers following the pattern of tests/unit/test_openai.py.

Motivation

Users pointing AnthropicLLM or ZaiLLM at a private proxy or a regional mirror had no
working way to redirect requests even though the config fields existed:

Provider Config field Env var Effect before this fix
Anthropic anthropic_base_url ANTHROPIC_LLM_BASE_URL Declared but never read — every request went to api.anthropic.com
Anthropic ANTHROPIC_BASE_URL Not read at all — Claude Code users needed manual workaround
ZAI zai_base_url ZAI_BASE_URL Declared but never read — always hit the hardcoded Zhipu default

Changes

File What changed
src/powermem/integrations/llm/anthropic.py Read anthropic_base_url from config and ANTHROPIC_BASE_URL from env; pass base_url to anthropic.Anthropic()
src/powermem/integrations/llm/zai.py Replace ZhipuAiClient with openai.OpenAI; read zai_base_url from config and pass as base_url
tests/unit/test_anthropic.py New — covers config field, ANTHROPIC_LLM_BASE_URL, and ANTHROPIC_BASE_URL
tests/unit/test_zai.py New — covers default URL, config field, ZAI_BASE_URL, generate_response, callback

Test plan

  • pytest tests/unit/test_anthropic.py tests/unit/test_zai.py — 6 passed
  • Real ZAI API call with zai_base_url explicitly set — response returned correctly
  • Real ZAI API call with default zai_base_url — response returned correctly
  • AnthropicLLM with anthropic_base_url config field — client.base_url matches
  • AnthropicLLM with ANTHROPIC_BASE_URL env var — client.base_url matches

lightzt99 added 2 commits June 5, 2026 16:17
AnthropicConfig already declares `anthropic_base_url` (env: ANTHROPIC_BASE_URL)
and ZaiConfig already declares `zai_base_url` (env: ZAI_BASE_URL), but neither
value was forwarded to the SDK client constructor.

For Anthropic: pass base_url to anthropic.Anthropic().
For ZAI: Zhipu AI exposes an OpenAI-compatible endpoint, so replace the
ZhipuAiClient dependency with openai.OpenAI and pass base_url directly —
no behavioural change since the response format is identical.
@wayyoungboy
wayyoungboy merged commit ced6d6d into oceanbase:main Jun 5, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants