cd /news/ai-tools/call-openai-and-anthropic-from-one-p… · home › topics › ai-tools › article
[ARTICLE · art-162732] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

Call OpenAI and Anthropic from one Python API with LiteLLM

LiteLLM, an open-source library from BerriAI, lets developers call more than 100 LLM providers through a single OpenAI-format completion call, so switching between OpenAI's gpt-4o and Anthropic's claude-sonnet-4-20250514 requires changing only the model string. The library also ships a proxy with virtual keys and spend tracking for teams that need shared model access without distributing raw provider API keys. The quick-start proxy listens on 0.0.0.0:4000, and the writeup cautions that network, TLS and access controls must be added before exposing it.

by read2 min views1 publishedNov 2, 2026

Every LLM provider has its own SDK, auth pattern and error types. Adding a model usually means more glue code. LiteLLM gives you one OpenAI-format call for 100+ providers, so switching from OpenAI to Anthropic is a one-string change. This is the short setup from the README.

One completion call in OpenAI format returns a response from whichever provider you name. You change only the model string. You still need an account and API key for each provider, and each provider's own pricing and limits apply.

uv add litellm

Set them as environment variables, such as OPENAI_API_KEY and ANTHROPIC_API_KEY. Keep them out of your code and out of version control.

from litellm import completion

messages = [{"role": "user", "content": "Hello!"}]
print(completion(model="openai/gpt-4o", messages=messages))

Change the model string and run the same call again:

print(completion(model="anthropic/claude-sonnet-4-20250514", messages=messages))

Same code, same response shape, different provider.

If several developers need model access without sharing raw provider keys, LiteLLM also ships a proxy with virtual keys and spend tracking.

uv tool install 'litellm[proxy]'
litellm --model gpt-4o

Point any OpenAI client at http://0.0.0.0:4000 and use a virtual key as the api_key. The README links an end-to-end tutorial for creating virtual keys: https://docs.litellm.ai/docs/proxy/docker_quick_start

One caution: the quick start listens on 0.0.0.0:4000, so add your own network, TLS and access controls before you expose it to a team.

"Using the litellm repo, write a short Python script that sends 'Hello!' to openai/gpt-4o and to anthropic/claude-sonnet-4-20250514 through litellm.completion. Print both responses. Verify both API keys are set in the environment before running."

Step-by-step card: Call 100+ LLM providers through one OpenAI-format API. More on the repo: LiteLLM use cases.

Source repo: BerriAI/litellm.

Want the setup commands for 50 AI repos people actually ship with? Get the free AI Repos That Actually Ship pack: https://dedupedai.com/ship-pack/?utm_source=devto&utm_medium=article&utm_campaign=shippack

Get one email every Monday with the week's hottest AI repos and exactly how to use them: subscribe free at dedupedai.com

── more in #ai-tools 4 stories · sorted by recency
── more on @litellm 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/call-openai-and-anth…] indexed:0 read:2min 2026-11-02 · —