Class AnthropicBedrockSDKClient
java.lang.Object
ai.redouble.nucleo.harness.llm.AbstractRateLimitedClient
ai.redouble.nucleo.harness.llm.AbstractLLMClient<com.anthropic.models.messages.ContentBlockParam>
ai.redouble.nucleo.providers.anthropic.AnthropicSDKClient
ai.redouble.nucleo.providers.bedrock.anthropic.AnthropicBedrockSDKClient
- Direct Known Subclasses:
AnthropicBedrockMantleSDKClient
Anthropic Claude API client using AWS Bedrock as the backend.
Uses the official Anthropic Java SDK with BedrockBackend.
Key differences from direct API (AnthropicSDKClient):
- Uses AWS credentials instead of Anthropic API key
- Model IDs use Bedrock format:
anthropic.claude-opus-4-5-20251101-v1:0 - Rate limiting uses AWS throttling (ThrottlingException)
Credentials and region per BedrockClients: AWS's own resolution (the standard
variables, a profile, or the role the process runs under), or the deployment's store records
under BedrockClients.SECRET_ID and BedrockClients.REGION_ID.
- Since:
- 0.1 (2025-12-02)
- Author:
- Andrey Santrosyan
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractRateLimitedClient
AbstractRateLimitedClient.RateLimitedOperation<T> -
Field Summary
Fields inherited from class AnthropicSDKClient
anthropicModel, client, SECRET_ID, SHAPEFields inherited from class AbstractLLMClient
formatter, temperatureFields inherited from class AbstractRateLimitedClient
model -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAnthropicBedrockSDKClient(com.anthropic.backends.Backend backend) Shared by the Bedrock endpoint variants. -
Method Summary
Modifier and TypeMethodDescriptionprotected static software.amazon.awssdk.auth.credentials.AwsCredentialsProviderAWS credentials for either Bedrock surface, resolved exactly as the runtime client resolves them (BedrockClients.credentialsProvider()).protected static software.amazon.awssdk.regions.RegionThe deployment's Bedrock region, the same one for either surface.protected <T> LLMResponse<T> doSingleResponse(LLMRequest<T> request, PreparedConversation prepared) The Anthropic call, with a Bedrock reading of one failure the shared client cannot give: an unresolvable endpoint hostname means the model is not served in this deployment's region, because the region built the hostname (bedrock-mantle.<region>.api.aws).protected <T> voiddoStreamResponse(LLMRequest<T> request, LLMResponse<T> response, PreparedConversation prepared, Consumer<StreamChunk> chunkHandler) Streaming implementation.Gets the API dialect for this client.protected booleanBedrock surfaces two different 429 shapes depending on which layer hits the limit.voidUses Bedrock model ID format.Methods inherited from class AnthropicSDKClient
accountIdentifier, attachThinkingConfig, buildEncoders, buildMessageCreateParams, close, countTokensExact, createFormatter, extractRateLimitInfo, getAnthropicModel, isCachingSupported, isOverloadError, isQuotaError, isServerError, setAnthropicModel, textWrapperMethods inherited from class AbstractLLMClient
base, createOutgoingMessage, encodeBlock, estimateTokens, findUnknownHost, getCallerInfo, getFormatter, getModelIdentifier, getTemperature, isPromptTooLongError, prepareConversation, reasoningEffortFor, resolveWireMaxTokens, setTemperature, singleResponse, streamResponse, updateRateLimitsFromHeaders, validateEstimatedTokensMethods inherited from class AbstractRateLimitedClient
executeWithRateLimit, getModel, messageChainContains, quotaExhausted
-
Constructor Details
-
AnthropicBedrockSDKClient
public AnthropicBedrockSDKClient() -
AnthropicBedrockSDKClient
protected AnthropicBedrockSDKClient(com.anthropic.backends.Backend backend) Shared by the Bedrock endpoint variants.AnthropicBedrockMantleSDKClientpasses aBedrockMantleBackendhere; everything downstream of the backend - throttle classification, model resolution, rate-limit header extraction - is identical between the two surfaces, so it lives once, in this class.
-
-
Method Details
-
awsCredentialsProvider
protected static software.amazon.awssdk.auth.credentials.AwsCredentialsProvider awsCredentialsProvider()AWS credentials for either Bedrock surface, resolved exactly as the runtime client resolves them (BedrockClients.credentialsProvider()). An unreadable secret surfaces as the store's own unchecked failure: this client cannot be built at all. -
bedrockRegion
protected static software.amazon.awssdk.regions.Region bedrockRegion()The deployment's Bedrock region, the same one for either surface. -
doSingleResponse
The Anthropic call, with a Bedrock reading of one failure the shared client cannot give: an unresolvable endpoint hostname means the model is not served in this deployment's region, because the region built the hostname (bedrock-mantle.<region>.api.aws).- Overrides:
doSingleResponsein classAnthropicSDKClient- Parameters:
request- the LLM requestprepared- the prepared conversation, ready for provider-specific encoding- Returns:
- the LLM response
-
doStreamResponse
protected <T> void doStreamResponse(LLMRequest<T> request, LLMResponse<T> response, PreparedConversation prepared, Consumer<StreamChunk> chunkHandler) Description copied from class:AnthropicSDKClientStreaming implementation. Parsesmessage_startfor initial input + cache counters and the message ID;message_deltafor the finaloutput_tokensandstop_reason; content-block deltas for text. Populates the response viaLLMResponse.setAdditiveUsage(int, Integer, Integer, int)once the stream completes.rateLimitInfois not populated on streaming because the SSE transport doesn't expose HTTP response headers.- Overrides:
doStreamResponsein classAnthropicSDKClient
-
getDialect
Description copied from class:AbstractLLMClientGets the API dialect for this client. Used to determine encoding strategies and compatibility.- Specified by:
getDialectin interfaceLLMClient- Overrides:
getDialectin classAnthropicSDKClient- Returns:
- the API dialect
-
setModel
Uses Bedrock model ID format.- Specified by:
setModelin interfaceClient- Overrides:
setModelin classAnthropicSDKClient
-
is429Error
Bedrock surfaces two different 429 shapes depending on which layer hits the limit. Anthropic's own TPM/RPM check is proxied through Bedrock ascom.anthropic.errors.RateLimitExceptionwith message "429: Too many tokens..." - this is the common case, and the parent's message-based detector already catches it. AWS-side throttling appears asThrottlingException/ServiceQuotaExceededExceptionin the cause chain, which we detect here. Failing to catch either of these makes the job terminate hard instead of riding through the dispatcher's transparent retry loop.- Overrides:
is429Errorin classAnthropicSDKClient- Parameters:
e- the exception to check- Returns:
- true if this is a rate limit error
-