IBM watsonx.ai
Since Camel 4.18
Only producer is supported
The IBM watsonx.ai component allows you to interact with IBM watsonx.ai foundation models for text generation, chat, embeddings, reranking, content detection (PII/HAP), document processing, and other AI capabilities using the IBM watsonx.ai API.
This component is built on top of the IBM watsonx.ai Java SDK.
Prerequisites
You must have a valid IBM Cloud account with access to watsonx.ai services. More information is available at IBM watsonx.ai.
To use this component, you need:
-
An IBM Cloud account
-
Access to watsonx.ai services
-
An API key from IBM Cloud IAM
-
A project ID or deployment space ID
-
(optional) IBM Content Object Storage connection to watsonx
URI Format
ibm-watsonx-ai:label[?options]
You can append query options to the URI in the following format:
?option=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 IBM watsonx.ai component supports 35 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Required The watsonx.ai base URL (e.g., https://us-south.ml.cloud.ibm.com). | String | ||
The component configuration. | WatsonxAiConfiguration | ||
IBM Cloud project ID. | String | ||
IBM Cloud deployment space ID (alternative to projectId). | String | ||
The watsonx.ai WX platform URL for tool operations (e.g., https://api.dataplatform.cloud.ibm.com/wx). | String | ||
Cloud Object Storage URL. | String | ||
Deployed model ID (for deployment operations). | String | ||
Whether to detect HAP (Harmful, Abusive, Profane content). | false | Boolean | |
Detection threshold (0.0 to 1.0). | Double | ||
Whether to detect PII (Personal Identifiable Information). | false | Boolean | |
COS bucket for document storage. | String | ||
COS connection ID for document storage. | String | ||
Frequency penalty for chat. | Double | ||
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 | |
Maximum completion tokens for chat. | Integer | ||
Maximum new tokens to generate. | Integer | ||
Foundation model ID (e.g., ibm/granite-13b-instruct-v2). | String | ||
The operation to perform. Enum values:
| WatsonxAiOperations | ||
Presence penalty for chat. | Double | ||
Repetition penalty. | Double | ||
Number of top results to return for reranking. | Integer | ||
COS bucket for result storage. | String | ||
COS connection ID for result storage. | String | ||
Whether to return documents in rerank response. | false | Boolean | |
Temperature for randomness (0.0 to 2.0). | Double | ||
Top K (top-k sampling). | Integer | ||
Top P (nucleus sampling). | Double | ||
Maximum number of tokens accepted per input for embeddings. Truncates from the end if exceeded. | Integer | ||
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 | |
Whether to log HTTP requests to the watsonx.ai API. | false | Boolean | |
Whether to log HTTP responses from the watsonx.ai API. | false | Boolean | |
Request timeout in milliseconds. | Long | ||
Whether to verify SSL certificates. | true | Boolean | |
Required IBM Cloud API key for authentication. | String | ||
OAuth profile name for obtaining an access token via the OAuth 2.0 Client Credentials grant. When set, the token is acquired from the configured identity provider and used as apiKey. Requires camel-oauth on the classpath. | String |
Endpoint Options
The IBM watsonx.ai endpoint is configured using URI syntax:
ibm-watsonx-ai:label
With the following path and query parameters:
Query Parameters (33 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
Required The watsonx.ai base URL (e.g., https://us-south.ml.cloud.ibm.com). | String | ||
IBM Cloud project ID. | String | ||
IBM Cloud deployment space ID (alternative to projectId). | String | ||
The watsonx.ai WX platform URL for tool operations (e.g., https://api.dataplatform.cloud.ibm.com/wx). | String | ||
Cloud Object Storage URL. | String | ||
Deployed model ID (for deployment operations). | String | ||
Whether to detect HAP (Harmful, Abusive, Profane content). | false | Boolean | |
Detection threshold (0.0 to 1.0). | Double | ||
Whether to detect PII (Personal Identifiable Information). | false | Boolean | |
COS bucket for document storage. | String | ||
COS connection ID for document storage. | String | ||
Frequency penalty for chat. | Double | ||
Maximum completion tokens for chat. | Integer | ||
Maximum new tokens to generate. | Integer | ||
Foundation model ID (e.g., ibm/granite-13b-instruct-v2). | String | ||
The operation to perform. Enum values:
| WatsonxAiOperations | ||
Presence penalty for chat. | Double | ||
Repetition penalty. | Double | ||
Number of top results to return for reranking. | Integer | ||
COS bucket for result storage. | String | ||
COS connection ID for result storage. | String | ||
Whether to return documents in rerank response. | false | Boolean | |
Temperature for randomness (0.0 to 2.0). | Double | ||
Top K (top-k sampling). | Integer | ||
Top P (nucleus sampling). | Double | ||
Maximum number of tokens accepted per input for embeddings. Truncates from the end if exceeded. | Integer | ||
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 | |
Whether to log HTTP requests to the watsonx.ai API. | false | Boolean | |
Whether to log HTTP responses from the watsonx.ai API. | false | Boolean | |
Request timeout in milliseconds. | Long | ||
Whether to verify SSL certificates. | true | Boolean | |
Required IBM Cloud API key for authentication. | String | ||
OAuth profile name for obtaining an access token via the OAuth 2.0 Client Credentials grant. When set, the token is acquired from the configured identity provider and used as apiKey. Requires camel-oauth on the classpath. | String |
Message Headers
The IBM watsonx.ai component supports 65 message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelIBMWatsonxAiOperation (producer) Constant: | The operation to perform. | WatsonxAiOperations | |
CamelIBMWatsonxAiInput (producer) Constant: | The input text/prompt for generation. | String | |
CamelIBMWatsonxAiInputs (producer) Constant: | The list of inputs for batch operations. | List | |
CamelIBMWatsonxAiGeneratedText (producer) Constant: | The generated text output. | String | |
CamelIBMWatsonxAiModelId (producer) Constant: | The model ID to use. | String | |
CamelIBMWatsonxAiDeploymentId (producer) Constant: | The deployment ID to use. | String | |
CamelIBMWatsonxAiSpaceId (producer) Constant: | The space ID for deployment operations. | String | |
CamelIBMWatsonxAiDeploymentName (producer) Constant: | The deployment name. | String | |
CamelIBMWatsonxAiDeploymentAssetType (producer) Constant: | The deployed asset type. | String | |
CamelIBMWatsonxAiDeploymentStatus (producer) Constant: | The deployment status state. | String | |
CamelIBMWatsonxAiTemperature (producer) Constant: | Temperature for randomness (0.0 to 2.0). | Double | |
CamelIBMWatsonxAiMaxNewTokens (producer) Constant: | Maximum new tokens to generate. | Integer | |
CamelIBMWatsonxAiTopP (producer) Constant: | Top P (nucleus sampling). | Double | |
CamelIBMWatsonxAiTopK (producer) Constant: | Top K (top-k sampling). | Integer | |
CamelIBMWatsonxAiRepetitionPenalty (producer) Constant: | Repetition penalty. | Double | |
CamelIBMWatsonxAiMessages (producer) Constant: | The chat messages. | List | |
CamelIBMWatsonxAiSystemMessage (producer) Constant: | The system message for chat (used to build messages if MESSAGES header is not set). | String | |
CamelIBMWatsonxAiUserMessage (producer) Constant: | The user message for chat (used to build messages if MESSAGES header is not set, alternative to body). | String | |
CamelIBMWatsonxAiTools (producer) Constant: | The tools available for function calling. | List | |
CamelIBMWatsonxAiToolChoice (producer) Constant: | Tool choice option (auto, required, none). | String | |
CamelIBMWatsonxAiEmbeddings (producer) Constant: | The embedding vectors result. | List | |
CamelIBMWatsonxAiRerankQuery (producer) Constant: | The query for reranking. | String | |
CamelIBMWatsonxAiRerankTopN (producer) Constant: | Number of top results to return for reranking. | Integer | |
CamelIBMWatsonxAiTokenCount (producer) Constant: | The token count. | Integer | |
CamelIBMWatsonxAiTokens (producer) Constant: | The token IDs. | List | |
CamelIBMWatsonxAiFile (producer) Constant: | The file to upload. | File | |
CamelIBMWatsonxAiFileName (producer) Constant: | The file name when using InputStream input. | String | |
CamelIBMWatsonxAiFilePath (producer) Constant: | The file path for extraction or classification (for files already in COS). | String | |
CamelIBMWatsonxAiExtractionId (producer) Constant: | The extraction request ID. | String | |
CamelIBMWatsonxAiExtractionStatus (producer) Constant: | The extraction status. | String | |
CamelIBMWatsonxAiExtractedText (producer) Constant: | The extracted text content. | String | |
CamelIBMWatsonxAiBucketName (producer) Constant: | The COS bucket name for file operations. | String | |
CamelIBMWatsonxAiUploadSuccess (producer) Constant: | Whether the upload operation was successful. | Boolean | |
CamelIBMWatsonxAiDeleteSuccess (producer) Constant: | Whether the delete operation was successful. | Boolean | |
CamelIBMWatsonxAiClassificationId (producer) Constant: | The classification request ID. | String | |
CamelIBMWatsonxAiClassificationStatus (producer) Constant: | The classification status. | String | |
CamelIBMWatsonxAiClassificationResult (producer) Constant: | The classification result (document type). | String | |
CamelIBMWatsonxAiDocumentClassified (producer) Constant: | Whether the document was classified. | Boolean | |
CamelIBMWatsonxAiErrorMessage (producer) Constant: | Error message when classification or extraction fails. | String | |
CamelIBMWatsonxAiErrorCode (producer) Constant: | Error code when classification or extraction fails. | String | |
CamelIBMWatsonxAiDetectors (producer) Constant: | List of detectors to use. | List | |
CamelIBMWatsonxAiDetected (producer) Constant: | Whether harmful content was detected. | Boolean | |
CamelIBMWatsonxAiDetectionResults (producer) Constant: | Detection results grouped by type. | Map | |
CamelIBMWatsonxAiDetectionCount (producer) Constant: | Count of detections found. | Integer | |
CamelIBMWatsonxAiStreamConsumer (producer) Constant: | Consumer for streaming text. | Consumer | |
CamelIBMWatsonxAiInputTokenCount (producer) Constant: | Input token count. | Integer | |
CamelIBMWatsonxAiOutputTokenCount (producer) Constant: | Output token count. | Integer | |
CamelIBMWatsonxAiStopReason (producer) Constant: | Stop reason for generation. | String | |
CamelIBMWatsonxAiForecastInputSchema (producer) Constant: | The input schema for time series forecast. | InputSchema | |
CamelIBMWatsonxAiForecastData (producer) Constant: | The forecast data. | ForecastData | |
CamelIBMWatsonxAiForecastResults (producer) Constant: | The forecast results. | List | |
CamelIBMWatsonxAiForecastInputDataPoints (producer) Constant: | Number of input data points. | Integer | |
CamelIBMWatsonxAiForecastOutputDataPoints (producer) Constant: | Number of output data points. | Integer | |
CamelIBMWatsonxAiFoundationModels (producer) Constant: | List of foundation models. | List | |
CamelIBMWatsonxAiFoundationModelTasks (producer) Constant: | List of foundation model tasks. | List | |
CamelIBMWatsonxAiFoundationModelFilter (producer) Constant: | Filter for foundation models or tasks. | String | |
CamelIBMWatsonxAiFoundationModelTechPreview (producer) Constant: | Include tech preview models. | Boolean | |
CamelIBMWatsonxAiToolName (producer) Constant: | The tool name to run. | String | |
CamelIBMWatsonxAiToolRequest (producer) Constant: | The tool request object. | ToolRequest | |
CamelIBMWatsonxAiToolConfig (producer) Constant: | The tool configuration. | Map | |
CamelIBMWatsonxAiUtilityTools (producer) Constant: | List of available utility tools. | List | |
CamelIBMWatsonxAiToolRegistry (producer) Constant: | Tool registry for chat with tool calling capabilities. | ToolRegistry | |
CamelIBMWatsonxAiToolCalls (producer) Constant: | List of tool calls requested by the assistant. | List | |
CamelIBMWatsonxAiHasToolCalls (producer) Constant: | Whether the assistant response contains tool calls. | Boolean | |
CamelIBMWatsonxAiAssistantMessage (producer) Constant: | The full assistant message from chat response. | AssistantMessage |
Required watsonx.ai component options
You must provide the following options to use this component:
-
apiKey- Your IBM Cloud API key for authentication -
baseUrl- The watsonx.ai endpoint URL (e.g., https://us-south.ml.cloud.ibm.com) -
projectIdorspaceId- Your IBM Cloud project or deployment space ID -
modelId- The foundation model ID (for model-specific operations) -
(optional)
documentConnectionId,documentBucket,cosUrl- needed by services liketextExtractionortextClassification -
(optional)
wxUrl- For hosted IBM tools
OAuth Authentication
When using an identity provider for service-to-service authentication instead of a static API key, set the oauthProfile parameter to acquire an access token via the OAuth 2.0 Client Credentials grant. The token is used as the apiKey. This requires camel-oauth on the classpath.
camel.oauth.ibm.client-id=my-client
camel.oauth.ibm.client-secret=my-secret
camel.oauth.ibm.token-endpoint=https://iam.cloud.ibm.com/identity/token -
Java
-
XML
-
YAML
from("direct:generate")
.to("ibm-watsonx-ai:myLabel?oauthProfile=ibm&baseUrl=https://us-south.ml.cloud.ibm.com&projectId=my-project&modelId=ibm/granite-13b-instruct-v2"); <route>
<from uri="direct:generate"/>
<to uri="ibm-watsonx-ai:myLabel?oauthProfile=ibm&baseUrl=https://us-south.ml.cloud.ibm.com&projectId=my-project&modelId=ibm/granite-13b-instruct-v2"/>
</route> - route:
from:
uri: direct:generate
steps:
- to:
uri: ibm-watsonx-ai:myLabel
parameters:
oauthProfile: ibm
baseUrl: "https://us-south.ml.cloud.ibm.com"
projectId: my-project
modelId: ibm/granite-13b-instruct-v2 Security Considerations
Sensitive Data Logging
When the logRequests option is enabled, HTTP requests to the watsonx.ai API may be logged, which can expose sensitive data including your API key. Only enable request logging in development or debugging scenarios, and ensure logs are properly secured. Never enable request logging in production environments where logs might be accessible to unauthorized parties. |
Usage
Supported Operations
The IBM watsonx.ai component provides the following operations:
Text Generation (Deprecated, use chat instead)
-
textGeneration- Generate text from a prompt -
textGenerationStreaming- Generate text with streaming responses
Chat
-
chat- Chat with conversation history supporting system, user, and assistant messages -
chatStreaming- Chat with streaming responses via callback consumer
Content Detection
-
detect- Detect PII (Personal Identifiable Information) and HAP (Harmful, Abusive, Profane) content in text
Document Processing
Text Extraction operations:
-
textExtraction- Start text extraction from documents stored in Cloud Object Storage -
textExtractionFetch- Fetch text extraction results by job ID -
textExtractionUpload- Upload a local file and start extraction -
textExtractionUploadAndFetch- Upload, extract, and return text synchronously -
textExtractionUploadFile- Upload file to COS without starting extraction -
textExtractionReadFile- Read file from COS result bucket -
textExtractionDeleteFile- Delete file from COS -
textExtractionDeleteRequest- Delete extraction job
Text Classification operations:
-
textClassification- Start document classification for documents in Cloud Object Storage -
textClassificationFetch- Fetch classification results by job ID -
textClassificationUpload- Upload a local file and start classification -
textClassificationUploadAndFetch- Upload, classify, and return result synchronously -
textClassificationUploadFile- Upload file to COS without starting classification -
textClassificationDeleteFile- Delete file from COS -
textClassificationDeleteRequest- Delete classification job
| Document processing operations require Cloud Object Storage (COS) configuration with HMAC credentials. See Cloud Object Storage Connection Setup for details. |
Deployment Operations
-
deploymentGenerate- Generate text using deployed models -
deploymentChat- Chat using deployed models -
deploymentForecast- Forecast using deployed time series models
Utility Tools (Experimental)
-
runTool- Run utility tools (GoogleSearch, Weather, WebCrawler, Wikipedia, etc.) -
listTools- List available utility tools -
processToolCalls- Execute tool calls from an assistant message and update the conversation
If you don’t specify an operation explicitly, you must set it via the operation parameter.
Common Use Cases
| Use Case | Recommended Operation | Models |
|---|---|---|
Conversational AI, chatbots, Text summarization, Q&A, translation |
| ibm/granite-4-h-small, meta-llama/llama-3-8b-instruct |
Semantic search, similarity matching |
| ibm/granite-embedding-278m-multilingual |
RAG document retrieval ranking |
| cross-encoder/ms-marco-minilm-l-12-v2 |
Token counting, context management |
| Any text generation model |
Content moderation, compliance |
| N/A (uses built-in detectors) |
Document text extraction |
| N/A (uses document processing pipeline) |
Document classification |
| N/A (uses document processing pipeline) |
Time series forecasting |
| ibm/granite-ttm-1536-96-r2 |
Model catalog exploration |
| N/A |
Deployed model inference |
| Deployed models |
Web search, weather, web crawling |
| N/A (uses utility tools) |
Chat with tool calling (agentic) |
| ibm/granite-3-8b-instruct, ibm/granite-4-h-small |
Sub-Pages
For more details, see:
-
Examples - Comprehensive examples for chat, embeddings, reranking, content detection, document processing, forecasting, and model operations
Spring Boot and Camel Main Configuration
When using Spring Boot or Camel Main, you can configure the component in application.properties:
This configuration approach works with both Spring Boot (camel-ibm-watsonx-ai-starter) and Camel Main runtimes. |
# watsonx.ai configuration
camel.component.ibm-watsonx-ai.configuration.api-key=${IBM_WATSONX_API_KEY}
camel.component.ibm-watsonx-ai.configuration.base-url=https://us-south.ml.cloud.ibm.com
camel.component.ibm-watsonx-ai.configuration.project-id=${IBM_WATSONX_PROJECT_ID}
camel.component.ibm-watsonx-ai.configuration.model-id=ibm/granite-13b-instruct-v2
camel.component.ibm-watsonx-ai.configuration.temperature=0.7
camel.component.ibm-watsonx-ai.configuration.max-new-tokens=200 Then use the component in routes without repeating configuration:
-
Java
-
XML
-
YAML
from("direct:generate")
.setBody(constant("Explain microservices architecture"))
.to("ibm-watsonx-ai:gen?operation=textGeneration")
.log("Generated: ${body}"); <route>
<from uri="direct:generate"/>
<setBody>
<constant>Explain microservices architecture</constant>
</setBody>
<to uri="ibm-watsonx-ai:gen?operation=textGeneration"/>
<log message="Generated: ${body}"/>
</route> - route:
from:
uri: direct:generate
steps:
- setBody:
constant: "Explain microservices architecture"
- to:
uri: ibm-watsonx-ai:gen
parameters:
operation: textGeneration
- log:
message: "Generated: ${body}" watsonx.ai Authentication
IBM watsonx.ai uses IBM Cloud IAM (Identity and Access Management) for authentication. You need to provide your IBM Cloud API key.
You can create API keys in the IBM Cloud console:
-
Click "Create an IBM Cloud API key"
-
Copy the API key and use it in your Camel routes
For more information about authentication, see the IBM Cloud IAM documentation.
Cloud Object Storage Connection Setup
Document processing operations (text extraction and classification) require a properly configured IBM Cloud Object Storage (COS) connection in your watsonx.ai project.
| The COS connection must include HMAC credentials (access_key_id and secret_access_key), not just IAM Service Credentials. Without HMAC credentials, you will encounter errors like "EmptyStaticCreds: static credentials are empty". |
Creating COS Credentials with HMAC
-
Go to your IBM Cloud console
-
Navigate to your Cloud Object Storage instance
-
Go to Service credentials tab
-
Click New credential
-
Important: Expand "Advanced options" and enable Include HMAC Credential
-
Create the credential
-
The credential will include both IAM and HMAC keys:
{ "apikey": "...", "cos_hmac_keys": { "access_key_id": "...", "secret_access_key": "..." }, ... }
Creating the COS Connection in watsonx.ai
-
In your watsonx.ai project, go to Manage → Connections
-
Click New connection
-
Select IBM Cloud Object Storage
-
Enter the HMAC credentials (access_key_id and secret_access_key)
-
Save the connection and note the Connection ID
The Connection ID is what you use for the documentConnectionId and resultConnectionId parameters.
Additional Resources
-
For more information about how to create the IBM Cloud Object Storage connection, see the IBM watsonx.ai COS connection documentation.
-
To find the bucket name and COS endpoint for your region, see the IBM Cloud Object Storage buckets documentation.
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ibm-watsonx-ai</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> where x.x.x is the version number of Camel.