Skip to content

[Bug]: Litellm does not work with AWS Bedrock Application Inference profiles #8911

Description

@mirodrr2

What happened?

To reproduce:

  1. Create application inference profile:
aws bedrock create-inference-profile \
  --inference-profile-name "Claude37" \      
  --description "Application profile for Claude 3.7 Sonnet" \
  --model-source copyFrom=arn:aws:bedrock:us-east-1:<Your-Account-Id>:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0 \
  --tags key=projectId,value=ai-gateway
{
    "inferenceProfileArn": "<Your application inference profile arn>",
    "status": "ACTIVE"
}
  1. Configure the inference profile arn as a model in your config.yaml. This matches the same way you would use it with the boto3 client
- model_name: anthropic.claude-3-7-sonnet-20250219-v1:0-profile
    litellm_params:
      model: bedrock/converse/<Your application inference profile arn>
  1. Call the model_name linked to your application inference profile
curl -i "$GATEWAY_URL/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GATEWAY_API_KEY" \
-d '{
    "model": "anthropic.claude-3-7-sonnet-20250219-v1:0-profile",
    "messages": [
        {
            "role": "user",
            "content": "tell me a one sentence story"
        }
    ]
}'

HTTP/2 200 
date: Sat, 01 Mar 2025 02:55:22 GMT
content-type: application/json
content-length: 1106
server: uvicorn
server: uvicorn
x-litellm-version: 1.61.20
x-litellm-response-cost: 0
x-litellm-key-spend: 0.0
x-litellm-timeout: 6000

{"error": {"message": "litellm.APIConnectionError: 'output'\nTraceback (most recent call last):\n  File \"/usr/lib/python3.13/site-packages/litellm/main.py\", line 470, in acompletion\n    response = await init_response\n               ^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3.13/site-packages/litellm/llms/bedrock/chat/converse_handler.py\", line 243, in async_completion\n    return litellm.AmazonConverseConfig()._transform_response(\n           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^\n        model=model,\n        ^^^^^^^^^^^^\n    ...<8 lines>...\n        encoding=encoding,\n        ^^^^^^^^^^^^^^^^^^\n    )\n    ^\n  File \"/usr/lib/python3.13/site-packages/litellm/llms/bedrock/chat/converse_transformation.py\", line 656, in _transform_response\n    message: Optional[MessageBlock] = completion_response[\"output\"][\"message\"]\n                                      ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^\nKeyError: 'output'\n. Received Model Group=anthropic.claude-3-7-sonnet-20250219-v1:0-profile\nAvailable Model Group Fallbacks=None", "type": null, "param": null, "code": "500"}}%     

This same request, but using the boto3 client against bedrock works just fine:

Example script that runs fine:

import boto3
import os
from botocore.client import Config
from botocore import UNSIGNED
from typing import Generator, Dict, Any, Optional


def create_bedrock_client():
    
    region = os.getenv("AWS_REGION")

    if not all([region]):
        raise ValueError(
            "Missing required environment variables: AWS_REGION"
        )
    
    session = boto3.Session()
    client = session.client(
        "bedrock-runtime",
        region_name=region,
    )
    return client

bedrock_client = create_bedrock_client()
messages = [{"role": "user", "content": [{"text": "Create a list of 3 pop songs."}]}]
model_id = "arn:aws:bedrock:us-east-1:235614385815:application-inference-profile/cmop7wjzk1jk"
response = bedrock_client.converse(modelId=model_id, messages=messages)
print(response)

Output:

{'ResponseMetadata': {'RequestId': 'e684f90b-a4af-4d5c-805c-590160849f4a', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 28 Feb 2025 20:14:11 GMT', 'content-type': 'application/json', 'content-length': '435', 'connection': 'keep-alive', 'x-amzn-requestid': 'e684f90b-a4af-4d5c-805c-590160849f4a'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': '# 3 Popular Songs\n\n1. "Billie Jean" by Michael Jackson\n2. "Shape of You" by Ed Sheeran\n3. "Uptown Funk" by Mark Ronson ft. Bruno Mars'}]}}, 'stopReason': 'end_turn', 'usage': {'inputTokens': 17, 'outputTokens': 54, 'totalTokens': 71}, 'metrics': {'latencyMs': 6475}}

Relevant log output

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.61.20.rc

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions