Class AnthropicRateLimit

java.lang.Object
org.springframework.ai.anthropic.metadata.AnthropicRateLimit
All Implemented Interfaces:
org.springframework.ai.chat.metadata.RateLimit

public class AnthropicRateLimit extends Object implements org.springframework.ai.chat.metadata.RateLimit
RateLimit implementation for the Anthropic SDK.

Parses Anthropic rate-limit response headers as documented at Anthropic rate limits. Beyond the request and token families exposed through the RateLimit contract, this class also surfaces the Anthropic-specific input-token and output-token buckets via dedicated getters.

Since:
2.0.0-M8
Author:
Gorre Surya, Soby Chacko
See Also:
  • Constructor Details

    • AnthropicRateLimit

      public AnthropicRateLimit(@Nullable Long requestsLimit, @Nullable Long requestsRemaining, @Nullable Duration requestsReset, @Nullable Long tokensLimit, @Nullable Long tokensRemaining, @Nullable Duration tokensReset, @Nullable Long inputTokensLimit, @Nullable Long inputTokensRemaining, @Nullable Duration inputTokensReset, @Nullable Long outputTokensLimit, @Nullable Long outputTokensRemaining, @Nullable Duration outputTokensReset)
  • Method Details

    • from

      public static org.springframework.ai.chat.metadata.RateLimit from(com.anthropic.core.http.Headers headers)
      Parses Anthropic rate-limit headers from the given Headers.
      Parameters:
      headers - the HTTP response headers
      Returns:
      an AnthropicRateLimit populated from the headers, or an EmptyRateLimit if no rate-limit headers are present
    • getRequestsLimit

      public Long getRequestsLimit()
      Specified by:
      getRequestsLimit in interface org.springframework.ai.chat.metadata.RateLimit
    • getRequestsRemaining

      public Long getRequestsRemaining()
      Specified by:
      getRequestsRemaining in interface org.springframework.ai.chat.metadata.RateLimit
    • getRequestsReset

      public Duration getRequestsReset()
      Specified by:
      getRequestsReset in interface org.springframework.ai.chat.metadata.RateLimit
    • getTokensLimit

      public Long getTokensLimit()
      Specified by:
      getTokensLimit in interface org.springframework.ai.chat.metadata.RateLimit
    • getTokensRemaining

      public Long getTokensRemaining()
      Specified by:
      getTokensRemaining in interface org.springframework.ai.chat.metadata.RateLimit
    • getTokensReset

      public Duration getTokensReset()
      Specified by:
      getTokensReset in interface org.springframework.ai.chat.metadata.RateLimit
    • getInputTokensLimit

      public @Nullable Long getInputTokensLimit()
      Returns the maximum number of input tokens allowed within the rate-limit window.
      Returns:
      the input tokens limit, or null if Anthropic did not return the header
    • getInputTokensRemaining

      public @Nullable Long getInputTokensRemaining()
      Returns the number of input tokens remaining within the current rate-limit window.
      Returns:
      the remaining input tokens, or null if Anthropic did not return the header
    • getInputTokensReset

      public @Nullable Duration getInputTokensReset()
      Returns the duration until the input-token rate-limit window resets.
      Returns:
      the duration until reset, or null if Anthropic did not return the header
    • getOutputTokensLimit

      public @Nullable Long getOutputTokensLimit()
      Returns the maximum number of output tokens allowed within the rate-limit window.
      Returns:
      the output tokens limit, or null if Anthropic did not return the header
    • getOutputTokensRemaining

      public @Nullable Long getOutputTokensRemaining()
      Returns the number of output tokens remaining within the current rate-limit window.
      Returns:
      the remaining output tokens, or null if Anthropic did not return the header
    • getOutputTokensReset

      public @Nullable Duration getOutputTokensReset()
      Returns the duration until the output-token rate-limit window resets.
      Returns:
      the duration until reset, or null if Anthropic did not return the header
    • toString

      public String toString()
      Overrides:
      toString in class Object