Rate limits

Calls are counted in three buckets. Every read route is counted, the list routes included. A call that goes over a limit is refused with 429 rate-limited and nothing is done.

The numbers below are starting values. GroupApp can change them without notice. Do not hard-code them: read Retry-After and back off.

The buckets

Bucket Charged by Cost of one call
read GET /v1/bots, GET /v1/bots/{botId}, GET /v1/super-groups, GET /v1/super-groups/{superGroupId}, GET /v1/groups, GET /v1/posts, GET /v1/posts/{postId}, GET /v1/requests/{requestId}, and the first-party routes GET /v1/actions and POST /v1/actions/{tool} 1
command POST /v1/posts 1
send POST /v1/posts The number of groups the post goes to (see below)

Each bucket has two limits, and a call must be within both:

  • a limit for the system the key belongs to (all keys of the same "System that uses the key" and the same mode together), and
  • a limit for the key itself.
Bucket System limit Key limit Window
read 120 60 1 minute
command 30 20 1 minute
send 2000 1000 60 minutes

A window starts with the first call counted in it and ends after its length. The count then starts again from zero. It is a fixed window, not a sliding one, so bursts at a window edge are possible.

A post counts once in command and as many times in send as it has target groups. The read bucket applies to GET /v1/requests/{id} too, so polling costs read units, and so does every page of a list: following nextCursor costs 1 read unit per page.

Test keys

A ga_test_ key is limited like a live key, with the same numbers and the same costs, and its calls are counted in buckets of their own: test calls never use up the allowance of the live keys of the same system, and the other way round. A test send costs send units like a live one.

What a send costs

The send cost is the number of groups the message will go to:

Post Cost
targetIds The number of distinct ids. Repeated ids count once.
superGroupId The number of groups in the super group that receive posts, at the moment the post is accepted. At least 1.

A single post can cost more than a whole bucket. The cost is capped at the bucket's limit, so one large post passes when the bucket is empty and uses all of it.

Order of charges

Reads

A read call is charged 1 read unit, after the checks that need no lookup:

Step Costs
The key is checked. A 401 nothing
On the list routes and GET /v1/bots/{botId}, GET /v1/super-groups/{superGroupId}: an unknown or invalid query parameter, a limit out of range, or a bad cursor (400) nothing
The key's scope for the route. A 403 nothing
The read bucket is charged. If it refuses, the call is 429 and nothing stays charged 1
A bot that is not one of the key's bots, or does not exist (404), or that was retired (410) 1
On GET /v1/posts/{postId} and GET /v1/requests/{requestId}: a malformed id (404), then the lookup (404 when not found) 1
A successful read 1

So a read that is refused for its parameters or its scope is free, and a read that gets as far as the bot or the id costs 1 even when it ends in 404 or 410.

Posts

For POST /v1/posts:

  1. The key and its scope and role are checked. A 401 or 403 costs nothing.
  2. The command bucket is charged (1), before the body is read. A call with an invalid body still costs this unit.
  3. The Idempotency-Key header, the body, the bot (scope and retired) and wait are checked.
  4. The Idempotency-Key is looked up. A replay of an accepted post stops here: it costs the command unit only, and no send units.
  5. The send bucket is charged.
  6. If the post is then refused before it starts (for example, a target is refused), the send units are given back. The command unit stays charged.
  7. A post that was accepted keeps its send units, even if the send later fails.

When a bucket refuses a call, everything that call charged in that bucket is given back. A refused send charge also frees the Idempotency-Key, so you can retry it.

Within a bucket the system limit is checked first, then the key limit.

The 429 answer

HTTP/1.1 429 Too Many Requests
Content-Type: application/problem+json
Retry-After: 23
Request-Id: ...
{
  "type": "https://api.groupapp.co.il/docs/problems/rate-limited",
  "title": "Rate limit exceeded",
  "status": 429,
  "detail": "send rate limit exceeded",
  "instance": "/v1/posts",
  "code": "rate-limited",
  "requestId": "..."
}
  • Retry-After is the number of whole seconds until the window that refused the call ends. It is at least 1.
  • detail names the bucket: read rate limit exceeded, command rate limit exceeded or send rate limit exceeded. It does not say whether the system limit or the key limit was reached.
  • The API sends no RateLimit-* headers, so you cannot read your remaining allowance. Count your own calls, and back off on 429.

Good practice

  • Wait Retry-After seconds, then retry. Add a random delay so many clients do not return at the same moment.
  • Retry a POST /v1/posts with the same Idempotency-Key.
  • Poll a request no faster than its Retry-After (2 seconds), or use ?wait (see Idempotency and async requests).
  • If you need more room, ask GroupApp.