How API access count works

My Wi-Fi module was off when I was hitting the turn on and off button. Subsequently I got an email stating that your API access has been rate limited.
My question is even when our device is turned off does the API count increases?
And also, it would be better if we can write some code that checks for the API count and alerts us before crossing the limit.

Hi @tahseen,

Below I am attaching the API Access Rules link for your reference.

Relating to the query that you have, API Call will be made depending on the code that you have written. Can you elaborate more on what project you are working on and send us the screenshot of the code so that we can help you out with this.

The API count depends on your usage of it. Even if the the device is off, the ‘on’ and ‘off’ buttons still make API calls which increase the counter and can get you rate-limited if it exceeds the limit. Spacing your API calls with a buffer of 10 seconds after each call is a safe option. However, if you want an api counter for say, when you make individual calls instead of running them in a loop, here is a python program for it.

from boltiot import Bolt
from datetime import datetime

myBolt = Bolt(<api key>, <device id>)    Your Bolt API and device ID here
calls = []
limit = 19
# The above call limit is as per the 1 minute rule. Set according to preference.

def a_Write():
    myBolt.<API call of choice>         # Add the API call you want to make
    now = datetime.now()
    ct = now.strftime("%H:%M:%S")
    hour = int(ct.split(":")[0])
    minute = int(ct.split(":")[1])
    second = int(ct.split(":")[2])

    if not len(calls):
        calls.extend([0, ct])

    else:
        hours_diff = abs(hour - int(calls[-1].split(":")[0]))

        if hours_diff >= 2:
            del calls[:-1]
            calls.insert(0, 0)
        else:
            if not hours_diff:
                carry = 0
            else:
                carry = 60
            minutes_diff = abs(minute + carry - int(calls[-1].split(":")[1]))

            if minutes_diff >= 2:
                del calls[:-1]
                calls.insert(0, 0)
            else:
                if not minutes_diff:
                    carry = 0
                else:
                    carry = 60
                seconds_diff = abs(second + carry - int(calls[-1].split(":")[2]))

        del calls[-1]
        calls.extend([seconds_diff, ct])

    if sum(calls[:-1]) >= 60:
        del calls[:-1]
        calls.insert(0, 0)
    if len(calls[:-1]) > limit:
        print(f"Warning! API count has crossed {limit} calls. Please wait {60 - sum(calls[:-1])} seconds to avoid getting rate limited.")