Error: cost limit exceeded


#1

When calling the stats/accounts/:account_id/campaigns endpoint, I’m sometimes getting the following response:

[{“message”: “Cost limit exceeded”, “code”: “COST_LIMIT_EXCEEDED”}]

This seems to have started happening around 4/22. I don’t see any cost limitation on this endpoint in the docs - can you clarify what is causing this error and how we can prevent it?

On a related note, I regularly make calls to get all campaign stats for a period of time in a given account. Currently I split my list of campaigns that were active during that period into chunks of 50 campaign IDs and call the API once per chunk. Many of these campaigns won’t have any stats during the period so this is very inefficient. Can you suggest a better approach for getting all campaign stats for an account efficiently?


#2

Hey Ben,

We rolled out a cost-based rate limiting scheme for our analytics endpoints on April 22nd. Those changes were announced in upcoming changes, which we would recommend that you subscribe to. This information is now contained in our analytics docs as well.

Personally, I think that following these types of changes on https://www.apichangelog.com/api/twitter is a great way to stay up-to-date on these types of changes, in addition to following Tweets from @AdsAPI.

In addition to the upcoming changes page, I would also suggest taking a look at our analytics best practices for tips on pulling stats and avoiding rate limits.

The quick points on this change include:

  • Rate limit windows changed from 15-minutes to 1-minute
  • Moved from a query-based rate limiting scheme to a cost-based rate limiting scheme
  • Ensure you write your code to detect rate limited calls that respond with a 429 and sleep until the end of the rate limiting window.

#3

Hi Jacob,

What is the rate limit? How many calls are allowed per minute?
Also - is there an overall daily quota?
Are these limits per User? App? Account?

Thanks,
Tali


#4

@TaliDolev,

These limits are cost-based, so there isn’t a set number of calls allowed per min. See the docs referenced in my previous comment for the details on the headers to determine what the limit is (it could differ based on the advertiser set-up).

All these limits remain user-based, just like our query rate limits and the limits are simply per-1-minute rate limit window, not per day.


#5

@bmorrismz @TaliDolev you can use the x-cost-rate-limit-reset header timestamp to reschedule your jobs.