anthropics / anthropics/claude-agent-sdk-python

Custom ANTHROPIC_BASE_URL ignored when used with LiteLLM + SAP AI Core

Aberta
#677 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
8.1k
Forks
1.3k
Merge médio
2d 31min
PRs com merge (30d)
1

Descrição

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

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.