OpenAI-to-Claude API Translation With LiteLLM
How LiteLLM translates OpenAI Chat Completions requests into Anthropic's Claude format, covering tools, streaming, and proxy routing.
OpenAI-to-Claude API Translation With LiteLLM
Applications written against the OpenAI Chat Completions format cannot send the same requests directly to Anthropic’s Claude models, because Claude uses a different API shape. LiteLLM is an open-source library that closes that gap by acting as a translation layer between the OpenAI Chat Completions format and Anthropic’s native API. Its documentation at https://docs.litellm.ai/docs/providers/anthropic describes how the translation works and which features it supports.
What Gets Translated
LiteLLM routes Anthropic requests through an anthropic/ prefix and exposes both /chat/completions and a /v1/messages passthrough endpoint. Several specific parameter conversions are documented:
- OpenAI’s
reasoning_effortis translated to Anthropic’sthinkingparameter, with values such as “low” mapping to abudget_tokensvalue. - The OpenAI
userparameter is translated to Anthropic’smetadata[user_id]parameter. - OpenAI’s
search_context_sizeparameter is mapped to Anthropic’smax_usesparameter for web search. - OpenAI’s
response_formatis transformed into Anthropic’s structured output format, with the required beta header added automatically.
The library also handles a difference in required fields. Because the Anthropic API rejects requests that do not include max_tokens, LiteLLM passes a default of max_tokens=4096 when a request omits it.
System messages are handled as part of the translation as well. The documentation notes that system role messages are formatted appropriately, and multi-element system content using text blocks is supported, including prompt caching.
Tool Use and Streaming
Function calling is supported through the OpenAI-style interface. The documentation covers standard tool use, forcing Anthropic tool use, disabling tools by setting tool_choice to “none”, parallel function calling, and MCP tool calling in the OpenAI Responses API format. Anthropic’s hosted tools, including the computer, text editor, web search, and memory tools, are also available.
Streaming works by setting stream=True on the completion call. The returned chunks come back in the same format an OpenAI client expects, so streaming code does not need to change to account for Claude’s underlying event structure.
Model names map from human-friendly identifiers to specific Claude model calls. For example, a name like claude-3-5-sonnet resolves to a completion call against a dated model identifier.
Running It as a Proxy
Beyond the library interface, LiteLLM offers a proxy server, described as an AI gateway, that is OpenAI compatible. An existing OpenAI client can point at a local base URL such as http://0.0.0.0:4000 instead of OpenAI’s endpoint. Models are defined in a config.yaml file with litellm_params, and the proxy is started with litellm --config. A wildcard model_name: "*" entry can route any Anthropic model without listing each one individually.
This proxy approach means tools that already speak the OpenAI API, including the OpenAI SDK and LangChain’s ChatOpenAI class, can target Claude through the gateway without code changes. For teams evaluating Claude alongside an existing OpenAI integration, the translation layer removes the need to maintain two separate request formats.
Source: docs.litellm.ai
Related Tips
Memory Systems for Long-Running AI Agents
How long-running AI agents manage memory through compaction, note-taking, and sub-agents, based on Anthropic's context engineering guidance.
Claude Code Hooks Can Block Risky Actions
Claude Code hooks run shell commands at lifecycle points and can deterministically block tool calls like risky edits or shell commands.
How Claude Code Remembers Projects With CLAUDE.md
Claude Code uses CLAUDE.md files and auto memory to carry project context across sessions, with files written by developers and notes written by Claude.