anthropics / anthropics/claude-agent-sdk-python

Custom ANTHROPIC_BASE_URL ignored when used with LiteLLM + SAP AI Core

未关闭
#677 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
8.1k
派生
1.3k
平均合并
2 天 31 分钟
30 天内合并 PR
1

描述

**Problem:** Custom ANTHROPIC_BASE_URL ignored when used the Agent SDK is used with LiteLLM + SAP AI Core

**Setup:**
- FastAPI backend → Claude Agent SDK → LiteLLM proxy (sidecar on port 4000) → SAP AI Core (Anthropic Claude)
- LiteLLM is configured with sap/anthropic--claude-4.6-* models via the sap provider

**Issues encountered:**

It looks like the bundled binary ignores `ANTHROPIC_BASE_URL`. When the SDK spawns it as a subprocess, the bundled binary did not respect ANTHROPIC_BASE_URL passed via `ClaudeAgentOptions(env={...})`, bypassing the LiteLLM entirely.

Workaround: I managed to make it work by forcing the system-installed claude binary via `cli_path=shutil.which("claude")`. This workaround works, but I am wondering why the custom base URL is ignored, and if there is a more elegant solution?

thank you :)

```
@router.get("/test")
async def test(request: Request):
# Workaround: setting cli_path
# Force the system-installed Claude Code CLI instead of the SDK's bundled binary.
# The bundled binary seems to ignore ANTHROPIC_BASE_URL, bypassing LiteLLM.
# The system binary respects it.
options = ClaudeAgentOptions(
cli_path=shutil.which("claude"),
env={
"ANTHROPIC_BASE_URL": "http://localhost:4000",
"ANTHROPIC_API_KEY": "dummy",
},
system_prompt="You are a helpful AI assistant.",
model="anthropic--claude-4.6-opus",
max_turns=20,
)

full_answer = ""

async with ClaudeSDKClient(options=options) as client:
await client.query("Reply with OK")

async for msg in client.receive_response():
if hasattr(msg, 'content'):
for content_block in msg.content:
if hasattr(content_block, 'text'):
text = content_block.text
print(text, end='', flush=True)
full_answer += text

print("Agent response:", full_answer)
return AgentResponse(result=full_answer)
```

DOCS
- https://docs.litellm.ai/docs/providers/sap#anthropic-models-special-syntax
- https://docs.litellm.ai/docs/tutorials/claude_agent_sdk

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。