{"slug": "call-openai-and-anthropic-from-one-python-api-with-litellm", "title": "Call OpenAI and Anthropic from one Python API with LiteLLM", "summary": "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.", "body_md": "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.\n\nOne `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.\n\n```\nuv add litellm\n```\n\nSet them as environment variables, such as `OPENAI_API_KEY` and `ANTHROPIC_API_KEY`. Keep them out of your code and out of version control.\n\n``` python\nfrom litellm import completion\n\nmessages = [{\"role\": \"user\", \"content\": \"Hello!\"}]\nprint(completion(model=\"openai/gpt-4o\", messages=messages))\n```\n\nChange the model string and run the same call again:\n\n```\nprint(completion(model=\"anthropic/claude-sonnet-4-20250514\", messages=messages))\n```\n\nSame code, same response shape, different provider.\n\nIf several developers need model access without sharing raw provider keys, LiteLLM also ships a proxy with virtual keys and spend tracking.\n\n```\nuv tool install 'litellm[proxy]'\nlitellm --model gpt-4o\n```\n\nPoint 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)\n\nOne 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.\n\n\"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.\"\n\nStep-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).\n\nSource repo: [BerriAI/litellm](https://github.com/BerriAI/litellm).\n\nWant 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)\n\n**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)**", "url": "https://wpnews.pro/news/call-openai-and-anthropic-from-one-python-api-with-litellm", "canonical_source": "https://dev.to/dedupedai/call-openai-and-anthropic-from-one-python-api-with-litellm-4jk5", "published_at": "2026-11-02 20:09:30+00:00", "updated_at": "2026-11-02 20:22:51.771986+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models", "developer-tools", "ai-agents"], "entities": ["LiteLLM", "BerriAI", "OpenAI", "Anthropic", "gpt-4o", "claude-sonnet-4-20250514"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/call-openai-and-anthropic-from-one-python-api-with-litellm", "markdown": "https://wpnews.pro/news/call-openai-and-anthropic-from-one-python-api-with-litellm.md", "text": "https://wpnews.pro/news/call-openai-and-anthropic-from-one-python-api-with-litellm.txt", "jsonld": "https://wpnews.pro/news/call-openai-and-anthropic-from-one-python-api-with-litellm.jsonld"}}