---
name: "Twitter::API::Trait::RateLimiting"
section: "3pm"
platform: "linux"
package: "libtwitter-api-perl"
version: "1.0006-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Twitter::API::Trait::RateLimiting"
---

# Twitter::API::Trait::RateLimiting(3pm)

Automatically sleep as needed to handle rate limiting

## NAME

Twitter::API::Trait::RateLimiting - Automatically sleep as needed to handle rate limiting

## VERSION

version 1.0006

## SYNOPSIS

```
    use Twitter::API;
    my $client = Twitter::API->new_with_options(
        traits => [ qw/ApiMethods RateLimiting/ ],
        %other_options,
    );
    # Use $client as normal
```

## DESCRIPTION

Twitter's API implements rate limiting in a 15-minute window, and will serve up an HTTP 429 error if the rate limit is exceeded for a window.  Applying this trait will give Twitter::API the ability to automatically sleep as much as is needed and then retry a request instead of simply throwing an exception.

## ATTRIBUTES

### rate\_limit\_sleep\_code

A coderef, called to implement sleeping.  It takes a single parameter - the number of seconds to sleep.  The default implementation is:

```
    sub { sleep shift }
```

## SEE ALSO

\<https://developer.twitter.com/en/docs/basics/rate-limiting\>

## AUTHOR

Marc Mims \<marc@questright.com\>

## COPYRIGHT AND LICENSE

This software is copyright (c) 2015-2021 by Marc Mims.

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