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
All Implemented Interfaces:
Client, LLMClient
Direct Known Subclasses:
AnthropicBedrockMantleSDKClient

public class AnthropicBedrockSDKClient extends AnthropicSDKClient
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:
  • Constructor Details

    • AnthropicBedrockSDKClient

      public AnthropicBedrockSDKClient()
    • AnthropicBedrockSDKClient

      protected AnthropicBedrockSDKClient(com.anthropic.backends.Backend backend)
      Shared by the Bedrock endpoint variants. AnthropicBedrockMantleSDKClient passes a BedrockMantleBackend here; 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

      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).
      Overrides:
      doSingleResponse in class AnthropicSDKClient
      Parameters:
      request - the LLM request
      prepared - 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: AnthropicSDKClient
      Streaming implementation. Parses message_start for initial input + cache counters and the message ID; message_delta for the final output_tokens and stop_reason; content-block deltas for text. Populates the response via LLMResponse.setAdditiveUsage(int, Integer, Integer, int) once the stream completes. rateLimitInfo is not populated on streaming because the SSE transport doesn't expose HTTP response headers.
      Overrides:
      doStreamResponse in class AnthropicSDKClient
    • getDialect

      public APIDialect getDialect()
      Description copied from class: AbstractLLMClient
      Gets the API dialect for this client. Used to determine encoding strategies and compatibility.
      Specified by:
      getDialect in interface LLMClient
      Overrides:
      getDialect in class AnthropicSDKClient
      Returns:
      the API dialect
    • setModel

      public void setModel(ModelSpec modelInfo)
      Uses Bedrock model ID format.
      Specified by:
      setModel in interface Client
      Overrides:
      setModel in class AnthropicSDKClient
    • is429Error

      protected boolean is429Error(Exception e)
      Bedrock surfaces two different 429 shapes depending on which layer hits the limit. Anthropic's own TPM/RPM check is proxied through Bedrock as com.anthropic.errors.RateLimitException with message "429: Too many tokens..." - this is the common case, and the parent's message-based detector already catches it. AWS-side throttling appears as ThrottlingException / ServiceQuotaExceededException in 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:
      is429Error in class AnthropicSDKClient
      Parameters:
      e - the exception to check
      Returns:
      true if this is a rate limit error