Menu

Call Count Rate Limiter

The Call Count rate limiter is the simplest and most commonly used rate limiter in ApiCharge. It restricts the total number of API calls a client can make during an ApiCharge Subscriptions by counting each request.

Best Use Case: Call Count is ideal for REST APIs and other request-based services where you want to limit the total number of invocations.

How It Works

The Call Count rate limiter works by:

  1. Starting with a configured maximum number of calls (the Count property)
  2. Tracking each request made to the API as one "permit" used
  3. Rejecting requests once the total call count is reached

Unlike other rate limiters, Call Count is not time-sensitive within the subscription duration. It tracks the absolute number of calls regardless of how quickly they are made. Once the limit is reached, no more calls are allowed until a new subscription is purchased.

Feature Capabilities

The Call Count rate limiter provides these key capabilities:

Configuration

To configure a Call Count rate limiter in your quote definition, use the following syntax:

{
  "ApiChargeQuotes": {
    "Quotes": [
      {
        "RouteId": "basic-api",
        "Duration": 3600,
        "MicroUnitPrice": 100000,
        "RateLimiters": [
          {
            "$type": "CallCount",
            "Count": 100
          }
        ]
      }
    ]
  }
}

In this example:

Multiple Tier Example

You can create multiple service tiers with different call count limits:

{
  "ApiChargeQuotes": {
    "Quotes": [
      {
        "RouteId": "api-service",
        "Duration": 3600,
        "MicroUnitPrice": 50000,
        "RateLimiters": [
          {
            "$type": "CallCount",
            "Count": 100
          }
        ]
      },
      {
        "RouteId": "api-service",
        "Duration": 3600,
        "MicroUnitPrice": 200000,
        "RateLimiters": [
          {
            "$type": "CallCount",
            "Count": 1000
          }
        ]
      },
      {
        "RouteId": "api-service",
        "Duration": 3600,
        "MicroUnitPrice": 500000,
        "RateLimiters": [
          {
            "$type": "CallCount",
            "Count": 10000
          }
        ]
      }
    ]
  }
}

This configuration creates three tiers of service (Basic, Premium, and Enterprise) with increasing call limits at different price points.

Response When Limit Is Reached

When a client reaches the Call Count limit, ApiCharge responds with:

Clients should handle this status code and either wait for the next subscription period or purchase a new subscription with a higher limit.

Performance Considerations

The Call Count rate limiter is the most lightweight of all rate limiters in ApiCharge:

Tip: For high-volume APIs, consider combining Call Count with DataLimit rate limiters to prevent abuse scenarios where clients could make few but extremely large requests.

Use Cases

REST API Monetization

The most common use case is for REST APIs where each API call represents a distinct operation that has a specific cost. For example:

Function-as-a-Service (FaaS)

For serverless function endpoints, the Call Count limiter can directly correlate to execution costs:

Mixed with Other Rate Limiters

Call Count is often combined with other rate limiters to create comprehensive QoS controls:

{
  "RouteId": "ai-inference",
  "Duration": 86400,
  "MicroUnitPrice": 1000000,
  "RateLimiters": [
    {
      "$type": "CallCount",
      "Count": 1000
    },
    {
      "$type": "DataLimitUpload",
      "Bytes": 104857600
    }
  ]
}

This configuration limits both the number of calls (1,000) and the total upload data (100 MB), providing protection against both frequent small requests and infrequent large requests.

Next Steps

Now that you understand the Call Count rate limiter, you can explore other rate limiter types: