# Call OpenAI and Anthropic from one Python API with LiteLLM

> Source: <https://dev.to/dedupedai/call-openai-and-anthropic-from-one-python-api-with-litellm-4jk5>
> Published: 2026-11-02 20:09:30+00:00

Every LLM provider has its own SDK, auth pattern and error types. Adding a model usually means more glue code. [LiteLLM](https://github.com/BerriAI/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.

``` python
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](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](https://dedupedai.com/use-cases/berriai-litellm/call-100-llms-with-one-openai-format-api/?utm_source=devto&utm_medium=article&utm_campaign=howto_litellm). More on the repo: [LiteLLM use cases](https://dedupedai.com/use-cases/berriai-litellm/?utm_source=devto&utm_medium=article&utm_campaign=howto_litellm).

Source repo: [BerriAI/litellm](https://github.com/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](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](https://dedupedai.com/join/?utm_source=devto&utm_medium=article&utm_campaign=howto_litellm)**
