Kobaru
  1. Core Concepts
Kobaru
  • Kobaru.io Gateway API
    • Introduction
      • What is Kobaru?
      • Quick start
      • How x402 works
    • Integration
      • Standard x402 SDK
      • Advanced SDK
      • Transparent proxy integration
      • Direct API integration
    • Core Concepts
      • Available Chains and Assets
      • Payment schemes
      • Security
      • Usage models
    • Guides
      • Pricing your API
      • Going to Production
      • Testing with devnet
      • Bazaar discovery
    • API Reference
      • Error Handling
      • Get Supported Payment Kinds
      • Verify Payment Authorization
      • Settle Payment
    • Discovery
      • List Discovery Resources
    • Schemas
      • SupportedResponse
      • ErrorResponse
      • UnauthorizedResponse
      • RateLimitResponse
      • VerifySuccessResponse
      • VerifyErrorResponse
      • SettleSuccessResponse
      • SettleErrorResponse
      • DiscoveryResourceItem
      • ListDiscoveryResourcesResponse
  1. Core Concepts

Usage models

Usage models#

Usage models define how clients consume their purchased API access. Kobaru supports two models: pay-per-request and pay-per-time.

Overview#

When a client pays for API access, they receive a usage allocation. The usage model determines how that allocation is consumed:
ModelHow it worksBest for
Pay-per-requestEach request decrements a counterVariable usage patterns
Pay-per-timeUnlimited requests within a time windowHigh-frequency access

Pay-per-request#

Clients purchase a bundle of requests. Each successful API call consumes one request from their balance.

Configuration#

{
  "extensions": {
    "usage": {
      "model": "pay_per_request",
      "limit": 10,
      "unit": "request"
    }
  }
}

How it works#

1.
Client pays and receives 10 requests
2.
Each successful request decrements the counter (10 → 9 → 8...)
3.
When counter reaches 0, access is denied
4.
Client must pay again for more requests

Tracking#

Usage is tracked atomically in Redis:
Key: usage:{paymentHash}:remaining
Operation: DECR on each request
Thread-safe across all edge locations

Refunds#

If your backend returns an error, Kobaru automatically refunds the request:
Status codeRefunded?Reason
200-299NoSuccessful response
400, 404, 422NoClient error
401, 403YesUpstream auth error
429YesUpstream rate limit
500-599YesServer error
Example: Client has 8 requests remaining. Your API returns 500. Kobaru refunds the request, so they still have 8 remaining.

Pay-per-time#

Clients purchase unlimited access for a specified duration. The clock starts on first use.

Configuration#

{
  "extensions": {
    "usage": {
      "model": "pay_per_time",
      "limit": 3600,
      "unit": "second"
    }
  }
}

How it works#

1.
Client pays and receives a 1-hour access window
2.
Timer starts on the first request
3.
Unlimited requests allowed until timer expires
4.
After expiration, access is denied

Tracking#

Activation is tracked in Redis:
Key: usage:{paymentHash}:activated
Value: Activation timestamp
TTL: Automatically expires after the time limit

No refunds#

Time-based access is not refundable. Once the timer starts, the time elapses regardless of usage or errors.

Choosing a usage model#

Use pay-per-request when:#

Usage varies significantly between clients
You want to charge proportionally to consumption
Clients make occasional, valuable requests
You want to offer refunds for errors

Use pay-per-time when:#

Clients need high-frequency access
Usage is predictable and consistent
You want to reduce payment friction
Simplicity is more important than precise billing

Configuration examples#

Per-request bundle#

Sell 100 requests for $0.10:

Time-based access#

Sell 1 hour of unlimited access for $1.00:

Usage in the proxy#

When using the transparent proxy, configure usage models in the Kobaru Console:
1.
Go to Services > Routes
2.
Select your route
3.
Set Usage model to pay_per_request or pay_per_time
4.
Set Limit (requests or seconds)

Related documentation#

Transparent proxy - Automatic usage tracking
Pricing guide - Setting prices for your API
Security - How usage tracking prevents abuse
Modified at 2026-01-04 13:59:25
Previous
Security
Next
Pricing your API
Built with