Follow Discord
Sweep 22 Oct 2026 · 04:32Z Build v2.1.308 527 read Stable v2.1.308 Latest v2.1.308 Next v2.1.308 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

java changedcli-sdks-libraries/sdks/java

Nearest release: v2.1.307, published an hour after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+21added
Lines−21removed
From line 99 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits23to this page, all time

The whole hunk

from line 99, old and new numbered
/
lines
from line 99
9999 .build();
100100```
101101 
102For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) with access to multiple workspaces, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
102For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) that isn't scoped to a workspace, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
103103 
104104### Configuration options
105105 
from line 316
316316 
317317[Tool use with Claude](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) lets you integrate external tools and functions directly into the AI model's responses. Instead of producing plain text, the model can output instructions (with parameters) for calling a tool or function when appropriate. You define JSON schemas for tools, and the model uses the schemas to determine when and how to use these tools.
318318 
319The tool use feature supports a "strict" mode that guarantees that the JSON output from the AI model will conform to the JSON schema you provide in the input parameters.
319The tool use feature supports a "strict" mode that guarantees that the JSON output from the AI model conforms to the JSON schema you provide in the input parameters.
320320 
321321The SDK can derive a tool and its parameters automatically from the structure of an arbitrary Java class: the class's name (converted to snake case) provides the tool name, and the class's fields define the tool's parameters.
322322 
from line 381
381381 
382382### Calling tools
383383 
384When your tool classes are defined, add them to the message parameters using `MessageCreateParams.Builder.addTool(Class<T>)` and then call them if requested to do so in the AI model's response. `BetaToolUseBlock.input(Class<T>)` can be used to parse a tool's parameters in JSON form to an instance of your tool-defining class.
384After you define your tool classes, add them to the message parameters using `MessageCreateParams.Builder.addTool(Class<T>)` and then call them if requested to do so in the AI model's response. `BetaToolUseBlock.input(Class<T>)` can be used to parse a tool's parameters in JSON form to an instance of your tool-defining class.
385385 
386386After calling the tool, use `BetaToolResultBlockParam.Builder.contentAsJson(Object)` to pass the tool's result back to the AI model:
387387 
from line 432
432432 
433433### Tool name conversion
434434 
435Tool names are derived from the camel case tool class names (for example, `GetWeather`) and converted to snake case (for example, `get_weather`). Word boundaries begin where the current character is not the first character, is uppercase, and either the preceding character is lowercase, or the following character is lowercase. For example, `MyJSONParser` becomes `my_json_parser` and `ParseJSON` becomes `parse_json`. This conversion can be overridden using the `@JsonTypeName` annotation.
435Tool names are derived from the camel case tool class names (for example, `GetWeather`) and converted to snake case (for example, `get_weather`). Word boundaries start where the current character is not the first character, is uppercase, and either the preceding character is lowercase, or the following character is lowercase. For example, `MyJSONParser` becomes `my_json_parser` and `ParseJSON` becomes `parse_json`. This conversion can be overridden using the `@JsonTypeName` annotation.
436436 
437437### Local tool JSON schema validation
438438 
from line 565
565565 
566566The SDK throws custom unchecked exception types:
567567 
568* `AnthropicServiceException` - Base class for HTTP errors.
569* `AnthropicIoException` - I/O networking errors.
570* `AnthropicRetryableException` - Generic error indicating a failure that could be retried.
571* `AnthropicInvalidDataException` - Failure to interpret successfully parsed data (for example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it).
572* `AnthropicException` - Base class for all exceptions.
568* `AnthropicServiceException` - Base class for HTTP errors
569* `AnthropicIoException` - I/O networking errors
570* `AnthropicRetryableException` - Generic error indicating a failure that could be retried
571* `AnthropicInvalidDataException` - Failure to interpret successfully parsed data (for example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it)
572* `AnthropicException` - Base class for all exceptions
573573 
574574### Status code mapping
575575 
from line 615
615615Optional<String> requestId = message.requestId();
616616```
617617 
618This can be used to quickly log failing requests and report them back to Anthropic. For more information on debugging requests, see [Request ID](https://platform.claude.com/docs/en/api/errors#request-id).
618This can be used to log failing requests and report them back to Anthropic. For more information on debugging requests, see [Request ID](https://platform.claude.com/docs/en/api/errors#request-id).
619619 
620620## Retries
621621 
from line 629
629629* 429 Rate Limit
630630* 5xx Internal
631631 
632The API may also explicitly instruct the SDK to retry or not retry a request.
632The API might also explicitly instruct the SDK to retry or not retry a request.
633633 
634634To set a custom number of retries, configure the client using the `maxRetries` method:
635635 
from line 687
687687## Long requests
688688 
689689<Warning>
690 Consider using [streaming](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#streaming) for longer running requests.
690 Consider using [streaming](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#streaming) for longer-running requests.
691691</Warning>
692692 
693Avoid setting a large `maxTokens` value without using streaming. Some networks may drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#timeouts) without receiving a response from Anthropic. The SDK periodically pings the API to keep the connection alive and reduce the impact of these networks.
693Avoid setting a large `maxTokens` value without using streaming. Some networks might drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#timeouts) without receiving a response from Anthropic. The SDK periodically pings the API to keep the connection alive and reduce the impact of these networks.
694694 
695695The SDK throws an error if a non-streaming request is expected to take longer than 10 minutes. Using a [streaming method](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#streaming) or [overriding the timeout](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/java#timeouts) at the client or request level disables the error.
696696 
from line 832
832832These can be accessed on the built object later using the `_additionalHeaders()`, `_additionalQueryParams()`, and `_additionalBodyProperties()` methods.
833833 
834834<Warning>
835 The values passed to these methods overwrite values passed to earlier methods. For security reasons, ensure these methods are only used with trusted input data.
835 The values passed to these methods overwrite values passed to earlier methods. For security reasons, use these methods only with trusted input data.
836836</Warning>
837837 
838To set undocumented parameters on nested headers, query params, or body classes:
838To set undocumented parameters on nested headers, query parameters, or body classes:
839839 
840840```java
841841import com.anthropic.core.JsonValue;
from line 1037
10371037 
10381038The SDK consists of three artifacts:
10391039 
1040* `anthropic-java-core` - Contains core SDK logic, does not depend on OkHttp. Exposes `AnthropicClient`, `AnthropicClientAsync`, and their implementation classes, all of which can work with any HTTP client.
1040* `anthropic-java-core` - Contains core SDK logic and does not depend on OkHttp. Exposes `AnthropicClient`, `AnthropicClientAsync`, and their implementation classes, all of which can work with any HTTP client.
10411041* `anthropic-java-client-okhttp` - Depends on OkHttp. Exposes `AnthropicOkHttpClient` and `AnthropicOkHttpClientAsync`.
10421042* `anthropic-java` - Depends on and exposes the APIs of both `anthropic-java-core` and `anthropic-java-client-okhttp`. Does not have its own logic.
10431043 
from line 1192
11921192 .build();
11931193```
11941194 
1195Prefer the well-typed constants (for example, `Model.CLAUDE_OPUS_5`) so you get autocomplete and deprecation warnings. The `String` overloads and `of(...)` are primarily for setting the field to an undocumented or not yet supported value while waiting for an SDK release that includes it.
1195Prefer the well-typed constants (for example, `Model.CLAUDE_OPUS_5`) so you get auto-complete and deprecation warnings. The `String` overloads and `of(...)` are primarily for setting the field to an undocumented or not yet supported value while waiting for an SDK release that includes it.
11961196 
11971197## Beta features
11981198 
11991199Beta features are available before general release to get early feedback and test new functionality. You can check the availability of all of Claude's capabilities and tools in the [Features overview](https://platform.claude.com/docs/en/build-with-claude/overview).
12001200 
1201You can access most beta API features through the `beta()` method on the client. To enable a particular beta feature, add the appropriate [beta header](https://platform.claude.com/docs/en/api/beta-headers) with `.addBeta()` when building the message params.
1201You can access most beta API features through the `beta()` method on the client. To enable a particular beta feature, add the appropriate [beta header](https://platform.claude.com/docs/en/api/beta-headers) with `.addBeta()` when building the message parameters.
12021202 
12031203For example, to enable [context editing](https://platform.claude.com/docs/en/build-with-claude/context-editing):
12041204 
from line 1234
12341234 
12351235 * Allowing usage of undocumented API functionality
12361236 * Lazily validating the API response against the expected shape
1237 * Representing absent vs explicitly null values
1237 * Representing absent versus explicitly null values
12381238 </Accordion>
12391239 
12401240 <Accordion title="Why doesn't the SDK use data classes?">
from line 1249
12491249 * Are verbose to handle
12501250 * Encourage error handling at the wrong level of abstraction, where nothing can be done about the error
12511251 * Are tedious to propagate because of the function coloring problem
1252 * Don't play well with lambdas (also because of the function coloring problem)
1252 * Don't work well with lambdas (also because of the function coloring problem)
12531253 </Accordion>
12541254</AccordionGroup>
12551255 
from line 1259
12591259 
12601260This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backward-incompatible changes may be released as minor versions:
12611261 
12621. Changes to library internals which are technically public but not intended or documented for external use.
12621. Changes to library internals that are technically public but not intended or documented for external use.
126312632. Changes that aren't expected to impact the vast majority of users in practice.
12641264 
12651265## Additional resources
Feedback