AWS Bedrock
Since Camel 4.5
Only producer is supported
The AWS2 Bedrock component supports invoking a supported LLM model from AWS Bedrock service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Bedrock. More information is available at Amazon Bedrock.
URI Format
aws-bedrock://label[?options]
You can append query options to the URI in the following format:
?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS Bedrock component supports 29 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Component configuration. | BedrockConfiguration | ||
The identifier (ID or ARN) for the guardrail to apply to the model invocation. | String | ||
Whether to return trace information from the guardrail. | false | boolean | |
The version of the guardrail to use. Defaults to DRAFT. | DRAFT | String | |
Whether to include streaming metadata in the response headers (completion reason, token count, chunk count). | true | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Required Define the model Id we are going to use. Enum values:
| String | ||
Required The operation to perform. Enum values:
| BedrockOperations | ||
Set the need for overriding the endpoint. This option needs to be used in combination with the uriEndpointOverride option. | false | boolean | |
If we want to use a POJO request as body or not. | false | boolean | |
If using a profile credentials provider, this parameter will set the profile name. | false | String | |
The region in which Bedrock client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example, ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). Enum values:
| String | ||
The streaming output mode (complete or chunks). In complete mode, the full response is accumulated and returned as a single message. In chunks mode, each chunk is emitted as a separate exchange. Enum values:
| complete | String | |
Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | ||
Set whether the Bedrock client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean | |
Set whether the Bedrock client should expect to load credentials through a profile credentials provider. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Autowired To use an existing configured AWS Bedrock Runtime Async client for streaming operations. | BedrockRuntimeAsyncClient | ||
Autowired To use an existing configured AWS Bedrock Runtime client. | BedrockRuntimeClient | ||
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
To define a proxy host when instantiating the Bedrock client. | String | ||
To define a proxy port when instantiating the Bedrock client. | Integer | ||
To define a proxy protocol when instantiating the Bedrock client. Enum values:
| HTTPS | Protocol | |
Amazon AWS Access Key. | String | ||
Amazon AWS Secret Key. | String | ||
Amazon AWS Session Token used when the user needs to assume an IAM role. | String | ||
If we want to trust all certificates in case of overriding the endpoint. | false | boolean | |
Set whether the Bedrock client should expect to use Session Credentials. This is useful in a situation in which the user needs to assume an IAM role for doing operations in Bedrock. | false | boolean |
Endpoint Options
The AWS Bedrock endpoint is configured using URI syntax:
aws-bedrock:label
With the following path and query parameters:
Query Parameters (25 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
The identifier (ID or ARN) for the guardrail to apply to the model invocation. | String | ||
Whether to return trace information from the guardrail. | false | boolean | |
The version of the guardrail to use. Defaults to DRAFT. | DRAFT | String | |
Whether to include streaming metadata in the response headers (completion reason, token count, chunk count). | true | boolean | |
Required Define the model Id we are going to use. Enum values:
| String | ||
Required The operation to perform. Enum values:
| BedrockOperations | ||
Set the need for overriding the endpoint. This option needs to be used in combination with the uriEndpointOverride option. | false | boolean | |
If we want to use a POJO request as body or not. | false | boolean | |
If using a profile credentials provider, this parameter will set the profile name. | false | String | |
The region in which Bedrock client needs to work. When using this parameter, the configuration will expect the lowercase name of the region (for example, ap-east-1) You’ll need to use the name Region.EU_WEST_1.id(). Enum values:
| String | ||
The streaming output mode (complete or chunks). In complete mode, the full response is accumulated and returned as a single message. In chunks mode, each chunk is emitted as a separate exchange. Enum values:
| complete | String | |
Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option. | String | ||
Set whether the Bedrock client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in. | false | boolean | |
Set whether the Bedrock client should expect to load credentials through a profile credentials provider. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired To use an existing configured AWS Bedrock Runtime Async client for streaming operations. | BedrockRuntimeAsyncClient | ||
Autowired To use an existing configured AWS Bedrock Runtime client. | BedrockRuntimeClient | ||
To define a proxy host when instantiating the Bedrock client. | String | ||
To define a proxy port when instantiating the Bedrock client. | Integer | ||
To define a proxy protocol when instantiating the Bedrock client. Enum values:
| HTTPS | Protocol | |
Amazon AWS Access Key. | String | ||
Amazon AWS Secret Key. | String | ||
Amazon AWS Session Token used when the user needs to assume an IAM role. | String | ||
If we want to trust all certificates in case of overriding the endpoint. | false | boolean | |
Set whether the Bedrock client should expect to use Session Credentials. This is useful in a situation in which the user needs to assume an IAM role for doing operations in Bedrock. | false | boolean |
Message Headers
The AWS Bedrock component supports 23 message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsBedrockOperation (producer) Constant: | The operation we want to perform. | String | |
CamelAwsBedrockContentType (producer) Constant: | The model content type. | String | |
CamelAwsBedrockAcceptContentType (producer) Constant: | The model accept content type. | String | |
CamelAwsBedrockStreamOutputMode (producer) Constant: | The streaming output mode (complete or chunks). | String | |
CamelAwsBedrockCompletionReason (producer) Constant: | The completion reason for streaming response. | String | |
CamelAwsBedrockTokenCount (producer) Constant: | The number of tokens generated in streaming response. | Integer | |
CamelAwsBedrockChunkCount (producer) Constant: | The number of chunks received in streaming response. | Integer | |
CamelAwsBedrockConverseMessages (producer) Constant: | The conversation messages for Converse API. | List | |
CamelAwsBedrockConverseSystem (producer) Constant: | The system prompts for Converse API. | List | |
CamelAwsBedrockConverseInferenceConfig (producer) Constant: | The inference configuration for Converse API. | InferenceConfiguration | |
CamelAwsBedrockConverseToolConfig (producer) Constant: | The tool configuration for Converse API. | ToolConfiguration | |
CamelAwsBedrockConverseAdditionalFields (producer) Constant: | The additional model request fields for Converse API. | Document | |
CamelAwsBedrockConverseStopReason (producer) Constant: | The stop reason from Converse API response. | String | |
CamelAwsBedrockConverseUsage (producer) Constant: | The usage metrics from Converse API response. | TokenUsage | |
CamelAwsBedrockConverseOutputMessage (producer) Constant: | The output message from Converse API response. | Message | |
CamelAwsBedrockGuardrailConfig (producer) Constant: | The guardrail configuration to apply to the request. | GuardrailConfiguration | |
CamelAwsBedrockGuardrailIdentifier (producer) Constant: | The guardrail identifier to use for the ApplyGuardrail operation. | String | |
CamelAwsBedrockGuardrailContent (producer) Constant: | The content blocks for ApplyGuardrail operation. | List | |
CamelAwsBedrockGuardrailSource (producer) Constant: | The source type for ApplyGuardrail operation (INPUT or OUTPUT). | String | |
CamelAwsBedrockGuardrailOutput (producer) Constant: | The guardrail assessment output from the response. | GuardrailAssessment | |
CamelAwsBedrockGuardrailTrace (producer) Constant: | The trace information from guardrail evaluation. | GuardrailTrace | |
CamelAwsBedrockGuardrailAssessments (producer) Constant: | The guardrail assessments from ApplyGuardrail response. | List | |
CamelAwsBedrockGuardrailUsage (producer) Constant: | The guardrail usage metrics from ApplyGuardrail response. | GuardrailUsage |
Required Bedrock component options
You have to provide the bedrockRuntimeClient in the Registry or your accessKey and secretKey to access the Amazon Bedrock service.
Usage
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Bedrock Producer operations
Camel-AWS Bedrock component provides the following operation on the producer side:
-
invokeTextModel
-
invokeImageModel
-
invokeEmbeddingsModel
-
invokeTextModelStreaming
-
invokeImageModelStreaming
-
invokeEmbeddingsModelStreaming
-
converse
-
converseStream
-
applyGuardrail
The operation must match the model type. Text-generation models are used with invokeTextModel, image-generation models (for example amazon.titan-image-generator-v1, amazon.nova-canvas-v1:0, the stability.* models) with invokeImageModel, and embedding models (for example amazon.titan-embed-text-v1, cohere.embed-english-v3) with invokeEmbeddingsModel. Invoking invokeTextModel with an image, embedding, rerank or video/speech model fails fast with an IllegalArgumentException that names the model and points to the operation to use instead.
Streaming Support
The streaming operations (invokeTextModelStreaming, invokeImageModelStreaming, invokeEmbeddingsModelStreaming) enable real-time streaming of model responses, providing lower latency and better user experience for interactive applications.
Streaming Output Modes
Two streaming modes are supported:
Complete Mode (default): Accumulates all chunks and returns the complete response as a single message. This is the simplest mode and behaves similarly to non-streaming operations, but with lower time-to-first-token.
Chunks Mode: Emits each chunk as it arrives in a List. Useful for reactive streaming pipelines or when you need to process chunks individually.
Streaming Configuration Options
-
streamOutputMode: Set to "complete" (default) or "chunks" -
includeStreamingMetadata: Whether to include metadata headers (default: true)
Streaming Metadata Headers
When includeStreamingMetadata is true, the following headers are set:
-
CamelAwsBedrockCompletionReason: The reason the model stopped generating (e.g., "FINISH", "end_turn", "stop") -
CamelAwsBedrockTokenCount: The number of tokens generated (if provided by the model) -
CamelAwsBedrockChunkCount: The number of chunks received
Converse API Support
The Converse API provides a unified, model-agnostic interface for conversational AI interactions with AWS Bedrock models. It offers several advantages over the legacy InvokeModel API:
-
Unified Interface: Single API across all supported models (Claude, Llama, Mistral, etc.)
-
Multi-turn Conversations: Native support for conversation history with user/assistant roles
-
Tool Use & Function Calling: Built-in support for tools and function calling
-
System Prompts: First-class support for system-level instructions
-
Structured Responses: Consistent response format across all models
-
Streaming Support: Real-time streaming with the
converseStreamoperation
Converse Operations
Two operations are provided:
converse: Standard request-response conversation
aws-bedrock://label?operation=converse&modelId=anthropic.claude-3-sonnet-20240229-v1:0 converseStream: Streaming conversation with real-time chunk delivery
aws-bedrock://label?operation=converseStream&modelId=anthropic.claude-3-sonnet-20240229-v1:0 Converse Configuration Options
Converse API uses message headers for configuration:
-
CamelAwsBedrockConverseMessages(required): List of Message objects representing the conversation -
CamelAwsBedrockConverseSystem: List of SystemContentBlock for system-level instructions -
CamelAwsBedrockConverseInferenceConfig: InferenceConfiguration for temperature, maxTokens, etc. -
CamelAwsBedrockConverseToolConfig: ToolConfiguration for function calling support -
CamelAwsBedrockConverseAdditionalFields: Document for model-specific additional fields
For streaming operations, you can also use: - CamelAwsBedrockStreamOutputMode: Set to "complete" (default) or "chunks"
Converse Response Headers
When a conversation completes, the following headers are set:
-
CamelAwsBedrockConverseStopReason: Why the model stopped (e.g., "end_turn", "max_tokens") -
CamelAwsBedrockConverseUsage: TokenUsage object with input/output token counts -
CamelAwsBedrockConverseOutputMessage: The complete Message object from the model -
CamelAwsBedrockChunkCount: (streaming only) Number of chunks received
Supported Models for Converse API
The Converse API supports all modern foundation models on Bedrock:
-
Anthropic Claude 3 family (Haiku, Sonnet, Opus)
-
Anthropic Claude 3.5 family (Sonnet v2, Haiku)
-
Amazon Nova family (Micro, Lite, Pro)
-
Meta Llama 3.x models
-
Mistral AI models
-
Cohere Command R models
Legacy models (Claude 2.x, Claude Instant) are not supported by the Converse API. Use the invokeTextModel operation for those models. |
Guardrails Support
AWS Bedrock Guardrails enable you to implement safeguards for your generative AI applications based on your use cases and responsible AI policies. Guardrails can filter harmful content, block sensitive topics, remove personally identifiable information (PII), and enhance content safety and privacy in generative AI applications.
The Camel AWS Bedrock component provides comprehensive support for guardrails through:
-
Converse API Integration: Apply guardrails to conversational interactions
-
Streaming Support: Use guardrails with real-time streaming responses
-
Standalone Validation: Check content against guardrails without invoking a model
-
Flexible Configuration: Configure guardrails at endpoint level or per-message
Guardrails Configuration Options
Endpoint-level Configuration (applies to all requests):
-
guardrailIdentifier: The ID or ARN of the guardrail to apply -
guardrailVersion: The version of the guardrail (default: "DRAFT") -
guardrailTrace: Whether to return trace information (default: false)
Message-level Configuration (per-message override via headers):
-
CamelAwsBedrockGuardrailConfig: GuardrailConfiguration object for converse operations -
CamelAwsBedrockGuardrailIdentifier: Guardrail identifier String for the applyGuardrail operation (overrides the endpointguardrailIdentifier) -
CamelAwsBedrockGuardrailContent: Content blocks for applyGuardrail operation -
CamelAwsBedrockGuardrailSource: Source type - "INPUT" or "OUTPUT" for applyGuardrail
Guardrails Operations
converse with Guardrails: Apply guardrails to conversational model invocations
aws-bedrock://label?operation=converse&modelId=anthropic.claude-3-sonnet-20240229-v1:0
&guardrailIdentifier=abc123xyz&guardrailVersion=DRAFT&guardrailTrace=true converseStream with Guardrails: Apply guardrails to streaming conversations
aws-bedrock://label?operation=converseStream&modelId=anthropic.claude-3-sonnet-20240229-v1:0
&guardrailIdentifier=abc123xyz&guardrailVersion=DRAFT applyGuardrail: Standalone operation to validate content against a guardrail without invoking a model
aws-bedrock://label?operation=applyGuardrail&guardrailIdentifier=abc123xyz
&guardrailVersion=DRAFT Guardrails Response Headers
When using guardrails, the following headers may be set in the response:
-
CamelAwsBedrockGuardrailTrace: Trace information from guardrail evaluation (when trace is enabled) -
CamelAwsBedrockGuardrailOutput: Output content blocks from applyGuardrail -
CamelAwsBedrockGuardrailAssessments: Detailed assessments from applyGuardrail -
CamelAwsBedrockGuardrailUsage: Token usage for guardrail evaluation
Creating a Guardrail in AWS
Before using guardrails, you need to create and configure one in the AWS Bedrock console:
-
Navigate to AWS Bedrock Console → Guardrails
-
Click "Create guardrail"
-
Configure filters:
-
Content filters: Block harmful content (hate, violence, sexual, etc.)
-
Denied topics: Block specific topics you define
-
Word filters: Block or mask custom words/phrases
-
PII filters: Detect and redact personally identifiable information
-
-
Save and note your Guardrail ID (e.g.,
abc123xyz)
Sub-Pages
For more details on specific features, see:
-
Supported Models - Complete list of supported AWS Bedrock models with JSON request schemas
-
Examples - Producer examples for text, image, embeddings, streaming, conversation, and guardrails
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws-bedrock</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.