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:
-
RateLimit- Anthropic rate limits
-
Constructor Summary
ConstructorsConstructorDescriptionAnthropicRateLimit(@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 Summary
Modifier and TypeMethodDescriptionstatic org.springframework.ai.chat.metadata.RateLimitfrom(com.anthropic.core.http.Headers headers) Parses Anthropic rate-limit headers from the givenHeaders.@Nullable LongReturns the maximum number of input tokens allowed within the rate-limit window.@Nullable LongReturns the number of input tokens remaining within the current rate-limit window.@Nullable DurationReturns the duration until the input-token rate-limit window resets.@Nullable LongReturns the maximum number of output tokens allowed within the rate-limit window.@Nullable LongReturns the number of output tokens remaining within the current rate-limit window.@Nullable DurationReturns the duration until the output-token rate-limit window resets.toString()
-
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 givenHeaders.- Parameters:
headers- the HTTP response headers- Returns:
- an
AnthropicRateLimitpopulated from the headers, or anEmptyRateLimitif no rate-limit headers are present
-
getRequestsLimit
- Specified by:
getRequestsLimitin interfaceorg.springframework.ai.chat.metadata.RateLimit
-
getRequestsRemaining
- Specified by:
getRequestsRemainingin interfaceorg.springframework.ai.chat.metadata.RateLimit
-
getRequestsReset
- Specified by:
getRequestsResetin interfaceorg.springframework.ai.chat.metadata.RateLimit
-
getTokensLimit
- Specified by:
getTokensLimitin interfaceorg.springframework.ai.chat.metadata.RateLimit
-
getTokensRemaining
- Specified by:
getTokensRemainingin interfaceorg.springframework.ai.chat.metadata.RateLimit
-
getTokensReset
- Specified by:
getTokensResetin interfaceorg.springframework.ai.chat.metadata.RateLimit
-
getInputTokensLimit
Returns the maximum number of input tokens allowed within the rate-limit window.- Returns:
- the input tokens limit, or
nullif Anthropic did not return the header
-
getInputTokensRemaining
Returns the number of input tokens remaining within the current rate-limit window.- Returns:
- the remaining input tokens, or
nullif Anthropic did not return the header
-
getInputTokensReset
Returns the duration until the input-token rate-limit window resets.- Returns:
- the duration until reset, or
nullif Anthropic did not return the header
-
getOutputTokensLimit
Returns the maximum number of output tokens allowed within the rate-limit window.- Returns:
- the output tokens limit, or
nullif Anthropic did not return the header
-
getOutputTokensRemaining
Returns the number of output tokens remaining within the current rate-limit window.- Returns:
- the remaining output tokens, or
nullif Anthropic did not return the header
-
getOutputTokensReset
Returns the duration until the output-token rate-limit window resets.- Returns:
- the duration until reset, or
nullif Anthropic did not return the header
-
toString
-