Request and Response - Amazon Bedrock (original) (raw)

The request body is passed in the body field of a request to InvokeModel orInvokeModelWithResponseStream.

Note

Restrictions apply to the following operations: InvokeModel, InvokeModelWithResponseStream, Converse, and ConverseStream. See API restrictions for details.

Warning

Claude Sonnet 4.5 and Claude Haiku 4.5 support specifying either the temperature or top_p parameter, but not both. This does not apply to any older models.

Request

Anthropic Claude has the following inference parameters for a messages inference call.

{
    "anthropic_version": "bedrock-2023-05-31", 
    "anthropic_beta": ["computer-use-2024-10-22"] 
    "max_tokens": int,
    "system": string | [{"type": "text", "text": string}],    
    "messages": [
        {
            "role": string,
            "content": [
                { "type": "image", "source": { "type": "base64", "media_type": "image/jpeg", "data": "content image bytes" } },
                { "type": "text", "text": "content text" }
      ]
        }
    ],
    "temperature": float,
    "top_p": float,
    "top_k": int,
    "tools": [
        {
                "type": "custom",
                "name": string,
                "description": string,
                "input_schema": json
            
        },
        { 
            "type": "computer_20241022",  
            "name": "computer", 
            "display_height_px": int,
            "display_width_px": int,
            "display_number": 0 int
        },
        { 
            "type": "bash_20241022", 
            "name": "bash"
        },
        { 
            "type": "text_editor_20241022",
            "name": "str_replace_editor"
        }
        
    ],
    "tool_choice": {
        "type" :  string,
        "name" : string,
    },

 
    "stop_sequences": [string]
}              

The following are required parameters.

The following are optional parameters.

Note

You can use system prompts with Anthropic Claude version 2.1 or higher.

Note

The 1 million token context length variant of Claude Sonnet 4 is available to you in select AWS Regions as a "Beta Service" as defined in the AWS Service Terms. It is subject to your Agreement with AWS and the AWS Service Terms, and the applicable model EULA. Please see the Amazon Bedrock Pricing page for more information about the pricing for longer context requests. For requests exceeding 200K input tokens, the long context rate applies to the entire request, not just the tokens above the threshold. Separate service quotas apply (for more information, see Service Quotas in the AWS Management Console).
Available beta headers include the following:

Beta feature Beta header Notes
Computer use computer-use-2025-01-24 Compatible with Claude 3.7 Sonnet.
Tool use token-efficient-tools-2025-02-19 Compatible with Claude 3.7 Sonnet and Claude 4+.
Interleaved thinking Interleaved-thinking-2025-05-14 Compatible with Claude 4+ models.
Enables output tokens up to 128K output-128k-2025-02-19 Compatible with Claude 3.7 Sonnet.
Developer mode for raw thinking on Claude 4+ models dev-full-thinking-2025-05-14 Compatible with Claude 4+ models only. Contact your account team to access this beta.
1 million tokens context-1m-2025-08-07 Compatible with Claude Sonnet 4, Claude Sonnet 4.6, and Claude Opus 4.6.
Context management context-management-2025-06-27 Compatible with Claude Sonnet 4.5 and Claude Haiku 4.5
Effort effort-2025-11-24 Compatible with Claude Opus 4.5
Tool search tool tool-search-tool-2025-10-19 Compatible with Claude Opus 4.5
Tool use examples tool-examples-2025-10-29 Compatible with Claude Opus 4.5
Note

Requires an Anthropic Claude 3 model.
If you include tools in your request, the model may return tool_use content blocks that represent the model's use of those tools. You can then run those tools using the tool input generated by the model and then optionally return results back to the model using tool_result content blocks.
You can pass the following tool types:

Custom

Definition for a custom tool.

Computer

Definition for the computer tool that you use with the computer use API.

bash

Definition for the bash tool that you use with the computer use API.

text editor

Definition for the text editor tool that you use with the computer use API.

Note

Requires an Anthropic Claude 3 model.

Response

The Anthropic Claude model returns the following fields for a messages inference call.

{
    "id": string,
    "model": string,
    "type" : "message",
    "role" : "assistant",
    "content": [
        {
            "type": string,
            "text": string,
            "image" :json,
            "id": string,
            "name":string,
            "input": json
        }
    ],
    "stop_reason": string,
    "stop_sequence": string,
    "usage": {
        "input_tokens": integer,
        "output_tokens": integer
    }
    
}

Example responses with new stop_reason values:

// Example with refusal
{
    "stop_reason": "refusal",
    "stop_details": {
        "type": "refusal",
        "category": "cyber",
        "explanation": "This request triggered restrictions on violative cyber content and was blocked under Anthropic's Usage Policy."
    },
    "content": [],
    "usage": {
        "input_tokens": 106,
        "output_tokens": 1
    }
}

// Example with tool_use
{
    "stop_reason": "tool_use",
    "content": [
        {
            "type": "tool_use",
            "id": "toolu_123",
            "name": "calculator",
            "input": {"expression": "2+2"}
        }
    ]
}

// Example with model_context_window_exceeded (Claude Sonnet 4.5)
{
    "stop_reason": "model_context_window_exceeded",
    "content": [
        {
            "type": "text",
            "text": "The response was truncated due to context window limits..."
        }
    ]
}
Note

Branch on stop_reason, not on stop_details. The stop_details field is informational and can be null even when stop_reason is "refusal". Refusals can also occur mid-stream: the classifier may fire after some content has already been streamed. In streaming mode, the refusal arrives as the final message_delta event with stop_reason: "refusal"; any content blocks streamed before the refusal are valid partial output.

Effort parameter (beta)

The effort parameter is an alternative to thinking token budgets for Claude Opus 4.5. This parameter tells Claude how liberally it should spend tokens to produce the best result, adjusting token usage across thinking, tool calls, and user communication. It can be used with or without extended thinking mode.

The effort parameter can be set to:

To use this feature you must pass the beta header effort-2025-11-24.

Request example:

{
    "anthropic_version": "bedrock-2023-05-31",
    "anthropic_beta": [
        "effort-2025-11-24"
    ],
    "max_tokens": 4096,
    "output_config": {
        "effort": "medium"
    },
    "messages": [{
        "role": "user",
        "content": "Analyze this complex dataset and provide insights"
    }]
}