IBM watsonx.ai Java SDK
The IBM watsonx.ai Java SDK is an open-source client library that interacts with IBM watsonx.ai, an enterprise-grade AI platform for building, training, and deploying AI models at scale.
Prerequisites
Before getting started, ensure you have:
- A watsonx.ai service instance (IBM Cloud or on-premises)
- Java 17 or higher
- Maven or Gradle
The Setup & Prerequisites guide walks through creating the resources the SDK needs (API key, Project ID, Cloud Object Storage, and more), with links to the IBM documentation.
Installation
Add the SDK and one JSON binding module to your Maven project:
<dependency>
<groupId>com.ibm.watsonx</groupId>
<artifactId>watsonx-ai</artifactId>
<version>0.50.0</version>
</dependency>
<dependency>
<groupId>com.ibm.watsonx</groupId>
<artifactId>watsonx-ai-jackson2</artifactId>
<version>0.50.0</version>
</dependency>
Or for Gradle:
implementation 'com.ibm.watsonx:watsonx-ai:0.50.0'
implementation 'com.ibm.watsonx:watsonx-ai-jackson2:0.50.0'
watsonx-ai-jackson2 binds Jackson 2 and watsonx-ai-jackson3 binds Jackson 3. Add exactly one of them. Without a binding the SDK fails on the first JSON operation, see JSON SPI.
Quick Start
Build and run your first watsonx.ai-powered chat:
ChatService chatService = ChatService.builder()
.apiKey(System.getenv("WATSONX_API_KEY"))
.projectId(System.getenv("WATSONX_PROJECT_ID"))
.baseUrl(CloudRegion.DALLAS)
.modelId("ibm/granite-4-h-small")
.build();
AssistantMessage response = chatService
.chat("Tell me a joke")
.toAssistantMessage();
System.out.println(response.content());
See the documentation for advanced usage.
Services
The SDK provides a unified Java interface to the watsonx.ai ecosystem and works with both IBM Cloud and CP4D (on-premises) deployments.
Inference
| Service |
Description |
| Chat |
Conversational AI with multi-turn dialogue, streaming, tool calling, vision, and reasoning |
| Embedding |
Dense vector representations for semantic search, similarity, and RAG |
| Rerank |
Relevance scoring and reordering of candidate documents |
| Time Series |
Time series forecasting using IBM Granite TTM models |
| Deployment |
Chat and forecasting via deployed model endpoints |
| Foundation Model |
Browse and query the watsonx.ai model catalog |
Model Gateway
Proxy layer that routes requests to third-party foundation models (OpenAI, Anthropic, Azure, Mistral, and others) through a single IBM-managed endpoint.
| Service |
Description |
| Chat |
Synchronous and streaming chat completions to any configured model |
| Catalog |
List all configured models and retrieve individual model details by UUID or alias |
| Embedding |
Generate vector embeddings from text using any configured embedding model |
| Image Generation |
Generate images from text prompts using any configured image model |
Document Processing
| Service |
Description |
| Schema |
Create, improve, merge, and cluster document extraction schemas |
| Text Extraction |
Structured data extraction from documents in IBM Cloud Object Storage |
| Text Classification |
Document classification from IBM Cloud Object Storage |
Utilities
| Service |
Description |
| Tool |
Server-side utility tools for agentic workflows |
| Tokenization |
Token counting and analysis for any model |
| Detection |
Identification of harmful content (HAP), PII, and safety violations |
| File |
Upload, list, and retrieve files for use in batch processing jobs |
| Batch |
High-volume asynchronous inference from JSONL input files |
| Project |
Retrieve project metadata |
Samples
Examples of usage are available in the samples/ directory.
Framework Integrations
The SDK integrates seamlessly with popular Java frameworks:
- LangChain4j - Native integration for building LLM-powered applications in Java.
- Quarkus LangChain4j - Optimized integration for building LLM-powered applications with Quarkus.
- Apache Camel - Integrate AI capabilities into enterprise integration patterns and workflows.
Contributing
We welcome contributions! Please follow these guidelines when submitting a patch:
License header: all source files must include an SPDX header for Apache License 2.0:
/*
* Copyright 2025 IBM Corporation
* SPDX-License-Identifier: Apache-2.0
*/
The header and code formatting are applied automatically by running:
DCO sign-off: include a Signed-off-by line in your commit message:
Signed-off-by: Your Name <your.email@example.com>
Add it automatically with:
License
Apache License 2.0. See the LICENSE file for details.