Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.15.0"
".": "2.16.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 34
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-29a6b7ba51942cd606e5bf4b533e5aac1bef42f6d4b1f7f45f756304cf676782.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-60fbf504538934c934f523d456bbf3cd99e7f1e2275041f74d5beb627bf38e19.yml
openapi_spec_hash: 58021ab18daccd5c45a930ffd7d6ab4d
config_hash: 4e204fead5f0af80eb9effa1d1e34dca
config_hash: a592b9a483e895373b649a575d475b15
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 2.16.0 (2026-02-24)

Full Changelog: [v2.15.0...v2.16.0](https://github.com/anthropics/anthropic-sdk-java/compare/v2.15.0...v2.16.0)

### Features

* **api:** change array_format to brackets ([f9eef6e](https://github.com/anthropics/anthropic-sdk-java/commit/f9eef6ecfdfc0e4ab88a089814412ff0cbf2b04c))
* **api:** remove publishing section from cli target ([f802cb0](https://github.com/anthropics/anthropic-sdk-java/commit/f802cb0b4cffaaf618c51c630b61275c888d742f))


### Chores

* make `Properties` more resilient to `null` ([5c7ad57](https://github.com/anthropics/anthropic-sdk-java/commit/5c7ad57d2a9c6ee69fe1c96a6cd8e5e2ada67f87))


### Documentation

* additional structured outputs documentation ([#302](https://github.com/anthropics/anthropic-sdk-java/issues/302)) ([3b1f131](https://github.com/anthropics/anthropic-sdk-java/commit/3b1f131312954856ecdaa66f06741e1e5f86d81d))

## 2.15.0 (2026-02-19)

Full Changelog: [v2.14.0...v2.15.0](https://github.com/anthropics/anthropic-sdk-java/compare/v2.14.0...v2.15.0)
Expand Down
228 changes: 175 additions & 53 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ fun getOsName(): String {
}
}

fun getOsVersion(): String = System.getProperty("os.version", "unknown")
fun getOsVersion(): String = System.getProperty("os.version", "unknown") ?: "unknown"

fun getPackageVersion(): String =
AnthropicClient::class.java.`package`.implementationVersion ?: "unknown"
AnthropicClient::class.java.`package`?.implementationVersion ?: "unknown"

fun getJavaVersion(): String = System.getProperty("java.version", "unknown")
fun getJavaVersion(): String = System.getProperty("java.version", "unknown") ?: "unknown"
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.models.messages.MessageCreateParams;
import com.anthropic.models.messages.Model;
import com.anthropic.models.messages.StructuredMessageCreateParams;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import java.util.List;

/**
* <p>
* Example demonstrating GA (non-beta) structured outputs.
*
* <p>This example uses the GA Messages API with structured outputs, which does NOT require any beta
* </p>
* <p>
* This example derives the JSON schema for the output format from the structure of Java classes.
* Compare to {@link StructuredOutputsRawExample} where the low-level API is used to define the same
* JSON schema without using Java classes.
* </p>
* <p>
* This example uses the GA Messages API with structured outputs, which does NOT require any beta
* headers. Compare with {@link BetaStructuredOutputsExample} which uses the beta API.
* </p>
*/
public final class StructuredOutputsExample {

Expand Down Expand Up @@ -65,7 +74,7 @@ public static void main(String[] args) {
// GA structured outputs - no beta header required!
// Use client.messages() instead of client.beta().messages()
StructuredMessageCreateParams<BookList> createParams = MessageCreateParams.builder()
.model("claude-sonnet-4-5")
.model(Model.CLAUDE_SONNET_4_5_20250929)
.maxTokens(2048)
.outputConfig(BookList.class)
.addUserMessage("List some famous late twentieth century novels.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.anthropic.example;

import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.core.JsonValue;
import com.anthropic.models.messages.JsonOutputFormat;
import com.anthropic.models.messages.MessageCreateParams;
import com.anthropic.models.messages.Model;
import com.anthropic.models.messages.OutputConfig;
import java.util.List;
import java.util.Map;

/**
* An example of structured outputs using the low-level ("raw") API to define the JSON schema for
* the output format. Compare to {@link StructuredOutputsExample} where the same JSON schema is
* derived from the structure of Java classes.
*/
public final class StructuredOutputsRawExample {

private StructuredOutputsRawExample() {}

public static void main(String[] args) {
// Configure by setting the `ANTHROPIC_API_KEY` environment variable.
AnthropicClient client = AnthropicOkHttpClient.fromEnv();

JsonOutputFormat.Schema schema = JsonOutputFormat.Schema.builder()
// The "$schema" property can be omitted.
.putAdditionalProperty("type", JsonValue.from("object"))
.putAdditionalProperty(
"properties",
JsonValue.from(Map.of(
"books",
Map.of(
"minItems",
1,
"type",
"array",
"items",
Map.of(
"type",
"object",
"properties",
Map.of(
"author",
Map.of(
"type",
"object",
"properties",
Map.of(
"birthYear", Map.of("type", "integer"),
"deathYear",
Map.of(
"type",
"string",
"description",
"The year the person"
+ " died, or"
+ " 'present' if"
+ " the person is"
+ " living."),
"name",
Map.of(
"type",
"string",
"description",
"The first"
+ " name"
+ " and surname"
+ " of the"
+ " person.")),
"required",
List.of("birthYear", "deathYear", "name"),
"additionalProperties",
false),
"genre", Map.of("type", "string"),
"publicationYear",
Map.of(
"type",
"integer",
"description",
"The year in which the book was first"
+ " published. No earlier than"
+ " 1500."),
"title", Map.of("type", "string")),
"required",
List.of("author", "genre", "publicationYear", "title"),
"additionalProperties",
false)))))
.putAdditionalProperty("required", JsonValue.from(List.of("books")))
.putAdditionalProperty("additionalProperties", JsonValue.from(false))
.build();

OutputConfig outputConfig = OutputConfig.builder()
.format(JsonOutputFormat.builder().schema(schema).build())
.build();

MessageCreateParams createParams = MessageCreateParams.builder()
.model(Model.CLAUDE_SONNET_4_5_20250929)
.maxTokens(2048)
.outputConfig(outputConfig)
.addUserMessage("List some famous late twentieth century novels.")
.build();

client.messages().create(createParams).content().stream()
.flatMap(contentBlock -> contentBlock.text().stream())
.forEach(textBlock -> System.out.println("JSON output: " + textBlock.text()));
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {

allprojects {
group = "com.anthropic"
version = "2.15.0" // x-release-please-version
version = "2.16.0" // x-release-please-version
}

subprojects {
Expand Down