Developers

Public API rate limits

How the Costfluent Public API limits each token's requests, and how to back off when it answers 429.

Each API token has its own request budget per minute and per hour, and the tokens of one organization also share one budget per minute, so creating more tokens does not multiply what an organization may send. A busy integration on one token slows another only once the organization's shared budget is spent. A request without a token shares one budget with every other anonymous caller.

Yes No No Yes A request Carriesa token? Its token's budget,per minute and per hour The budget its organization'stokens share, per minute The budget everyanonymous caller shares Over abudget? The operation runs Refused with 429
A request with a token spends its token's own budgets and the per-minute budget its organization's tokens share; one without a token shares a budget with every other anonymous caller. A request over a budget is refused with 429.

A SCIM connection's token has a provisioning budget of its own on the SCIM base URL, per minute and per hour. The SCIM connections of one organization share it, and it is apart from the budgets above, so provisioning and the organization's API tokens never spend each other's budget. Anywhere else the SCIM token is on the budgets above like every other token. A request to the SCIM base URL that is refused answers 429 as a SCIM error, application/scim+json, with the same four headers as below.

When a request is refused

A request over the budget answers 429 with the error body, code rate_limit_exceeded and retryable true. Its detail names the limit and its window. Four headers say when to try again:

HeaderValue
RateLimit-LimitThe requests the window that refused this one allows.
RateLimit-RemainingThe requests left in that window: 0.
RateLimit-ResetSeconds until the window lets a request through again.
Retry-AfterThe same seconds as RateLimit-Reset.

Back off

  1. On a 429, read Retry-After, or RateLimit-Reset when a proxy dropped it.
  2. Wait that many seconds, then send the same request again.
  3. When the wait is long, such as most of an hour, the hourly budget is spent: stop and resume later rather than holding the request open.

The Terraform provider does this for you: it waits out a short Retry-After and reports a long one as an error.

Cost reads at the same time

Apart from the request budget, each organization may run only a few reads of cost data at the same time, so heavy reporting in one organization cannot take the capacity another needs. This bound counts reads that are running, not requests per minute, and it belongs to the organization: reads sent with different tokens of one organization count together.

A cost read that finds all of its organization's reads taken waits a few seconds for one to finish. When none finishes in time, it answers 429 with the same code, retryable true and the same four headers, but they mean something different from a refusal by the request budget:

  • RateLimit-Limit is the number of cost reads the organization may run at once, not a number of requests per window.
  • Retry-After and RateLimit-Reset are a few seconds. The read can pass as soon as one of the organization's running reads finishes, so a refusal here does not mean the organization's request budget is spent.

To stay clear of this bound:

  • Honour Retry-After as for any other 429: wait that many seconds, then send the same read again.
  • Avoid running many heavy cost reads in parallel from one organization. Send them one after another, or a few at a time, whether they come from one integration or several.

Cost submissions at the same time

A cost submission to a custom provider, POST /v1/custom-providers/{providerId}/costs, and a business metric values import, POST /v1/business-metrics/{metricId}/values, can take much of an API server's memory at their limits, so each API server processes one of them at a time, for every organization together. This bound counts the submissions being processed, not requests per minute.

A submission that finds another being processed waits up to 15 seconds for its turn. When several wait, the one whose organization's owner has used the turn least goes next, so one owner's organizations cannot keep everyone else's out. When its turn has not come within that wait, it answers 429 with the same code, retryable true and the same four headers, and nothing of it is imported:

  • RateLimit-Limit is 1, the submissions processed at once, not a number of requests per window.
  • Retry-After and RateLimit-Reset are 30 seconds.

Once its turn starts, the request body has 10 seconds to arrive. A body still arriving after that answers 408 with code request_timeout and retryable true, and nothing of it is imported. A request that declares a body larger than its operation takes under Request size answers 413 at once, without waiting for a turn.

To stay clear of this bound:

  • Send submissions one after another rather than in parallel, whether to one custom provider or several, and from one organization or several.
  • Honour Retry-After as for any other 429.
  • Send a large feed as a file to POST /v1/custom-providers/{providerId}/uploads instead, as Custom provider describes. An upload does not wait for this turn.

Invitation budget

Inviting a user with POST /v1/users spends a third budget, kept per organization over any 24 hours: at most 100 invitations from the organization, and at most 3 to one address. Resending an invitation in the product spends the same budget, and every token of the organization and every person in it share it. Past either limit the invitation is refused with 429, the same code, retryable true and the same four headers, which here mean:

  • RateLimit-Limit is the invitations allowed in 24 hours: 100 for the organization, or 3 for the address.
  • Retry-After and RateLimit-Reset are the seconds until the oldest of those invitations is 24 hours old, up to 86,400.

A long wait here means the invitation budget is spent, not the hourly request budget: every other request still passes. Do not hold the invitation open; send it again after the wait, or invite the remaining people the next day.

Connection removals

Removing a connection with DELETE /v1/providers/{providerId}, or removing a connection or a Kubernetes cluster in the product, spends a budget kept per organization over any hour: at most 120 removals, and every token of the organization and every person in it share it. Past it the removal is refused with 429, the same code, retryable true and the same four headers, which here mean:

  • RateLimit-Limit is the removals allowed in an hour: 120.
  • Retry-After and RateLimit-Reset are the seconds until the oldest of those removals is an hour old, up to 3,600.

A refused removal removes nothing, and every other request still passes; adding connections is not limited by it. Remove the connection again after the wait.

Kubernetes report volume

The Kubernetes agent's reports to POST /v1/kubernetes/reports spend a budget of their own, kept per organization for each UTC day: the organization's clusters together store at most 1,024 MiB of compressed reports a day, each report counted on the day it is accepted. A report that would take the day past it is refused with 429, the same code, retryable true and the same four headers, which here mean:

  • RateLimit-Limit is the budget in MiB: 1024.
  • Retry-After and RateLimit-Reset are the seconds until the next midnight UTC, when the budget starts again.

A long wait here means the organization's report volume for the day is spent, not the hourly request budget: every request other than a report still passes. The agent keeps a refused report and sends it again, as Kubernetes describes.

Custom provider uploads

Every organization's file uploads to a custom provider, POST /v1/custom-providers/{providerId}/uploads, wait for the same upload workers, so an organization has at most 5 uploads waiting or being processed at once, whichever of its tokens or people sent them. An upload deleted before it finished keeps its place for 5 minutes after the delete, while what it imported is removed. A further upload is refused with 429, the same code, retryable true and the same four headers, and nothing of it is stored. So is an upload sent once the organization's custom providers have imported as many cost records or bytes as they may in a UTC day, uploads and API submissions together.

Every CSV upload is unpacked in full before it can be refused, so an organization may also have at most 10 uploads in any 10 minutes that have not completed, counting CSV uploads only. A CSV upload counts from when it is sent until it completes, so one refused once it was unpacked, such as one that decompresses past its limit or whose files do not share one header, one failed in processing and one deleted before it finished keep counting until they are 10 minutes old. The next upload is refused with 429, the same code, retryable true and the same four headers, before it is unpacked. One refused before it is read, such as a file that is not .csv or .csv.gz, does not count, and neither does an upload to an e-invoice provider, which has its own limits in Import e-invoices. The headers here mean:

  • Past the uploads in flight, RateLimit-Limit is 5, the uploads waiting or being processed at once, not a number of requests per window, and the wait in Retry-After and RateLimit-Reset is 60 seconds.
  • With the day spent, Retry-After and RateLimit-Reset are the seconds until the next midnight UTC, when the budget starts again.
  • Past the uploads that have not completed, RateLimit-Limit is 10, and Retry-After and RateLimit-Reset are the seconds until the oldest of them is 10 minutes old.

A wait here means the organization's uploads are busy, its day is spent or too many of its recent uploads have not completed, not the hourly request budget: every other request still passes. Send the upload again once one of the five has finished, after midnight UTC, or, having fixed the files, after the wait, as the refusal's message says. Custom provider shows each upload's status.

Request size

A request body may be at most 2 MiB. That holds the largest filter any operation accepts when its values are in plain Latin letters and digits; a filter at every limit written in another script can be larger. The operations that carry data in bulk take more, and bound how many items a request holds:

OperationBodyItems
POST /v1/custom-providers/{providerId}/costs15 MB7,500 entries, each with at most 128 tags
POST /v1/business-metrics/{metricId}/values30 MB10,000 values, each with at most one label per label column (five at most)
POST /v1/custom-providers/{providerId}/uploads100 MBsee Custom provider
POST /v1/kubernetes/reports16 MiB compressedsent by the Kubernetes agent

A larger body answers 413 with code payload_too_large before the operation runs. A list past its count answers 400, and errors names the list, such as costs or costs[1].tags, with the reason At most 128 items. Neither is retryable. Split a long list over several requests; an entry with more tags or labels than its limit is refused however the request is split, so it has to carry fewer.

How it behaves

  • The budget belongs to the token, and the shared one to its organization, whatever client or address sends it. A header such as X-Client-Id does not open a new budget.
  • Only Authorization: Bearer carries a token. A token sent any other way, such as an X-Api-Key header, is not read, so an operation that needs a token answers 401.
  • A 429 is refused before the operation runs, so retrying it is safe for every method, a create included.
  • Reading cost data with limit=5000 costs one request per 5,000 rows; see Pagination.