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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(converse_transformation.py): fix encoding model
Krrish Dholakia5dc46f0cf7d5
diff --git a/docs/my-website/docs/providers/bedrock.md b/docs/my-website/docs/providers/bedrock.mdindex 1416006bf10..19b3728882b 100644--- a/docs/my-website/docs/providers/bedrock.md+++ b/docs/my-website/docs/providers/bedrock.md@@ -1262,271 +1262,365 @@ curl -X POST 'http://0.0.0.0:4000/chat/completions' \</Tabs>-## Boto3 - Authentication+## Bedrock Imported Models (Deepseek, Deepseek R1)++### Deepseek R1++This is a separate route, as the chat template is different.++| Property | Details |+|----------|---------|+| Provider Route | `bedrock/deepseek_r1/{model_arn}` |+| Provider Documentation | [Bedrock Imported Models](https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html), [Deepseek Bedrock Imported Model](https://aws.amazon.com/blogs/machine-learning/deploy-deepseek-r1-distilled-llama-models-with-amazon-bedrock-custom-model-import/) |++<Tabs>+<TabItem value="sdk" label="SDK">-### Passing credentials as parameters - Completion()-Pass AWS credentials as parameters to litellm.completion```python-import osfrom litellm import completion+import osresponse = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=[{ "content": "Hello, how are you?","role": "user"}],- aws_access_key_id="",- aws_secret_access_key="",- aws_region_name="",+ model="bedrock/deepseek_r1/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n", # bedrock/deepseek_r1/{your-model-arn}+ messages=[{"role": "user", "content": "Tell me a joke"}],)```-### Passing extra headers + Custom API Endpoints+</TabItem>++<TabItem value="proxy" label="Proxy">+++**1. Add to config**++```yaml+model_list:+ - model_name: DeepSeek-R1-Distill-Llama-70B+ litellm_params:+ model: bedrock/deepseek_r1/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n++```++**2. Start proxy**++```bash+litellm --config /path/to/config.yaml++# RUNNING at http://0.0.0.0:4000+```++**3. Test it!**++```bash+curl --location 'http://0.0.0.0:4000/chat/completions' \+ --header 'Authorization: Bearer sk-1234' \+ --header 'Content-Type: application/json' \+ --data '{+ "model": "DeepSeek-R1-Distill-Llama-70B", # 👈 the 'model_name' in config+ "messages": [+ {+ "role": "user",+ "content": "what llm are you"+ }+ ],+ }'+```++</TabItem>+</Tabs>+++### Deepseek (not R1)++| Property | Details |+|----------|---------|+| Provider Route | `bedrock/llama/{model_arn}` |+| Provider Documentation | [Bedrock Imported Models](https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html), [Deepseek Bedrock Imported Model](https://aws.amazon.com/blogs/machine-learning/deploy-deepseek-r1-distilled-llama-models-with-amazon-bedrock-custom-model-import/) |++++Use this route to call Bedrock Imported Models that follow the `llama` Invoke Request / Response spec-This can be used to override existing headers (e.g. `Authorization`) when calling custom api endpoints<Tabs><TabItem value="sdk" label="SDK">```python-import os-import litellmfrom litellm import completion--litellm.set_verbose = True # 👈 SEE RAW REQUEST+import osresponse = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=[{ "content": "Hello, how are you?","role": "user"}],- aws_access_key_id="",- aws_secret_access_key="",- aws_region_name="",- aws_bedrock_runtime_endpoint="https://my-fake-endpoint.com",- extra_headers={"key": "value"}+ model="bedrock/llama/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n", # bedrock/llama/{your-model-arn}+ messages=[{"role": "user", "content": "Tell me a joke"}],)```+</TabItem>-<TabItem value="proxy" label="PROXY">-1. Setup config.yaml+<TabItem value="proxy" label="Proxy">+++**1. Add to config**```yamlmodel_list:- - model_name: bedrock-model+ - model_name: DeepSeek-R1-Distill-Llama-70Blitellm_params:- model: bedrock/anthropic.claude-instant-v1- aws_access_key_id: "",- aws_secret_access_key: "",- aws_region_name: "",- aws_bedrock_runtime_endpoint: "https://my-fake-endpoint.com",- extra_headers: {"key": "value"}+ model: bedrock/llama/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n+```-2. Start proxy+**2. Start proxy**```bash-litellm --config /path/to/config.yaml --detailed_debug+litellm --config /path/to/config.yaml++# RUNNING at http://0.0.0.0:4000```-3. Test it!+**3. Test it!**```bash-curl -X POST 'http://0.0.0.0:4000/chat/completions' \--H 'Content-Type: application/json' \--H 'Authorization: Bearer sk-1234' \--d '{- "model": "bedrock-model",- "messages": [- {- "role": "system",- "content": "You are a helpful math tutor. Guide the user through the solution step by step."- },- {- "role": "user",- "content": "how can I solve 8x + 7 = -23"- }- ]-}'+curl --location 'http://0.0.0.0:4000/chat/completions' \+ --header 'Authorization: Bearer sk-1234' \+ --header 'Content-Type: application/json' \+ --data '{+ "model": "DeepSeek-R1-Distill-Llama-70B", # 👈 the 'model_name' in config+ "messages": [+ {+ "role": "user",+ "content": "what llm are you"+ }+ ],+ }'```</TabItem></Tabs>-### SSO Login (AWS Profile)-- Set `AWS_PROFILE` environment variable-- Make bedrock completion call+++## Provisioned throughput models+To use provisioned throughput Bedrock models pass+- `model=bedrock/<base-model>`, example `model=bedrock/anthropic.claude-v2`. Set `model` to any of the [Supported AWS models](#supported-aws-bedrock-models)+- `model_id=provisioned-model-arn`++Completion```python-import os-from litellm import completion+import litellm+response = litellm.completion(+ model="bedrock/anthropic.claude-instant-v1",+ model_id="provisioned-model-arn",+ messages=[{"content": "Hello, how are you?", "role": "user"}]+)+```-response = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=[{ "content": "Hello, how are you?","role": "user"}]+Embedding+```python+import litellm+response = litellm.embedding(+ model="bedrock/amazon.titan-embed-text-v1",+ model_id="provisioned-model-arn",+ input=["hi"],)```-or pass `aws_profile_name`:+## Supported AWS Bedrock Models+Here's an example of using a bedrock model with LiteLLM. For a complete list, refer to the [model cost map](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json)++| Model Name | Command |+|----------------------------|------------------------------------------------------------------|+| Anthropic Claude-V3.5 Sonnet | `completion(model='bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Anthropic Claude-V3 sonnet | `completion(model='bedrock/anthropic.claude-3-sonnet-20240229-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Anthropic Claude-V3 Haiku | `completion(model='bedrock/anthropic.claude-3-haiku-20240307-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Anthropic Claude-V3 Opus | `completion(model='bedrock/anthropic.claude-3-opus-20240229-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Anthropic Claude-V2.1 | `completion(model='bedrock/anthropic.claude-v2:1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Anthropic Claude-V2 | `completion(model='bedrock/anthropic.claude-v2', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Anthropic Claude-Instant V1 | `completion(model='bedrock/anthropic.claude-instant-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Meta llama3-1-405b | `completion(model='bedrock/meta.llama3-1-405b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Meta llama3-1-70b | `completion(model='bedrock/meta.llama3-1-70b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Meta llama3-1-8b | `completion(model='bedrock/meta.llama3-1-8b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Meta llama3-70b | `completion(model='bedrock/meta.llama3-70b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Meta llama3-8b | `completion(model='bedrock/meta.llama3-8b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |+| Amazon Titan Lite | `completion(model='bedrock/amazon.titan-text-lite-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| Amazon Titan Express | `completion(model='bedrock/amazon.titan-text-express-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| Cohere Command | `completion(model='bedrock/cohere.command-text-v14', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| AI21 J2-Mid | `completion(model='bedrock/ai21.j2-mid-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| AI21 J2-Ultra | `completion(model='bedrock/ai21.j2-ultra-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| AI21 Jamba-Instruct | `completion(model='bedrock/ai21.jamba-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| Meta Llama 2 Chat 13b | `completion(model='bedrock/meta.llama2-13b-chat-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| Meta Llama 2 Chat 70b | `completion(model='bedrock/meta.llama2-70b-chat-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| Mistral 7B Instruct | `completion(model='bedrock/mistral.mistral-7b-instruct-v0:2', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+| Mixtral 8x7B Instruct | `completion(model='bedrock/mistral.mixtral-8x7b-instruct-v0:1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |++## Bedrock Embedding++### API keys+This can be set as env variables or passed as **params to litellm.embedding()**```pythonimport os-from litellm import completion+os.environ["AWS_ACCESS_KEY_ID"] = "" # Access key+os.environ["AWS_SECRET_ACCESS_KEY"] = "" # Secret access key+os.environ["AWS_REGION_NAME"] = "" # us-east-1, us-east-2, us-west-1, us-west-2+```-response = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=[{ "content": "Hello, how are you?","role": "user"}],- aws_profile_name="dev-profile",+### Usage+```python+from litellm import embedding+response = embedding(+ model="bedrock/amazon.titan-embed-text-v1",+ input=["good morning from litellm"],)+print(response)```-### STS (Role-based Auth)+## Supported AWS Bedrock Embedding Models-- Set `aws_role_name` and `aws_session_name`+| Model Name | Usage | Supported Additional OpenAI params |+|----------------------|---------------------------------------------|-----|+| Titan Embeddings V2 | `embedding(model="bedrock/amazon.titan-embed-text-v2:0", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/amazon_titan_v2_transformation.py#L59) |+| Titan Embeddings - V1 | `embedding(model="bedrock/amazon.titan-embed-text-v1", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/amazon_titan_g1_transformation.py#L53)+| Titan Multimodal Embeddings | `embedding(model="bedrock/amazon.titan-embed-image-v1", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/amazon_titan_multimodal_transformation.py#L28) |+| Cohere Embeddings - English | `embedding(model="bedrock/cohere.embed-english-v3", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/cohere_transformation.py#L18)+| Cohere Embeddings - Multilingual | `embedding(model="bedrock/cohere.embed-multilingual-v3", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/cohere_transformation.py#L18)+### Advanced - [Drop Unsupported Params](https://docs.litellm.ai/docs/completion/drop_params#openai-proxy-usage)-| LiteLLM Parameter | Boto3 Parameter | Description | Boto3 Documentation |-|------------------|-----------------|-------------|-------------------|-| `aws_access_key_id` | `aws_access_key_id` | AWS access key associated with an IAM user or role | [Credentials](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html) |-| `aws_secret_access_key` | `aws_secret_access_key` | AWS secret key associated with the access key | [Credentials](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html) |-| `aws_role_name` | `RoleArn` | The Amazon Resource Name (ARN) of the role to assume | [AssumeRole API](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sts.html#STS.Client.assume_role) |-| `aws_session_name` | `RoleSessionName` | An identifier for the assumed role session | [AssumeRole API](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sts.html#STS.Client.assume_role) |+### Advanced - [Pass model/provider-specific Params](https://docs.litellm.ai/docs/completion/provider_specific_params#proxy-usage)+## Image Generation+Use this for stable diffusion, and amazon nova canvas on bedrock-Make the bedrock completion call+### Usage<Tabs><TabItem value="sdk" label="SDK">```python-from litellm import completion+import os+from litellm import image_generation-response = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=messages,- max_tokens=10,- temperature=0.1,- aws_role_name=aws_role_name,- aws_session_name="my-test-session",+os.environ["AWS_ACCESS_KEY_ID"] = ""+os.environ["AWS_SECRET_ACCESS_KEY"] = ""+os.environ["AWS_REGION_NAME"] = ""++response = image_generation(+ prompt="A cute baby sea otter",+ model="bedrock/stability.stable-diffusion-xl-v0",)+print(f"response: {response}")```-If you also need to dynamically set the aws user accessing the role, add the additional args in the completion()/embedding() function-+**Set optional params**```python-from litellm import completion+import os+from litellm import image_generation-response = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=messages,- max_tokens=10,- temperature=0.1,- aws_region_name=aws_region_name,- aws_access_key_id=aws_access_key_id,- aws_secret_access_key=aws_secret_access_key,- aws_role_name=aws_role_name,- aws_session_name="my-test-session",+os.environ["AWS_ACCESS_KEY_ID"] = ""+os.environ["AWS_SECRET_ACCESS_KEY"] = ""+os.environ["AWS_REGION_NAME"] = ""++response = image_generation(+ prompt="A cute baby sea otter",+ model="bedrock/stability.stable-diffusion-xl-v0",+ ### OPENAI-COMPATIBLE ###+ size="128x512", # width=128, height=512+ ### PROVIDER-SPECIFIC ### see `AmazonStabilityConfig` in bedrock.py for all params+ seed=30)+print(f"response: {response}")```</TabItem>-<TabItem value="proxy" label="PROXY">+1. Setup config.yaml+```yamlmodel_list:- - model_name: bedrock/*+ - model_name: amazon.nova-canvas-v1:0litellm_params:- model: bedrock/*- aws_role_name: arn:aws:iam::888602223428:role/iam_local_role # AWS RoleArn- aws_session_name: "bedrock-session" # AWS RoleSessionName- aws_access_key_id: os.environ/AWS_ACCESS_KEY_ID # [OPTIONAL - not required if using role]- aws_secret_access_key: os.environ/AWS_SECRET_ACCESS_KEY # [OPTIONAL - not required if using role]+ model: bedrock/amazon.nova-canvas-v1:0+ aws_region_name: "us-east-1"+ aws_secret_access_key: my-key # OPTIONAL - all boto3 auth params supported+ aws_secret_access_id: my-id # OPTIONAL - all boto3 auth params supported```+2. Start proxy-</TabItem>--</Tabs>---### Passing an external BedrockRuntime.Client as a parameter - Completion()--:::warning--This is a deprecated flow. Boto3 is not async. And boto3.client does not let us make the http call through httpx. Pass in your aws params through the method above 👆. [See Auth Code](https://github.com/BerriAI/litellm/blob/55a20c7cce99a93d36a82bf3ae90ba3baf9a7f89/litellm/llms/bedrock_httpx.py#L284) [Add new auth flow](https://github.com/BerriAI/litellm/issues)---Experimental - 2024-Jun-23:- `aws_access_key_id`, `aws_secret_access_key`, and `aws_session_token` will be extracted from boto3.client and be passed into the httpx client+```bash+litellm --config /path/to/config.yaml+```-:::+3. Test it!-Pass an external BedrockRuntime.Client object as a parameter to litellm.completion. Useful when using an AWS credentials profile, SSO session, assumed role session, or if environment variables are not available for auth.+```bash+curl -L -X POST 'http://0.0.0.0:4000/v1/images/generations' \+-H 'Content-Type: application/json' \+-H 'Authorization: Bearer $LITELLM_VIRTUAL_KEY' \+-d '{+ "model": "amazon.nova-canvas-v1:0",+ "prompt": "A cute baby sea otter"+}'+```-Create a client from session credentials:-```python-import boto3-from litellm import completion+</TabItem>+</Tabs>-bedrock = boto3.client(- service_name="bedrock-runtime",- region_name="us-east-1",- aws_access_key_id="",- aws_secret_access_key="",- aws_session_token="",-)+## Supported AWS Bedrock Image Generation Models-response = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=[{ "content": "Hello, how are you?","role": "user"}],- aws_bedrock_client=bedrock,-)-```+| Model Name | Function Call |+|----------------------|---------------------------------------------|+| Stable Diffusion 3 - v0 | `embedding(model="bedrock/stability.stability.sd3-large-v1:0", prompt=prompt)` |+| Stable Diffusion - v0 | `embedding(model="bedrock/stability.stable-diffusion-xl-v0", prompt=prompt)` |+| Stable Diffusion - v0 | `embedding(model="bedrock/stability.stable-diffusion-xl-v1", prompt=prompt)` |-Create a client from AWS profile in `~/.aws/config`:-```python-import boto3-from litellm import completion-dev_session = boto3.Session(profile_name="dev-profile")-bedrock = dev_session.client(- service_name="bedrock-runtime",- region_name="us-east-1",-)+## Rerank API-response = completion(- model="bedrock/anthropic.claude-instant-v1",- messages=[{ "content": "Hello, how are you?","role": "user"}],- aws_bedrock_client=bedrock,-)-```-## Calling via Internal Proxy+Use Bedrock's Rerank API in the Cohere `/rerank` format.-Use the `bedrock/converse_like/model` endpoint to call bedrock converse model via your internal proxy.+Supported Cohere Rerank Params+- `model` - the foundation model ARN+- `query` - the query to rerank against+- `documents` - the list of documents to rerank+- `top_n` - the number of results to return<Tabs>-<TabItem value="sdk" label="SDK">+<TabItem label="SDK" value="sdk">```python-from litellm import completion+from litellm import rerank+import os-response = completion(- model="bedrock/converse_like/some-model",- messages=[{"role": "user", "content": "What's AWS?"}],- api_key="sk-1234",- api_base="https://some-api-url/models",- extra_headers={"test": "hello world"},+os.environ["AWS_ACCESS_KEY_ID"] = ""+os.environ["AWS_SECRET_ACCESS_KEY"] = ""+os.environ["AWS_REGION_NAME"] = ""++response = rerank(+ model="bedrock/arn:aws:bedrock:us-west-2::foundation-model/amazon.rerank-v1:0", # provide the model ARN - get this here https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock/client/list_foundation_models.html+ query="hello",+ documents=["hello", "world"],+ top_n=2,)++print(response)```</TabItem>-<TabItem value="proxy" label="LiteLLM Proxy">+<TabItem label="PROXY" value="proxy">1. Setup config.yaml```yamlmodel_list:- - model_name: anthropic-claude+ - model_name: bedrock-reranklitellm_params:- model: bedrock/converse_like/some-model- api_base: https://some-api-url/models+ model: bedrock/arn:aws:bedrock:us-west-2::foundation-model/amazon.rerank-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: os.environ/AWS_REGION_NAME```2. Start proxy server@@ -1540,389 +1634,366 @@ litellm --config config.yaml3. Test it!```bash-curl -X POST 'http://0.0.0.0:4000/chat/completions' \--H 'Content-Type: application/json' \--H 'Authorization: Bearer sk-1234' \--d '{- "model": "anthropic-claude",- "messages": [- {- "role": "system",- "content": "You are a helpful math tutor. Guide the user through the solution step by step."- },- { "content": "Hello, how are you?", "role": "user" }- ]-}'+curl http://0.0.0.0:4000/rerank \+ -H "Authorization: Bearer sk-1234" \+ -H "Content-Type: application/json" \+ -d '{+ "model": "bedrock-rerank",+ "query": "What is the capital of the United States?",+ "documents": [+ "Carson City is the capital city of the American state of Nevada.",+ "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",+ "Washington, D.C. is the capital of the United States.",+ "Capital punishment has existed in the United States since before it was a country."+ ],+ "top_n": 3+++ }'```</TabItem></Tabs>-**Expected Output URL**--```bash-https://some-api-url/models-```-## Bedrock Imported Models (Deepseek, Deepseek R1)+## Bedrock Application Inference Profile-### Deepseek R1+Use Bedrock Application Inference Profile to track costs for projects on AWS.-This is a separate route, as the chat template is different.+You can either pass it in the model name - `model="bedrock/arn:...` or as a separate `model_id="arn:..` param.-| Property | Details |-|----------|---------|-| Provider Route | `bedrock/deepseek_r1/{model_arn}` |-| Provider Documentation | [Bedrock Imported Models](https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html), [Deepseek Bedrock Imported Model](https://aws.amazon.com/blogs/machine-learning/deploy-deepseek-r1-distilled-llama-models-with-amazon-bedrock-custom-model-import/) |+### Set via `model_id`<Tabs>-<TabItem value="sdk" label="SDK">+<TabItem label="SDK" value="sdk">```pythonfrom litellm import completion-import os+import os++os.environ["AWS_ACCESS_KEY_ID"] = ""+os.environ["AWS_SECRET_ACCESS_KEY"] = ""+os.environ["AWS_REGION_NAME"] = ""response = completion(- model="bedrock/deepseek_r1/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n", # bedrock/deepseek_r1/{your-model-arn}- messages=[{"role": "user", "content": "Tell me a joke"}],+ model="bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0",+ messages=[{"role": "user", "content": "Hello, how are you?"}],+ model_id="arn:aws:bedrock:eu-central-1:000000000000:application-inference-profile/a0a0a0a0a0a0",)++print(response)```</TabItem>+<TabItem label="PROXY" value="proxy">-<TabItem value="proxy" label="Proxy">---**1. Add to config**+1. Setup config.yaml```yamlmodel_list:- - model_name: DeepSeek-R1-Distill-Llama-70B- litellm_params:- model: bedrock/deepseek_r1/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n-+ - model_name: anthropic-claude-3-5-sonnet+ litellm_params:+ model: bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0+ # You have to set the ARN application inference profile in the model_id parameter+ model_id: arn:aws:bedrock:eu-central-1:000000000000:application-inference-profile/a0a0a0a0a0a0```-**2. Start proxy**+2. Start proxy```bashlitellm --config /path/to/config.yaml--# RUNNING at http://0.0.0.0:4000```-**3. Test it!**+3. Test it!```bash-curl --location 'http://0.0.0.0:4000/chat/completions' \- --header 'Authorization: Bearer sk-1234' \- --header 'Content-Type: application/json' \- --data '{- "model": "DeepSeek-R1-Distill-Llama-70B", # 👈 the 'model_name' in config- "messages": [- {- "role": "user",- "content": "what llm are you"- }- ],- }'+curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \+-H 'Content-Type: application/json' \+-H 'Authorization: Bearer $LITELLM_API_KEY' \+-d '{+ "model": "anthropic-claude-3-5-sonnet",+ "messages": [+ {+ "role": "user",+ "content": [+ {+ "type": "text",+ "text": "List 5 important events in the XIX century"+ }+ ]+ }+ ]+}'```</TabItem></Tabs>+## Boto3 - Authentication-### Deepseek (not R1)--| Property | Details |-|----------|---------|-| Provider Route | `bedrock/llama/{model_arn}` |-| Provider Documentation | [Bedrock Imported Models](https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html), [Deepseek Bedrock Imported Model](https://aws.amazon.com/blogs/machine-learning/deploy-deepseek-r1-distilled-llama-models-with-amazon-bedrock-custom-model-import/) |-+### Passing credentials as parameters - Completion()+Pass AWS credentials as parameters to litellm.completion+```python+import os+from litellm import completion+response = completion(+ model="bedrock/anthropic.claude-instant-v1",+ messages=[{ "content": "Hello, how are you?","role": "user"}],+ aws_access_key_id="",+ aws_secret_access_key="",+ aws_region_name="",+)+```-Use this route to call Bedrock Imported Models that follow the `llama` Invoke Request / Response spec+### Passing extra headers + Custom API Endpoints+This can be used to override existing headers (e.g. `Authorization`) when calling custom api endpoints<Tabs><TabItem value="sdk" label="SDK">```python-from litellm import completionimport os+import litellm+from litellm import completion++litellm.set_verbose = True # 👈 SEE RAW REQUESTresponse = completion(- model="bedrock/llama/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n", # bedrock/llama/{your-model-arn}- messages=[{"role": "user", "content": "Tell me a joke"}],+ model="bedrock/anthropic.claude-instant-v1",+ messages=[{ "content": "Hello, how are you?","role": "user"}],+ aws_access_key_id="",+ aws_secret_access_key="",+ aws_region_name="",+ aws_bedrock_runtime_endpoint="https://my-fake-endpoint.com",+ extra_headers={"key": "value"})```-</TabItem>+<TabItem value="proxy" label="PROXY">-<TabItem value="proxy" label="Proxy">---**1. Add to config**+1. Setup config.yaml```yamlmodel_list:- - model_name: DeepSeek-R1-Distill-Llama-70B+ - model_name: bedrock-modellitellm_params:- model: bedrock/llama/arn:aws:bedrock:us-east-1:086734376398:imported-model/r4c4kewx2s0n-+ model: bedrock/anthropic.claude-instant-v1+ aws_access_key_id: "",+ aws_secret_access_key: "",+ aws_region_name: "",+ aws_bedrock_runtime_endpoint: "https://my-fake-endpoint.com",+ extra_headers: {"key": "value"}```-**2. Start proxy**+2. Start proxy```bash-litellm --config /path/to/config.yaml--# RUNNING at http://0.0.0.0:4000+litellm --config /path/to/config.yaml --detailed_debug```-**3. Test it!**+3. Test it!```bash-curl --location 'http://0.0.0.0:4000/chat/completions' \- --header 'Authorization: Bearer sk-1234' \- --header 'Content-Type: application/json' \- --data '{- "model": "DeepSeek-R1-Distill-Llama-70B", # 👈 the 'model_name' in config- "messages": [- {- "role": "user",- "content": "what llm are you"- }- ],- }'-```--</TabItem>-</Tabs>----## Provisioned throughput models-To use provisioned throughput Bedrock models pass-- `model=bedrock/<base-model>`, example `model=bedrock/anthropic.claude-v2`. Set `model` to any of the [Supported AWS models](#supported-aws-bedrock-models)-- `model_id=provisioned-model-arn`--Completion-```python-import litellm-response = litellm.completion(- model="bedrock/anthropic.claude-instant-v1",- model_id="provisioned-model-arn",- messages=[{"content": "Hello, how are you?", "role": "user"}]-)-```--Embedding-```python-import litellm-response = litellm.embedding(- model="bedrock/amazon.titan-embed-text-v1",- model_id="provisioned-model-arn",- input=["hi"],-)-```---## Supported AWS Bedrock Models-Here's an example of using a bedrock model with LiteLLM. For a complete list, refer to the [model cost map](https://github.com/BerriAI/litellm/blob/main/model_prices_and_context_window.json)--| Model Name | Command |-|----------------------------|------------------------------------------------------------------|-| Anthropic Claude-V3.5 Sonnet | `completion(model='bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Anthropic Claude-V3 sonnet | `completion(model='bedrock/anthropic.claude-3-sonnet-20240229-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Anthropic Claude-V3 Haiku | `completion(model='bedrock/anthropic.claude-3-haiku-20240307-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Anthropic Claude-V3 Opus | `completion(model='bedrock/anthropic.claude-3-opus-20240229-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Anthropic Claude-V2.1 | `completion(model='bedrock/anthropic.claude-v2:1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Anthropic Claude-V2 | `completion(model='bedrock/anthropic.claude-v2', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Anthropic Claude-Instant V1 | `completion(model='bedrock/anthropic.claude-instant-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Meta llama3-1-405b | `completion(model='bedrock/meta.llama3-1-405b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Meta llama3-1-70b | `completion(model='bedrock/meta.llama3-1-70b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Meta llama3-1-8b | `completion(model='bedrock/meta.llama3-1-8b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Meta llama3-70b | `completion(model='bedrock/meta.llama3-70b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Meta llama3-8b | `completion(model='bedrock/meta.llama3-8b-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']` |-| Amazon Titan Lite | `completion(model='bedrock/amazon.titan-text-lite-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| Amazon Titan Express | `completion(model='bedrock/amazon.titan-text-express-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| Cohere Command | `completion(model='bedrock/cohere.command-text-v14', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| AI21 J2-Mid | `completion(model='bedrock/ai21.j2-mid-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| AI21 J2-Ultra | `completion(model='bedrock/ai21.j2-ultra-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| AI21 Jamba-Instruct | `completion(model='bedrock/ai21.jamba-instruct-v1:0', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| Meta Llama 2 Chat 13b | `completion(model='bedrock/meta.llama2-13b-chat-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| Meta Llama 2 Chat 70b | `completion(model='bedrock/meta.llama2-70b-chat-v1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| Mistral 7B Instruct | `completion(model='bedrock/mistral.mistral-7b-instruct-v0:2', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |-| Mixtral 8x7B Instruct | `completion(model='bedrock/mistral.mixtral-8x7b-instruct-v0:1', messages=messages)` | `os.environ['AWS_ACCESS_KEY_ID']`, `os.environ['AWS_SECRET_ACCESS_KEY']`, `os.environ['AWS_REGION_NAME']` |+curl -X POST 'http://0.0.0.0:4000/chat/completions' \+-H 'Content-Type: application/json' \+-H 'Authorization: Bearer sk-1234' \+-d '{+ "model": "bedrock-model",+ "messages": [+ {+ "role": "system",+ "content": "You are a helpful math tutor. Guide the user through the solution step by step."+ },+ {+ "role": "user",+ "content": "how can I solve 8x + 7 = -23"+ }+ ]+}'+```-## Bedrock Embedding+</TabItem>+</Tabs>-### API keys-This can be set as env variables or passed as **params to litellm.embedding()**+### SSO Login (AWS Profile)+- Set `AWS_PROFILE` environment variable+- Make bedrock completion call```pythonimport os-os.environ["AWS_ACCESS_KEY_ID"] = "" # Access key-os.environ["AWS_SECRET_ACCESS_KEY"] = "" # Secret access key-os.environ["AWS_REGION_NAME"] = "" # us-east-1, us-east-2, us-west-1, us-west-2+from litellm import completion++response = completion(+ model="bedrock/anthropic.claude-instant-v1",+ messages=[{ "content": "Hello, how are you?","role": "user"}]+)```-### Usage+or pass `aws_profile_name`:+```python-from litellm import embedding-response = embedding(- model="bedrock/amazon.titan-embed-text-v1",- input=["good morning from litellm"],+import os+from litellm import completion++response = completion(+ model="bedrock/anthropic.claude-instant-v1",+ messages=[{ "content": "Hello, how are you?","role": "user"}],+ aws_profile_name="dev-profile",)-print(response)```-## Supported AWS Bedrock Embedding Models+### STS (Role-based Auth)-| Model Name | Usage | Supported Additional OpenAI params |-|----------------------|---------------------------------------------|-----|-| Titan Embeddings V2 | `embedding(model="bedrock/amazon.titan-embed-text-v2:0", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/amazon_titan_v2_transformation.py#L59) |-| Titan Embeddings - V1 | `embedding(model="bedrock/amazon.titan-embed-text-v1", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/amazon_titan_g1_transformation.py#L53)-| Titan Multimodal Embeddings | `embedding(model="bedrock/amazon.titan-embed-image-v1", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/amazon_titan_multimodal_transformation.py#L28) |-| Cohere Embeddings - English | `embedding(model="bedrock/cohere.embed-english-v3", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/cohere_transformation.py#L18)-| Cohere Embeddings - Multilingual | `embedding(model="bedrock/cohere.embed-multilingual-v3", input=input)` | [here](https://github.com/BerriAI/litellm/blob/f5905e100068e7a4d61441d7453d7cf5609c2121/litellm/llms/bedrock/embed/cohere_transformation.py#L18)+- Set `aws_role_name` and `aws_session_name`-### Advanced - [Drop Unsupported Params](https://docs.litellm.ai/docs/completion/drop_params#openai-proxy-usage)-### Advanced - [Pass model/provider-specific Params](https://docs.litellm.ai/docs/completion/provider_specific_params#proxy-usage)+| LiteLLM Parameter | Boto3 Parameter | Description | Boto3 Documentation |+|------------------|-----------------|-------------|-------------------|+| `aws_access_key_id` | `aws_access_key_id` | AWS access key associated with an IAM user or role | [Credentials](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html) |+| `aws_secret_access_key` | `aws_secret_access_key` | AWS secret key associated with the access key | [Credentials](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html) |+| `aws_role_name` | `RoleArn` | The Amazon Resource Name (ARN) of the role to assume | [AssumeRole API](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sts.html#STS.Client.assume_role) |+| `aws_session_name` | `RoleSessionName` | An identifier for the assumed role session | [AssumeRole API](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sts.html#STS.Client.assume_role) |-## Image Generation-Use this for stable diffusion, and amazon nova canvas on bedrock-### Usage+Make the bedrock completion call<Tabs><TabItem value="sdk" label="SDK">```python-import os-from litellm import image_generation--os.environ["AWS_ACCESS_KEY_ID"] = ""-os.environ["AWS_SECRET_ACCESS_KEY"] = ""-os.environ["AWS_REGION_NAME"] = ""+from litellm import completion-response = image_generation(- prompt="A cute baby sea otter",- model="bedrock/stability.stable-diffusion-xl-v0",+response = completion(+ model="bedrock/anthropic.claude-instant-v1",+ messages=messages,+ max_tokens=10,+ temperature=0.1,+ aws_role_name=aws_role_name,+ aws_session_name="my-test-session",)-print(f"response: {response}")```-**Set optional params**-```python-import os-from litellm import image_generation+If you also need to dynamically set the aws user accessing the role, add the additional args in the completion()/embedding() function-os.environ["AWS_ACCESS_KEY_ID"] = ""-os.environ["AWS_SECRET_ACCESS_KEY"] = ""-os.environ["AWS_REGION_NAME"] = ""+```python+from litellm import completion-response = image_generation(- prompt="A cute baby sea otter",- model="bedrock/stability.stable-diffusion-xl-v0",- ### OPENAI-COMPATIBLE ###- size="128x512", # width=128, height=512- ### PROVIDER-SPECIFIC ### see `AmazonStabilityConfig` in bedrock.py for all params- seed=30+response = completion(+ model="bedrock/anthropic.claude-instant-v1",+ messages=messages,+ max_tokens=10,+ temperature=0.1,+ aws_region_name=aws_region_name,+ aws_access_key_id=aws_access_key_id,+ aws_secret_access_key=aws_secret_access_key,+ aws_role_name=aws_role_name,+ aws_session_name="my-test-session",)-print(f"response: {response}")```</TabItem>-<TabItem value="proxy" label="PROXY">-1. Setup config.yaml+<TabItem value="proxy" label="PROXY">```yamlmodel_list:- - model_name: amazon.nova-canvas-v1:0+ - model_name: bedrock/*litellm_params:- model: bedrock/amazon.nova-canvas-v1:0- aws_region_name: "us-east-1"- aws_secret_access_key: my-key # OPTIONAL - all boto3 auth params supported- aws_secret_access_id: my-id # OPTIONAL - all boto3 auth params supported+ model: bedrock/*+ aws_role_name: arn:aws:iam::888602223428:role/iam_local_role # AWS RoleArn+ aws_session_name: "bedrock-session" # AWS RoleSessionName+ aws_access_key_id: os.environ/AWS_ACCESS_KEY_ID # [OPTIONAL - not required if using role]+ aws_secret_access_key: os.environ/AWS_SECRET_ACCESS_KEY # [OPTIONAL - not required if using role]```-2. Start proxy-```bash-litellm --config /path/to/config.yaml-```+</TabItem>-3. Test it!+</Tabs>-```bash-curl -L -X POST 'http://0.0.0.0:4000/v1/images/generations' \--H 'Content-Type: application/json' \--H 'Authorization: Bearer $LITELLM_VIRTUAL_KEY' \--d '{- "model": "amazon.nova-canvas-v1:0",- "prompt": "A cute baby sea otter"-}'-```-</TabItem>-</Tabs>+### Passing an external BedrockRuntime.Client as a parameter - Completion()-## Supported AWS Bedrock Image Generation Models+:::warning-| Model Name | Function Call |-|----------------------|---------------------------------------------|-| Stable Diffusion 3 - v0 | `embedding(model="bedrock/stability.stability.sd3-large-v1:0", prompt=prompt)` |-| Stable Diffusion - v0 | `embedding(model="bedrock/stability.stable-diffusion-xl-v0", prompt=prompt)` |-| Stable Diffusion - v0 | `embedding(model="bedrock/stability.stable-diffusion-xl-v1", prompt=prompt)` |+This is a deprecated flow. Boto3 is not async. And boto3.client does not let us make the http call through httpx. Pass in your aws params through the method above 👆. [See Auth Code](https://github.com/BerriAI/litellm/blob/55a20c7cce99a93d36a82bf3ae90ba3baf9a7f89/litellm/llms/bedrock_httpx.py#L284) [Add new auth flow](https://github.com/BerriAI/litellm/issues)-## Rerank API+Experimental - 2024-Jun-23:+ `aws_access_key_id`, `aws_secret_access_key`, and `aws_session_token` will be extracted from boto3.client and be passed into the httpx client-Use Bedrock's Rerank API in the Cohere `/rerank` format.+:::-Supported Cohere Rerank Params-- `model` - the foundation model ARN-- `query` - the query to rerank against-- `documents` - the list of documents to rerank-- `top_n` - the number of results to return+Pass an external BedrockRuntime.Client object as a parameter to litellm.completion. Useful when using an AWS credentials profile, SSO session, assumed role session, or if environment variables are not available for auth.-<Tabs>-<TabItem label="SDK" value="sdk">+Create a client from session credentials:+```python+import boto3+from litellm import completion++bedrock = boto3.client(+ service_name="bedrock-runtime",+ region_name="us-east-1",+ aws_access_key_id="",+ aws_secret_access_key="",+ aws_session_token="",+)++response = completion(+ model="bedrock/anthropic.claude-instant-v1",+ messages=[{ "content": "Hello, how are you?","role": "user"}],+ aws_bedrock_client=bedrock,+)+```+Create a client from AWS profile in `~/.aws/config`:```python-from litellm import rerank-import os+import boto3+from litellm import completion-os.environ["AWS_ACCESS_KEY_ID"] = ""-os.environ["AWS_SECRET_ACCESS_KEY"] = ""-os.environ["AWS_REGION_NAME"] = ""+dev_session = boto3.Session(profile_name="dev-profile")+bedrock = dev_session.client(+ service_name="bedrock-runtime",+ region_name="us-east-1",+)-response = rerank(- model="bedrock/arn:aws:bedrock:us-west-2::foundation-model/amazon.rerank-v1:0", # provide the model ARN - get this here https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock/client/list_foundation_models.html- query="hello",- documents=["hello", "world"],- top_n=2,+response = completion(+ model="bedrock/anthropic.claude-instant-v1",+ messages=[{ "content": "Hello, how are you?","role": "user"}],+ aws_bedrock_client=bedrock,)+```+## Calling via Internal Proxy (not bedrock url compatible)-print(response)+Use the `bedrock/converse_like/model` endpoint to call bedrock converse model via your internal proxy.++<Tabs>+<TabItem value="sdk" label="SDK">++```python+from litellm import completion++response = completion(+ model="bedrock/converse_like/some-model",+ messages=[{"role": "user", "content": "What's AWS?"}],+ api_key="sk-1234",+ api_base="https://some-api-url/models",+ extra_headers={"test": "hello world"},+)```</TabItem>-<TabItem label="PROXY" value="proxy">+<TabItem value="proxy" label="LiteLLM Proxy">1. Setup config.yaml```yamlmodel_list:- - model_name: bedrock-rerank+ - model_name: anthropic-claudelitellm_params:- model: bedrock/arn:aws:bedrock:us-west-2::foundation-model/amazon.rerank-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: os.environ/AWS_REGION_NAME+ model: bedrock/converse_like/some-model+ api_base: https://some-api-url/models```2. Start proxy server@@ -1936,25 +2007,26 @@ litellm --config config.yaml3. Test it!```bash-curl http://0.0.0.0:4000/rerank \- -H "Authorization: Bearer sk-1234" \- -H "Content-Type: application/json" \- -d '{- "model": "bedrock-rerank",- "query": "What is the capital of the United States?",- "documents": [- "Carson City is the capital city of the American state of Nevada.",- "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",- "Washington, D.C. is the capital of the United States.",- "Capital punishment has existed in the United States since before it was a country."- ],- "top_n": 3--- }'+curl -X POST 'http://0.0.0.0:4000/chat/completions' \+-H 'Content-Type: application/json' \+-H 'Authorization: Bearer sk-1234' \+-d '{+ "model": "anthropic-claude",+ "messages": [+ {+ "role": "system",+ "content": "You are a helpful math tutor. Guide the user through the solution step by step."+ },+ { "content": "Hello, how are you?", "role": "user" }+ ]+}'```</TabItem></Tabs>+**Expected Output URL**+```bash+https://some-api-url/models+```diff --git a/litellm/llms/bedrock/base_aws_llm.py b/litellm/llms/bedrock/base_aws_llm.pyindex 86b47675d4b..5482d80687e 100644--- a/litellm/llms/bedrock/base_aws_llm.py+++ b/litellm/llms/bedrock/base_aws_llm.py@@ -279,16 +279,30 @@ class BaseAWSLLM:return Nonedef _get_aws_region_name(- self, optional_params: dict, model: Optional[str] = None+ self,+ optional_params: dict,+ model: Optional[str] = None,+ model_id: Optional[str] = None,) -> str:"""- Get the AWS region name from the environment variables+ Get the AWS region name from the environment variables.++ Parameters:+ optional_params (dict): Optional parameters for the model call+ model (str): The model name+ model_id (str): The model ID. This is the ARN of the model, if passed in as a separate param.++ Returns:+ str: The AWS region name"""aws_region_name = optional_params.get("aws_region_name", None)### SET REGION NAME ###if aws_region_name is None:# check model arn #- aws_region_name = self._get_aws_region_from_model_arn(model)+ if model_id is not None:+ aws_region_name = self._get_aws_region_from_model_arn(model_id)+ else:+ aws_region_name = self._get_aws_region_from_model_arn(model)# check env #litellm_aws_region_name = get_secret("AWS_REGION_NAME", None)diff --git a/litellm/llms/bedrock/chat/converse_handler.py b/litellm/llms/bedrock/chat/converse_handler.pyindex d45ab40c4bd..c4c518cca53 100644--- a/litellm/llms/bedrock/chat/converse_handler.py+++ b/litellm/llms/bedrock/chat/converse_handler.py@@ -268,23 +268,29 @@ class BedrockConverseLLM(BaseAWSLLM):## SETUP ##stream = optional_params.pop("stream", None)- modelId = optional_params.pop("model_id", None)+ unencoded_model_id = optional_params.pop("model_id", None)fake_stream = optional_params.pop("fake_stream", False)json_mode = optional_params.get("json_mode", False)- if modelId is not None:- modelId = self.encode_model_id(model_id=modelId)+ if unencoded_model_id is not None:+ modelId = self.encode_model_id(model_id=unencoded_model_id)else:modelId = self.encode_model_id(model_id=model)if stream is True and "ai21" in modelId:fake_stream = True+ ### SET REGION NAME ###+ aws_region_name = self._get_aws_region_name(+ optional_params=optional_params,+ model=model,+ model_id=unencoded_model_id,+ )+## CREDENTIALS ### pop aws_secret_access_key, aws_access_key_id, aws_region_name from kwargs, since completion calls fail with themaws_secret_access_key = optional_params.pop("aws_secret_access_key", None)aws_access_key_id = optional_params.pop("aws_access_key_id", None)aws_session_token = optional_params.pop("aws_session_token", None)- aws_region_name = optional_params.pop("aws_region_name", None)aws_role_name = optional_params.pop("aws_role_name", None)aws_session_name = optional_params.pop("aws_session_name", None)aws_profile_name = optional_params.pop("aws_profile_name", None)@@ -293,25 +299,25 @@ class BedrockConverseLLM(BaseAWSLLM):) # https://bedrock-runtime.{region_name}.amazonaws.comaws_web_identity_token = optional_params.pop("aws_web_identity_token", None)aws_sts_endpoint = optional_params.pop("aws_sts_endpoint", None)+ optional_params.pop("aws_region_name", None)- ### SET REGION NAME ###- if aws_region_name is None:- # check env #- litellm_aws_region_name = get_secret("AWS_REGION_NAME", None)-- if litellm_aws_region_name is not None and isinstance(- litellm_aws_region_name, str- ):- aws_region_name = litellm_aws_region_name-- standard_aws_region_name = get_secret("AWS_REGION", None)- if standard_aws_region_name is not None and isinstance(- standard_aws_region_name, str- ):- aws_region_name = standard_aws_region_name-- if aws_region_name is None:- aws_region_name = "us-west-2"+ # if aws_region_name is None:+ # # check env #+ # litellm_aws_region_name = get_secret("AWS_REGION_NAME", None)++ # if litellm_aws_region_name is not None and isinstance(+ # litellm_aws_region_name, str+ # ):+ # aws_region_name = litellm_aws_region_name++ # standard_aws_region_name = get_secret("AWS_REGION", None)+ # if standard_aws_region_name is not None and isinstance(+ # standard_aws_region_name, str+ # ):+ # aws_region_name = standard_aws_region_name++ # if aws_region_name is None:+ # aws_region_name = "us-west-2"litellm_params["aws_region_name"] = (aws_region_name # [DO NOT DELETE] important for async callsdiff --git a/tests/llm_translation/test_bedrock_completion.py b/tests/llm_translation/test_bedrock_completion.pyindex 602992aee84..be6d31d511b 100644--- a/tests/llm_translation/test_bedrock_completion.py+++ b/tests/llm_translation/test_bedrock_completion.py@@ -2948,3 +2948,28 @@ async def test_bedrock_stream_thinking_content_openwebui():assert (len(response_content) > 0), "There should be non-empty content after thinking tags"+++def test_bedrock_application_inference_profile():+ from litellm.llms.custom_httpx.http_handler import HTTPHandler, AsyncHTTPHandler++ client = HTTPHandler()++ with patch.object(client, "post") as mock_post:+ try:+ resp = completion(+ model="bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0",+ messages=[{"role": "user", "content": "Hello, how are you?"}],+ model_id="arn:aws:bedrock:eu-central-1:000000000000:application-inference-profile/a0a0a0a0a0a0",+ client=client,+ )+ except Exception as e:+ print(e)++ mock_post.assert_called_once()++ print(mock_post.call_args.kwargs)+ json_data = mock_post.call_args.kwargs["data"]+ assert mock_post.call_args.kwargs["url"].startswith(+ "https://bedrock-runtime.eu-central-1.amazonaws.com/"+ )