Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Update Anthropic unified docs with multi-provider examples and proxy usage (#11523)

Ishaan Jaff3351f0513e0b
diff --git a/docs/my-website/docs/anthropic_unified.md b/docs/my-website/docs/anthropic_unified.md
index 8a34db52482..404c1675b8f 100644
--- a/docs/my-website/docs/anthropic_unified.md
+++ b/docs/my-website/docs/anthropic_unified.md
@@ -14,29 +14,239 @@ Use LiteLLM to call all your LLM APIs in the Anthropic `v1/messages` format.
| Logging | ✅ | works across all integrations |
| End-user Tracking | ✅ | |
| Streaming | ✅ | |
-| Fallbacks | ✅ | between anthropic models |
-| Loadbalancing | ✅ | between anthropic models |
-| Support llm providers | - `anthropic` <br/> - `bedrock` (only Anthropic models) | |
-
-Planned improvement:
-- Vertex AI Anthropic support
+| Fallbacks | ✅ | between supported models |
+| Loadbalancing | ✅ | between supported models |
+| Support llm providers | **All LiteLLM supported providers** | `openai`, `anthropic`, `bedrock`, `vertex_ai`, `gemini`, `azure`, `azure_ai`, etc. |
## Usage
---
### LiteLLM Python SDK
+<Tabs>
+<TabItem value="anthropic" label="Anthropic">
+
#### Non-streaming example
-```python showLineNumbers title="Example using LiteLLM Python SDK"
+```python showLineNumbers title="Anthropic Example using LiteLLM Python SDK"
+import litellm
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ api_key=api_key,
+ model="anthropic/claude-3-haiku-20240307",
+ max_tokens=100,
+)
+```
+
+#### Streaming example
+```python showLineNumbers title="Anthropic Streaming Example using LiteLLM Python SDK"
import litellm
response = await litellm.anthropic.messages.acreate(
messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
api_key=api_key,
model="anthropic/claude-3-haiku-20240307",
max_tokens=100,
+ stream=True,
+)
+async for chunk in response:
+ print(chunk)
+```
+
+</TabItem>
+
+<TabItem value="openai" label="OpenAI">
+
+#### Non-streaming example
+```python showLineNumbers title="OpenAI Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set API key
+os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="openai/gpt-4",
+ max_tokens=100,
+)
+```
+
+#### Streaming example
+```python showLineNumbers title="OpenAI Streaming Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set API key
+os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="openai/gpt-4",
+ max_tokens=100,
+ stream=True,
+)
+async for chunk in response:
+ print(chunk)
+```
+
+</TabItem>
+
+<TabItem value="o1-pro" label="OpenAI o1-pro">
+
+#### Non-streaming example
+```python showLineNumbers title="OpenAI o1-pro Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set API key
+os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Solve this math problem: What is the derivative of x^3 + 2x^2 - 5x + 1?"}],
+ model="openai/o1-pro",
+ max_tokens=500,
+)
+```
+
+#### Streaming example
+```python showLineNumbers title="OpenAI o1-pro Streaming Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set API key
+os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Solve this math problem: What is the derivative of x^3 + 2x^2 - 5x + 1?"}],
+ model="openai/o1-pro",
+ max_tokens=500,
+ stream=True,
+)
+async for chunk in response:
+ print(chunk)
+```
+
+</TabItem>
+
+<TabItem value="gemini" label="Google Gemini">
+
+#### Non-streaming example
+```python showLineNumbers title="Google Gemini Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set API key
+os.environ["GEMINI_API_KEY"] = "your-gemini-api-key"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="gemini/gemini-2.0-flash-exp",
+ max_tokens=100,
)
```
+#### Streaming example
+```python showLineNumbers title="Google Gemini Streaming Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set API key
+os.environ["GEMINI_API_KEY"] = "your-gemini-api-key"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="gemini/gemini-2.0-flash-exp",
+ max_tokens=100,
+ stream=True,
+)
+async for chunk in response:
+ print(chunk)
+```
+
+</TabItem>
+
+<TabItem value="vertex" label="Vertex AI">
+
+#### Non-streaming example
+```python showLineNumbers title="Vertex AI Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set credentials - Vertex AI uses application default credentials
+# Run 'gcloud auth application-default login' to authenticate
+os.environ["VERTEXAI_PROJECT"] = "your-gcp-project-id"
+os.environ["VERTEXAI_LOCATION"] = "us-central1"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="vertex_ai/gemini-2.0-flash-exp",
+ max_tokens=100,
+)
+```
+
+#### Streaming example
+```python showLineNumbers title="Vertex AI Streaming Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set credentials - Vertex AI uses application default credentials
+# Run 'gcloud auth application-default login' to authenticate
+os.environ["VERTEXAI_PROJECT"] = "your-gcp-project-id"
+os.environ["VERTEXAI_LOCATION"] = "us-central1"
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="vertex_ai/gemini-2.0-flash-exp",
+ max_tokens=100,
+ stream=True,
+)
+async for chunk in response:
+ print(chunk)
+```
+
+</TabItem>
+
+<TabItem value="bedrock" label="AWS Bedrock">
+
+#### Non-streaming example
+```python showLineNumbers title="AWS Bedrock Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set AWS credentials
+os.environ["AWS_ACCESS_KEY_ID"] = "your-access-key-id"
+os.environ["AWS_SECRET_ACCESS_KEY"] = "your-secret-access-key"
+os.environ["AWS_REGION_NAME"] = "us-west-2" # or your AWS region
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",
+ max_tokens=100,
+)
+```
+
+#### Streaming example
+```python showLineNumbers title="AWS Bedrock Streaming Example using LiteLLM Python SDK"
+import litellm
+import os
+
+# Set AWS credentials
+os.environ["AWS_ACCESS_KEY_ID"] = "your-access-key-id"
+os.environ["AWS_SECRET_ACCESS_KEY"] = "your-secret-access-key"
+os.environ["AWS_REGION_NAME"] = "us-west-2" # or your AWS region
+
+response = await litellm.anthropic.messages.acreate(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",
+ max_tokens=100,
+ stream=True,
+)
+async for chunk in response:
+ print(chunk)
+```
+
+</TabItem>
+</Tabs>
+
Example response:
```json
{
@@ -61,30 +271,57 @@ Example response:
}
```
-#### Streaming example
-```python showLineNumbers title="Example using LiteLLM Python SDK"
-import litellm
-response = await litellm.anthropic.messages.acreate(
+### LiteLLM Proxy Server
+
+<Tabs>
+<TabItem value="anthropic-proxy" label="Anthropic">
+
+1. Setup config.yaml
+
+```yaml
+model_list:
+ - model_name: anthropic-claude
+ litellm_params:
+ model: claude-3-7-sonnet-latest
+ api_key: os.environ/ANTHROPIC_API_KEY
+```
+
+2. Start proxy
+
+```bash
+litellm --config /path/to/config.yaml
+```
+
+3. Test it!
+
+```python showLineNumbers title="Anthropic Example using LiteLLM Proxy Server"
+import anthropic
+
+# point anthropic sdk to litellm proxy
+client = anthropic.Anthropic(
+ base_url="http://0.0.0.0:4000",
+ api_key="sk-1234",
+)
+
+response = client.messages.create(
messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
- api_key=api_key,
- model="anthropic/claude-3-haiku-20240307",
+ model="anthropic-claude",
max_tokens=100,
- stream=True,
)
-async for chunk in response:
- print(chunk)
```
-### LiteLLM Proxy Server
+</TabItem>
+<TabItem value="openai-proxy" label="OpenAI">
1. Setup config.yaml
```yaml
model_list:
- - model_name: anthropic-claude
+ - model_name: openai-gpt4
litellm_params:
- model: claude-3-7-sonnet-latest
+ model: openai/gpt-4
+ api_key: os.environ/OPENAI_API_KEY
```
2. Start proxy
@@ -95,10 +332,83 @@ litellm --config /path/to/config.yaml
3. Test it!
-<Tabs>
-<TabItem label="Anthropic Python SDK" value="python">
+```python showLineNumbers title="OpenAI Example using LiteLLM Proxy Server"
+import anthropic
+
+# point anthropic sdk to litellm proxy
+client = anthropic.Anthropic(
+ base_url="http://0.0.0.0:4000",
+ api_key="sk-1234",
+)
+
+response = client.messages.create(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="openai-gpt4",
+ max_tokens=100,
+)
+```
+
+</TabItem>
+
+<TabItem value="o1-pro-proxy" label="OpenAI o1-pro">
+
+1. Setup config.yaml
+
+```yaml
+model_list:
+ - model_name: openai-o1-pro
+ litellm_params:
+ model: openai/o1-pro
+ api_key: os.environ/OPENAI_API_KEY
+```
+
+2. Start proxy
+
+```bash
+litellm --config /path/to/config.yaml
+```
+
+3. Test it!
-```python showLineNumbers title="Example using LiteLLM Proxy Server"
+```python showLineNumbers title="OpenAI o1-pro Example using LiteLLM Proxy Server"
+import anthropic
+
+# point anthropic sdk to litellm proxy
+client = anthropic.Anthropic(
+ base_url="http://0.0.0.0:4000",
+ api_key="sk-1234",
+)
+
+response = client.messages.create(
+ messages=[{"role": "user", "content": "Solve this math problem: What is the derivative of x^3 + 2x^2 - 5x + 1?"}],
+ model="openai-o1-pro",
+ max_tokens=500,
+)
+```
+
+</TabItem>
+
+<TabItem value="gemini-proxy" label="Google Gemini">
+
+1. Setup config.yaml
+
+```yaml
+model_list:
+ - model_name: gemini-2-flash
+ litellm_params:
+ model: gemini/gemini-2.0-flash-exp
+ api_key: os.environ/GEMINI_API_KEY
+```
+
+2. Start proxy
+
+```bash
+litellm --config /path/to/config.yaml
+```
+
+3. Test it!
+
+```python showLineNumbers title="Google Gemini Example using LiteLLM Proxy Server"
import anthropic
# point anthropic sdk to litellm proxy
@@ -109,12 +419,93 @@ client = anthropic.Anthropic(
response = client.messages.create(
messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
- model="anthropic-claude",
+ model="gemini-2-flash",
max_tokens=100,
)
```
+
</TabItem>
-<TabItem label="curl" value="curl">
+
+<TabItem value="vertex-proxy" label="Vertex AI">
+
+1. Setup config.yaml
+
+```yaml
+model_list:
+ - model_name: vertex-gemini
+ litellm_params:
+ model: vertex_ai/gemini-2.0-flash-exp
+ vertex_project: your-gcp-project-id
+ vertex_location: us-central1
+```
+
+2. Start proxy
+
+```bash
+litellm --config /path/to/config.yaml
+```
+
+3. Test it!
+
+```python showLineNumbers title="Vertex AI Example using LiteLLM Proxy Server"
+import anthropic
+
+# point anthropic sdk to litellm proxy
+client = anthropic.Anthropic(
+ base_url="http://0.0.0.0:4000",
+ api_key="sk-1234",
+)
+
+response = client.messages.create(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="vertex-gemini",
+ max_tokens=100,
+)
+```
+
+</TabItem>
+
+<TabItem value="bedrock-proxy" label="AWS Bedrock">
+
+1. Setup config.yaml
+
+```yaml
+model_list:
+ - model_name: bedrock-claude
+ litellm_params:
+ model: bedrock/anthropic.claude-3-sonnet-20240229-v1:0
+ aws_access_key_id: os.environ/AWS_ACCESS_KEY_ID
+ aws_secret_access_key: os.environ/AWS_SECRET_ACCESS_KEY
+ aws_region_name: us-west-2
+```
+
+2. Start proxy
+
+```bash
+litellm --config /path/to/config.yaml
+```
+
+3. Test it!
+
+```python showLineNumbers title="AWS Bedrock Example using LiteLLM Proxy Server"
+import anthropic
+
+# point anthropic sdk to litellm proxy
+client = anthropic.Anthropic(
+ base_url="http://0.0.0.0:4000",
+ api_key="sk-1234",
+)
+
+response = client.messages.create(
+ messages=[{"role": "user", "content": "Hello, can you tell me a short joke?"}],
+ model="bedrock-claude",
+ max_tokens=100,
+)
+```
+
+</TabItem>
+
+<TabItem value="curl-proxy" label="curl">
```bash showLineNumbers title="Example using LiteLLM Proxy Server"
curl -L -X POST 'http://0.0.0.0:4000/v1/messages' \
@@ -136,7 +527,6 @@ curl -L -X POST 'http://0.0.0.0:4000/v1/messages' \
</TabItem>
</Tabs>
-
## Request Format
---
@@ -189,7 +579,7 @@ Request body will be in the Anthropic messages API format. **litellm follows the
- **system** (string or array):
A system prompt providing context or specific instructions to the model.
- **temperature** (number):
- Controls randomness in the model’s responses. Valid range: `0 < temperature < 1`.
+ Controls randomness in the model's responses. Valid range: `0 < temperature < 1`.
- **thinking** (object):
Configuration for enabling extended thinking. If enabled, it includes:
- **budget_tokens** (integer):
@@ -201,7 +591,7 @@ Request body will be in the Anthropic messages API format. **litellm follows the
- **tools** (array of objects):
Definitions for tools available to the model. Each tool includes:
- **name** (string):
- The tool’s name.
+ The tool's name.
- **description** (string):
A detailed description of the tool.
- **input_schema** (object):