anthropics / anthropics/claude-agent-sdk-python

Custom ANTHROPIC_BASE_URL ignored when used with LiteLLM + SAP AI Core

Aperta
#677 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
8.1k
Fork
1.3k
Merge medio
2g 31m
PR unite (30g)
1

Descrizione

**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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.