NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server

Counter API

The Counter API provides a integer counter service for your application. The counters are stored in our database and can be accessed via IDs unique to the provided API key.

For free users, counters are kept for 14 days.

For premium users, counters are retained indefinitely until it becomes inactive for 180 days, at which point it gets deleted.

(4.5)

From 5,189 users

1,800+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
199ms237ms295ms694ms1058ms

Didn't find what you were looking for? Suggest an improvement


/v1/counter GET

https://api.api-ninjas.com/v1/counter

Fetch and possibly update a counter.

Parameters

  • id  required

    ID to specify the counter. Use a new id to create a new counter.

  • hit  optional

    Whether to increase the count by 1. If used, must be set to true.

  • value  optional

    Set the count to a specific integer value. Setting the value to 0 resets the counter.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON object with the following fields or an error if the request is unsuccessful.

  • id

    The counter ID.

  • value

    The current counter value.

Sample Request Live Demo!

Try our APIs in the API playground

Sign up for a free API key to get started — no credit card required.

https://api.api-ninjas.com/v1/counter?id=test_id&hit=true

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
{
    id:"test_id",
    value:38
}

Code Examples

1 2 curl -X GET "https://api.api-ninjas.com/v1/counter?id=test_id&hit=true" \ -H "X-Api-Key: YOUR_API_KEY"

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the Counter API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.
  • The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.
  • Pass a unique id to create a new counter, then include hit set to true on each request to increase its count by 1; the response returns the id and current value. Sign up for a free API key to get started.
  • Yes, include the optional value parameter to set the counter to a specific integer, and set value to 0 to reset the counter. See the full parameter list on the Counter API documentation.
  • For free users, counters are kept for 14 days, while premium users have counters retained indefinitely until they become inactive for 180 days, at which point they are deleted.
  • No, counters are stored in our database and accessed via id values that are unique to your provided API key, so your counters are isolated to your account. Register to obtain your own key.