NAME

Langertha::RateLimit - Rate limit information from API response headers

VERSION

version 0.302

SYNOPSIS

my $response = $engine->simple_chat('Hello');

if ($response->has_rate_limit) {
    my $rl = $response->rate_limit;
    say "Requests remaining: ", $rl->requests_remaining // 'unknown';
    say "Tokens remaining: ", $rl->tokens_remaining // 'unknown';
    say "Reset in: ", $rl->requests_reset // 'unknown', " seconds";
}

# Access raw provider-specific headers
my $raw = $response->rate_limit->raw;

# Also available on the engine (always reflects latest response)
if ($engine->has_rate_limit) {
    say "Engine requests remaining: ", $engine->rate_limit->requests_remaining;
}

DESCRIPTION

Normalized rate limit data extracted from HTTP response headers. Different providers use different header naming conventions; this class provides a unified interface.

Supported providers:

  • OpenAI, Groq, Cerebras, OpenRouter, Replicate, HuggingFace (x-ratelimit-*)

  • Anthropic (anthropic-ratelimit-*)

Engines that do not return rate limit headers (DeepSeek, Ollama, vLLM, LlamaCpp, etc.) will not have a rate_limit set.

requests_limit

Maximum number of requests allowed in the current window.

requests_remaining

Number of requests remaining in the current window.

requests_reset

Time until the request limit resets. Format varies by provider (seconds, RFC 3339 timestamp, or epoch).

tokens_limit

Maximum number of tokens allowed in the current window.

tokens_remaining

Number of tokens remaining in the current window.

tokens_reset

Time until the token limit resets. Format varies by provider.

raw

HashRef of all rate-limit-related headers as returned by the provider. Useful for accessing provider-specific fields not covered by the normalized attributes (e.g. Anthropic's input-tokens-limit).

to_hash

my $hash = $rate_limit->to_hash;

Returns a flat HashRef of all defined rate limit fields plus the raw headers.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de> https://raudss.us/

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.