Skip to content

release: 2.1.0 #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a5287dc
chore(internal): fix release workflows
stainless-app[bot] May 23, 2025
b9b63ca
fix(client): remove `@MustBeClosed` for future returning methods
stainless-app[bot] May 29, 2025
3d2f428
fix(client): handle server tool use delta and extract to better type
dtmeadows May 29, 2025
6a52203
codegen metadata
stainless-app[bot] Jun 2, 2025
f85d1a2
feat(client): add support for new text_editor_20250429 tool
stainless-app[bot] Jun 3, 2025
151e181
feat(client): more `toParam()` methods
stainless-app[bot] Jun 3, 2025
2632693
fix(client): `toParam` methods
stainless-app[bot] Jun 3, 2025
7d1a430
Update anthropic-java-core/src/main/kotlin/com/anthropic/helpers/Mess…
dtmeadows Jun 4, 2025
a0349a0
Update anthropic-java-core/src/main/kotlin/com/anthropic/helpers/Beta…
dtmeadows Jun 4, 2025
69c5260
Merge remote-tracking branch 'origin/next' into dmeadows/fix-server-t…
dtmeadows Jun 4, 2025
3d39549
clean up
dtmeadows Jun 4, 2025
0fe8946
Merge pull request #516 from stainless-sdks/dmeadows/fix-server-tool-…
dtmeadows Jun 4, 2025
e83424b
fix(client): deprecate BetaBase64PDFBlock in favor of BetaRequestDocu…
stainless-app[bot] Jun 6, 2025
37aa2a1
feat(client): add support for fine-grained-tool-streaming-2025-05-14
stainless-app[bot] Jun 10, 2025
7d1758a
chore(docs): adjust MCP example to show use of beta header
dtmeadows Jun 10, 2025
2b39131
chore(tests): add test for fine-grained-tool-streaming-2025-05-14 logic
dtmeadows Jun 10, 2025
823032b
feat(api): api update
stainless-app[bot] Jun 11, 2025
6156bcb
feat(api): manual updates
stainless-app[bot] Jun 11, 2025
8d119e7
release: 2.1.0
stainless-app[bot] Jun 11, 2025
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.0.0"
".": "2.1.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 26
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-1fdf23e8226430012c21819427e8d1ed16c08c0fb2d4abf69b8e318a42e99552.yml
openapi_spec_hash: 836bbb4ab7c33c37456d1842876d7aba
config_hash: 7b17fe2f10f5942177ff51b0a13506fa
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-a7b84017aa1126ad99443296dcd81ab2b53f1c346014b92096226cf993f30502.yml
openapi_spec_hash: 58d4e72c7906bd8a680ab17b99de6215
config_hash: 0d82158a1e3c18a76a63f7424d293ec6
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## 2.1.0 (2025-06-11)

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

### Features

* **api:** api update ([823032b](https://github.com/anthropics/anthropic-sdk-java/commit/823032be6cb8d06ad6a106b78672f7df0f0fdb37))
* **api:** manual updates ([6156bcb](https://github.com/anthropics/anthropic-sdk-java/commit/6156bcb1d6d21041b6e34d8bab9f5e75e7a085fa))
* **client:** add support for fine-grained-tool-streaming-2025-05-14 ([37aa2a1](https://github.com/anthropics/anthropic-sdk-java/commit/37aa2a1d82cddde6ff7f1b3e38085bf658971e1d))
* **client:** add support for new text_editor_20250429 tool ([f85d1a2](https://github.com/anthropics/anthropic-sdk-java/commit/f85d1a233b58b7c926dddb64131de7122716d169))
* **client:** more `toParam()` methods ([151e181](https://github.com/anthropics/anthropic-sdk-java/commit/151e181c1521dab983e9fb03a9bfb2430dca88f9))


### Bug Fixes

* **client:** `toParam` methods ([2632693](https://github.com/anthropics/anthropic-sdk-java/commit/26326938e574f4265c3c940fa5a85a143ee75f7f))
* **client:** deprecate BetaBase64PDFBlock in favor of BetaRequestDocumentBlock ([e83424b](https://github.com/anthropics/anthropic-sdk-java/commit/e83424bb384c33f677cccd2174d779d344cfe916))
* **client:** handle server tool use delta and extract to better type ([3d2f428](https://github.com/anthropics/anthropic-sdk-java/commit/3d2f4289a8195a9c9faf97ef48904aa769383157))
* **client:** remove `@MustBeClosed` for future returning methods ([b9b63ca](https://github.com/anthropics/anthropic-sdk-java/commit/b9b63ca942178bc390a1c8a95deea4817edb9b60))


### Chores

* **docs:** adjust MCP example to show use of beta header ([7d1758a](https://github.com/anthropics/anthropic-sdk-java/commit/7d1758a00b49c9fbe7ccbf2cc1bc294e1257a58a))
* **internal:** fix release workflows ([a5287dc](https://github.com/anthropics/anthropic-sdk-java/commit/a5287dc4ffaad0e02fed166b63e4635448666247))
* **tests:** add test for fine-grained-tool-streaming-2025-05-14 logic ([2b39131](https://github.com/anthropics/anthropic-sdk-java/commit/2b391311176cc7fbdc4325ee5777818014d10ca1))

## 2.0.0 (2025-05-22)

Full Changelog: [v1.4.0...v2.0.0](https://github.com/anthropics/anthropic-sdk-java/compare/v1.4.0...v2.0.0)
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.anthropic/anthropic-java)](https://central.sonatype.com/artifact/com.anthropic/anthropic-java/2.0.0)
[![javadoc](https://javadoc.io/badge2/com.anthropic/anthropic-java/2.0.0/javadoc.svg)](https://javadoc.io/doc/com.anthropic/anthropic-java/2.0.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.anthropic/anthropic-java)](https://central.sonatype.com/artifact/com.anthropic/anthropic-java/2.1.0)
[![javadoc](https://javadoc.io/badge2/com.anthropic/anthropic-java/2.1.0/javadoc.svg)](https://javadoc.io/doc/com.anthropic/anthropic-java/2.1.0)

<!-- x-release-please-end -->

The Anthropic Java SDK provides convenient access to the [Anthropic REST API](https://docs.anthropic.com/claude/reference/) from applications written in Java.

<!-- x-release-please-start-version -->

The REST API documentation can be found on [docs.anthropic.com](https://docs.anthropic.com/claude/reference/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.anthropic/anthropic-java/2.0.0).
The REST API documentation can be found on [docs.anthropic.com](https://docs.anthropic.com/claude/reference/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.anthropic/anthropic-java/2.1.0).

<!-- x-release-please-end -->

Expand All @@ -22,7 +22,7 @@ The REST API documentation can be found on [docs.anthropic.com](https://docs.ant
### Gradle

```kotlin
implementation("com.anthropic:anthropic-java:2.0.0")
implementation("com.anthropic:anthropic-java:2.1.0")
```

### Maven
Expand All @@ -31,7 +31,7 @@ implementation("com.anthropic:anthropic-java:2.0.0")
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
</dependency>
```

Expand Down Expand Up @@ -632,7 +632,7 @@ requires the `anthropic-java-bedrock` library dependency.
### Gradle

```kotlin
implementation("com.anthropic:anthropic-java-bedrock:2.0.0")
implementation("com.anthropic:anthropic-java-bedrock:2.1.0")
```

### Maven
Expand All @@ -641,7 +641,7 @@ implementation("com.anthropic:anthropic-java-bedrock:2.0.0")
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java-bedrock</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
</dependency>
```

Expand Down Expand Up @@ -739,7 +739,7 @@ This support requires the `anthropic-java-vertex` library dependency.
### Gradle

```kotlin
implementation("com.anthropic:anthropic-java-vertex:2.0.0")
implementation("com.anthropic:anthropic-java-vertex:2.1.0")
```

### Maven
Expand All @@ -748,7 +748,7 @@ implementation("com.anthropic:anthropic-java-vertex:2.0.0")
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java-vertex</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import com.anthropic.core.jsonMapper
import com.anthropic.errors.AnthropicInvalidDataException
import com.anthropic.models.beta.messages.*

/** Checks if a content block is one that tracks tool input via input_json_delta events */
@JvmSynthetic
internal fun BetaContentBlock.tracksToolInput(): Boolean =
isToolUse() || isServerToolUse() || isMcpToolUse()

/**
* An accumulator that constructs a [BetaMessage] from a sequence of streamed events. Pass all
* events from the `message_start` event to the `message_stop` event to [accumulate] and then call
Expand Down Expand Up @@ -398,44 +403,52 @@ class BetaMessageAccumulator private constructor() {
// to update the final `tool_use` content block.
val inputJson = messageContentInputJson[index]

if (oldContentBlock.isToolUse()) {
if (oldContentBlock.tracksToolInput()) {
// Check that there was at least one delta, so a potentially-valid `input`
// JSON string was accumulated.
inputJson
?: throw AnthropicInvalidDataException(
"Missing input JSON for index $index."
)

messageContent[index] =
BetaContentBlock.ofToolUse(
oldContentBlock
.asToolUse()
.toBuilder()
// Anthropic Streaming Messages API: "the final `tool_use.input`
// is always an _object_."
.input(JSON_MAPPER.readValue(inputJson, JsonObject::class.java))
.build()
)
}

if (oldContentBlock.isMcpToolUse()) {
// Check that there was at least one delta, so a potentially-valid `input`
// JSON string was accumulated.
inputJson
?: throw AnthropicInvalidDataException(
"Missing input JSON for index $index."
)
val parsedInput =
try {
JSON_MAPPER.readValue(inputJson, JsonObject::class.java)
} catch (e: Exception) {
throw AnthropicInvalidDataException(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we check for the beta header here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and do we have tests for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added testing this for!

"Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${e}. JSON: $inputJson"
)
}

messageContent[index] =
BetaContentBlock.ofMcpToolUse(
oldContentBlock
.asMcpToolUse()
.toBuilder()
// Anthropic Streaming Messages API: "the final `tool_use.input`
// is always an _object_."
.input(JSON_MAPPER.readValue(inputJson, JsonObject::class.java))
.build()
)
when {
oldContentBlock.isToolUse() ->
BetaContentBlock.ofToolUse(
oldContentBlock
.asToolUse()
.toBuilder()
.input(parsedInput)
.build()
)
oldContentBlock.isServerToolUse() ->
BetaContentBlock.ofServerToolUse(
oldContentBlock
.asServerToolUse()
.toBuilder()
.input(parsedInput)
.build()
)
oldContentBlock.isMcpToolUse() ->
BetaContentBlock.ofMcpToolUse(
oldContentBlock
.asMcpToolUse()
.toBuilder()
.input(parsedInput)
.build()
)
else -> oldContentBlock // Should never happen given tracksToolInput
// check
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import com.anthropic.models.messages.ToolUseBlock
import com.anthropic.models.messages.Usage
import com.anthropic.models.messages.WebSearchToolResultBlock

/** Checks if a content block is one that tracks tool input via input_json_delta events */
@JvmSynthetic
internal fun ContentBlock.tracksToolInput(): Boolean = isToolUse() || isServerToolUse()

/**
* An accumulator that constructs a [Message] from a sequence of streamed events. Pass all events
* from the `message_start` event to the `message_stop` event to [accumulate] and then call
Expand Down Expand Up @@ -380,30 +384,46 @@ class MessageAccumulator private constructor() {
// to update the final `tool_use` content block.
val inputJson = messageContentInputJson[index]

if (oldContentBlock.isToolUse()) {
if (oldContentBlock.tracksToolInput()) {
// Check that there was at least one delta, so a potentially-valid `input`
// JSON string was accumulated.
inputJson
?: throw AnthropicInvalidDataException(
"Missing input JSON for index $index."
)

val parsedInput =
if (inputJson.trim() == "") JsonMissing.of()
else JSON_MAPPER.readValue(inputJson, JsonObject::class.java)

messageContent[index] =
ContentBlock.ofToolUse(
oldContentBlock
.asToolUse()
.toBuilder()
// Anthropic Streaming Messages API: "the final `tool_use.input`
// is always an _object_." However, if a tool function has no
// arguments, the concatenated `inputJson` can be an empty
// string. In that case, interpret it as a missing field.
.input(
if (inputJson.trim() == "") JsonMissing.of()
else
JSON_MAPPER.readValue(inputJson, JsonObject::class.java)
when {
oldContentBlock.isToolUse() ->
ContentBlock.ofToolUse(
oldContentBlock
.asToolUse()
.toBuilder()
// Anthropic Streaming Messages API: "the final
// `tool_use.input` is always an _object_."
// However, if a tool function has no arguments, the
// concatenated `inputJson` can be an
// empty string. In that case, interpret it as a missing
// field.
.input(parsedInput)
.build()
)
.build()
)
oldContentBlock.isServerToolUse() ->
ContentBlock.ofServerToolUse(
oldContentBlock
.asServerToolUse()
.toBuilder()
// See note above about empty `inputJson`.
.input(parsedInput)
.build()
)
else -> oldContentBlock // Should never happen given tracksToolInput
// check
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ private constructor(
mutableMapOf(),
)

fun toParam(): BetaCitationCharLocationParam =
BetaCitationCharLocationParam.builder()
.citedText(_citedText())
.documentIndex(_documentIndex())
.documentTitle(_documentTitle())
.endCharIndex(_endCharIndex())
.startCharIndex(_startCharIndex())
.build()

/**
* @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ private constructor(
mutableMapOf(),
)

fun toParam(): BetaCitationContentBlockLocationParam =
BetaCitationContentBlockLocationParam.builder()
.citedText(_citedText())
.documentIndex(_documentIndex())
.documentTitle(_documentTitle())
.endBlockIndex(_endBlockIndex())
.startBlockIndex(_startBlockIndex())
.build()

/**
* @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ private constructor(
mutableMapOf(),
)

fun toParam(): BetaCitationPageLocationParam =
BetaCitationPageLocationParam.builder()
.citedText(_citedText())
.documentIndex(_documentIndex())
.documentTitle(_documentTitle())
.endPageNumber(_endPageNumber())
.startPageNumber(_startPageNumber())
.build()

/**
* @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ private constructor(
@JsonProperty("url") @ExcludeMissing url: JsonField<String> = JsonMissing.of(),
) : this(citedText, encryptedIndex, title, type, url, mutableMapOf())

fun toParam(): BetaCitationWebSearchResultLocationParam =
BetaCitationWebSearchResultLocationParam.builder()
.citedText(_citedText())
.encryptedIndex(_encryptedIndex())
.title(_title())
.url(_url())
.build()

/**
* @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
Expand Down
Loading