Skip to main content

0.40.0 → 0.50.0

This release removes the direct Jackson dependency from watsonx-ai-core and watsonx-ai. JSON serialization goes through the JsonProvider SPI, and a separate binding module now supplies the implementation. It also adds ProjectService, context and generated-text detection, ContainerReference storage for document processing, custom HTTP log handlers, and an expanded JsonSchema API. A few request and response fields are removed, and WatsonxService.ProjectService is renamed to ScopedService.


What's new​

ProjectService​

ProjectService retrieves watsonx platform project metadata, including the storage configuration of a project. It lives in com.ibm.watsonx.ai.project.

ProjectService service = ProjectService.builder()
.baseUrl(CloudRegion.DALLAS)
.apiKey(WATSONX_API_KEY)
.build();

Optional<Project> project = service.findProject(WATSONX_PROJECT_ID);

findProject returns an empty Optional when the API answers 404. See Project.


Context and generated-text detection​

DetectionService gains detectContext(...) for the ContextRelevance and Faithfulness detectors, and detectGenerated(...) for AnswerRelevance. These detectors need a watsonx.governance service instance, set once with governanceInstanceId(...) on the builder or per request with serviceInstanceId(...).

DetectionService detectionService = DetectionService.builder()
.apiKey(WATSONX_API_KEY)
.projectId(WATSONX_PROJECT_ID)
.governanceInstanceId(WATSONX_GOVERNANCE_INSTANCE_ID)
.baseUrl(CloudRegion.DALLAS)
.build();

var request = DetectionContextRequest.builder()
.input("What is IBM?")
.context(List.of("IBM is a technology company."))
.detectors(ContextRelevance.ofDefaults(), Faithfulness.ofThreshold(0.5))
.build();

DetectionResponse<DetectionContextResponse> response = detectionService.detectContext(request);

When a governance instance ID is present, it is sent in the x-governance-instance-id header and the request leaves project_id and space_id out of the body. Without one, the request is scoped by Project ID or Space ID as before.


ContainerReference for text extraction and classification​

TextExtractionService and TextClassificationService accept a ContainerReference in addition to CosReference. It points at the default container of the project, so no COS URL or credentials are needed. DocumentReference is the new sealed interface implemented by both.

TextExtractionService service = TextExtractionService.builder()
.apiKey(WATSONX_API_KEY)
.projectId(WATSONX_PROJECT_ID)
.baseUrl(CloudRegion.DALLAS)
.documentReference(ContainerReference.container())
.resultReference(ContainerReference.container())
.build();

Uploads then go to the default COS bucket of the project, resolved through ProjectService. A Project ID is required, a Space ID alone is not supported. With baseUrl(CloudRegion) the lookup is automatic. With a plain URL, pass an explicit projectService(...) on the builder.


Custom HTTP log handlers​

logRequests(...) and logResponses(...) on every service builder accept an HttpRequestLogger or HttpResponseLogger (package com.ibm.watsonx.ai.core.http.logging) instead of a boolean, with an optional SLF4J Level that gates the handler. Handlers run on the callback executor, so a slow handler never blocks the I/O threads. Request and response bodies arrive already masked. See HTTP Client: Custom loggers.

ChatService chatService = ChatService.builder()
.apiKey(WATSONX_API_KEY)
.projectId(WATSONX_PROJECT_ID)
.baseUrl(CloudRegion.DALLAS)
.modelId("ibm/granite-4-h-small")
.logRequests(entry -> telemetry.record("request", entry.body()))
.logResponses(entry -> telemetry.record("response", entry.statusCode()), Level.DEBUG)
.build();

onThinking consumers in streaming​

ChatService, DeploymentService, and ModelGatewayChatService gain chatStreaming overloads that take a second Consumer<String> for reasoning tokens, so a ChatHandler is no longer needed to separate them from the answer.

chatService.chatStreaming(messages,
token -> System.out.print(token),
thinking -> System.err.print(thinking));

Expanded JsonSchema​

Every schema builder now supports title, defaultValue, examples, readOnly, writeOnly, deprecated, anyOf, allOf, not, and conditionals through ifCondition, then, and otherwise. ObjectSchema adds propertyNames, dependentRequired, dependentSchema, and unevaluatedProperties. ArraySchema adds prefixItems, uniqueItems, minContains, maxContains, and unevaluatedItems.

ChatParameters and ModelGatewayChatParameters also accept a raw JSON schema string through responseAsJsonSchema(String) and responseAsJsonSchema(String, String, boolean). A string that is not a valid JSON object throws IllegalArgumentException. See Chat: Structured Output.

JsonSchema schema = JsonSchema.object()
.property("id", JsonSchema.string().title("Identifier").readOnly())
.property("kind", JsonSchema.string().examples("a", "b"))
.anyOf(JsonSchema.required("id"), JsonSchema.required("kind"))
.dependentRequired("kind", "id")
.build();

ChatParameters parameters = ChatParameters.builder()
.responseAsJsonSchema(schema)
.build();

Breaking changes​

Add a JSON binding module​

watsonx-ai alone no longer brings Jackson onto the classpath. Add exactly one binding module alongside it:

Binding moduleJackson versionPackage
watsonx-ai-jackson2Jackson 2com.fasterxml.jackson
watsonx-ai-jackson3Jackson 3tools.jackson

Before:

<dependency>
<groupId>com.ibm.watsonx</groupId>
<artifactId>watsonx-ai</artifactId>
<version>0.40.0</version>
</dependency>

After:

<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>

Without a binding module, the first JSON operation fails with an ExceptionInInitializerError caused by an IllegalStateException ("No JsonProvider found. Add exactly one JSON binding, for example watsonx-ai-jackson2 or watsonx-ai-jackson3."). Every later one fails with a NoClassDefFoundError, because Json cannot be initialized. Adding both modules fails too, because they ship a class with the same name (com.ibm.watsonx.ai.WatsonxJacksonModule): the first jar on the classpath wins and the other binding fails to load, with a VerifyError or a ServiceConfigurationError. Because these are Error subclasses, a catch (Exception e) block does not intercept them. See JSON SPI.

The GraalVM reachability metadata for the SDK model classes now ships inside the binding modules, and watsonx-ai no longer carries its own reachability-metadata.json. Native-image projects need the binding module like everyone else.


WatsonxJacksonModule moved out of watsonx-ai​

com.ibm.watsonx.ai.WatsonxJacksonModule no longer ships inside watsonx-ai. It now lives inside each binding module (one copy per Jackson major version, same fully qualified name), so code importing it directly needs watsonx-ai-jackson2 or watsonx-ai-jackson3 on the classpath, which the change above already requires.


JacksonProvider moved out of watsonx-ai-core​

com.ibm.watsonx.ai.core.provider.JacksonProvider no longer exists. Each binding module ships its own, registered through ServiceLoader:

Binding moduleClass
watsonx-ai-jackson2com.ibm.watsonx.ai.jackson2.provider.JacksonProvider
watsonx-ai-jackson3com.ibm.watsonx.ai.jackson3.provider.JacksonProvider

Code that referenced the old class, for example a custom provider that extends it, must switch to the new import.


WatsonxService.ProjectService renamed to ScopedService​

The abstract base class for services that need a Project ID or Space ID is now WatsonxService.ScopedService. The name ProjectService belongs to the new com.ibm.watsonx.ai.project.ProjectService. Built-in services are unaffected. A custom service must update both its class and its builder:

BeforeAfter
WatsonxService.ProjectServiceWatsonxService.ScopedService
ProjectService.Builder<T>ScopedService.Builder<T>

ModelService and CryptoService keep their names. ModelService now extends ScopedService.


Removed fields​

RemovedFromNotes
repetitionPenalty, lengthPenalty (builder methods and accessors)ChatParameters, TextChatRequestTextGenerationParameters keeps both
enableGenericKvp (builder method and accessor)TextExtractionSemanticConfig, TextClassificationSemanticConfigenableSchemaKvp is unchanged
numberPagesProcessed (record component)TextClassificationResponse.ClassificationResultExtractionResult and CreateSchemaResult keep it

Delete the calls. The matching JSON fields are no longer sent. For ClassificationResult, the record constructor also loses a parameter.


Changed types and signatures​

BeforeAfter
TextGenerationResponse.TokenInfo.topTokens() returns TopTokenInforeturns List<TopTokenInfo>, which fixes deserialization
NumberSchema.minimum(), maximum(), exclusiveMinimum(), exclusiveMaximum() return Integerreturn Double, and the builder methods take double (existing int arguments still compile)
StringSchema.getPattern(), getMaxLength(), getMinLength(), getFormat()pattern(), maxLength(), minLength(), format()
ObjectSchema.anyOf() returns List<RequiredSchema>returns List<? extends JsonSchema>, and builder calls compile unchanged
BaseChatParameters.Builder.responseAsJsonSchema(String, Object, boolean) is publicprotected, use the overloads that take JsonSchema, Map<String, Object>, or String
TextExtractionParameters.documentReference() and resultReference(), TextClassificationParameters.documentReference() return CosReferencereturn DocumentReference (match on CosReference or ContainerReference)
TextClassificationService.deleteFile(bucket, file) declares no checked exceptiondeclares throws FileNotFoundException, like TextExtractionService
CosDataLocation(fileName, bucket) requires a non-null fileNameCosDataLocation(fileName, bucket, path) validates nothing, path is used by container references
DataReference forces its type to connection_assetkeeps the type it is given, with constants TYPE_CONNECTION_ASSET and TYPE_CONTAINER
TextExtractionParameters.Builder is an open classfinal

CosReference.toDataReference(...) and ContainerReference.toDataReference(...) build a correct DataReference, so prefer them to calling the record constructors.


Custom DetectionRestClient​

A custom client registered through the Service Provider Interface must adapt to the new abstract methods:

public abstract DetectionResponse<DetectionTextResponse> detect(
String transactionId, String serviceInstanceId, TextDetectionContentDetectors request);

public abstract DetectionResponse<DetectionContextResponse> detectContext(
String transactionId, String serviceInstanceId, TextDetectionContextDetectors request);

public abstract DetectionResponse<DetectionGeneratedResponse> detectGenerated(
String transactionId, String serviceInstanceId, TextDetectionGeneratedDetectors request);

When serviceInstanceId is not null, send it in the header named by DetectionRestClient.GOVERNANCE_INSTANCE_ID_HEADER. WatsonxRestClient also exposes the new protected fields requestLogger, requestLogLevel, responseLogger, and responseLogLevel. Pass them to HttpClientFactory.createSync and createAsync to honor custom log handlers.


Behavior changes​

Custom JsonProvider implementations are unaffected​

JsonProvider gained an isDefault() default method that returns false. An existing custom implementation needs no change: staying at the default keeps it an explicit provider, which wins over a binding module's bundled one automatically, even when that binding module is also on the classpath (for example, to reuse WatsonxJacksonModule). See JSON SPI: Resolution.


watsonx.ai API version​

The API version sent with every request moved from 2026-08-19 to 2026-10-28.


uploadFile(File) rejects directories explicitly​

Passing a directory to TextExtractionService.uploadFile(File) or TextClassificationService.uploadFile(File) now fails with the error code directory_not_allowed. It used to fail with file_not_found, because the JDK reports a directory as a missing file when opening it as a stream.