Our account gets rate-limit responses, but Moralis doesn't detect any errors

I’ve been speaking to Kresimir about an issue we’re seeing on our account: we frequently get rate limit responses when we call the Moralis API:

Error: This Moralis Server is rate-limited because of the plan restrictions. See the details about the current rate and throttle limits: {}

But Kresimir asked engineering to look at our account, and they didn’t report seeing any rate-limiting on our account! Can you let me know if this descrepancy is on our side or on yours?

This is an example of how we’re detecting rate limit responses:

async function rateLimit<T>(cb: () => Promise<T>): Promise<T> {
  try {
    if (Date.now() - rateLimitedAt < 120 * 1000) {
      throw new Error('Moralis rate limit has been hit, skipping request.');
    }
    return await cb();
  } catch (err) {
    if (
      `${err}`.includes('Could not fetch keys') ||
      `${err}`.includes('Moralis Server is rate-limited')
    ) {
      rateLimitedAt = Date.now();
    }
    throw err;
  }
}

export const loadTokenBalancesFor = async (wallet: Wallet) => {
  const tokenBalances = await rateLimit(async () => {
    return await Moralis.Web3API.account.getTokenBalances({
      chain: 'eth',
      address: wallet.publicKey,
    });
  });
  return tokenBalances.map(b => ({
    communityAddress: b.token_address,
    tokenBalance: Number(applyDecimals(b.balance, b.decimals)),
  }));
};

Can you send in DM to Kresimir the api key that you are using?

This is not a standard error message for our api from what I know.

Can you print the exact error message and a status code?

This is the error we’re getting, according to our logs:

Feb 08 07:52:32 daylight-api-prod app/web.1  Moralis rate limit started: Error: This Moralis Server is rate-limited because of the plan restrictions. See the details about the current rate and throttle limits: {}

Kresimir already has our API key, he said he forwarded it along!

You get that error for this call?

Also in case it wasn’t clear: we’re using the Moralis Node API

EDIT: The SDK, version 1.7.0

Yes, and Moralis.Web3API.account.getNFTs.

I checked again now and we don’t save the rate limit errors in order to be able to check on our side now, I did find some 500 errors, not too many.

  {
    "endpoint": "getTokenBalances",
    "path": "/{address}/erc20",
    "price": 5,
    "rateLimitCost": 5
  },

How many requests you make per second to that endpoint?

We don’t keep close track of the number of requests per second: we’re adding that metric right now.

Or method for dealing with rate limits is in the code block:

  • Make requests until we get a rate-limit response from the API
  • Wait 2 minutes before resuming responses

2 minutes is probably too long – how long should we wait? And do you suggest a better way of doing this?

It should be enough to wait 1-2 seconds as the rate limit is only per second now.