API Documentation

Calculate AI token costs programmatically. Free tier needs no API key. Upgrade to Pro for 1,000 calls/day.

Base URL

url
https://numstack.net

Authentication

Free tier requires no authentication. Pro/Enterprise: pass your API key via header.

http
X-API-Key: ns_pro_YOUR_KEY_HERE
# or
Authorization: Bearer ns_pro_YOUR_KEY_HERE

🔑 Get a Pro API key at /pricing

Rate Limits

TierDaily LimitResetPrice
Free10 callsMidnight UTCFree
Pro1,000 callsMidnight UTC$4/month
EnterpriseUnlimitedCustom

Rate limit headers returned on every response: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset

Endpoints

POST/api/calculators/token-cost

Calculate token costs for a single model or compare all models.

Request Body

json
{
  "model": "gpt-4o",          // Model ID — required unless compareAll: true
  "inputTokens": 1000,        // Number of input tokens per request — required
  "outputTokens": 500,        // Number of output tokens per request — required
  "requestsPerDay": 100,      // Requests per day for projections — default: 1
  "compareAll": false         // Set true to compare all models — ignores "model"
}

Single Model Example

bash
curl -X POST https://numstack.net/api/calculators/token-cost \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "inputTokens": 1000,
    "outputTokens": 500,
    "requestsPerDay": 100
  }'

Response

json
{
  "model": "gpt-4o",
  "name": "GPT-4o",
  "provider": "OpenAI",
  "query": { "inputTokens": 1000, "outputTokens": 500, "requestsPerDay": 100 },
  "costs": {
    "perRequest": 0.0075,
    "perDay": 0.75,
    "perWeek": 5.25,
    "perMonth": 22.5,
    "perYear": 273.75
  },
  "pricing": {
    "input_per_1m_tokens": 2.5,
    "output_per_1m_tokens": 10
  },
  "currency": "USD",
  "rateLimit": { "remaining": 9, "limit": 10, "resetAt": "2026-05-05T00:00:00.000Z" },
  "meta": {
    "calculator": "token-cost",
    "version": "1.0",
    "tier": "free",
    "pricingUpdated": "April 23, 2026",
    "source": "numstack.net"
  }
}

Compare All Models

bash
curl -X POST https://numstack.net/api/calculators/token-cost \
  -H "Content-Type: application/json" \
  -d '{
    "compareAll": true,
    "inputTokens": 1000,
    "outputTokens": 500,
    "requestsPerDay": 100
  }'

With Pro API Key

bash
curl -X POST https://numstack.net/api/calculators/token-cost \
  -H "Content-Type: application/json" \
  -H "X-API-Key: ns_pro_YOUR_KEY_HERE" \
  -d '{ "model": "claude-sonnet-4", "inputTokens": 2000, "outputTokens": 1000 }'
GET/api/v1/models

List all supported models and their pricing.

bash
curl https://numstack.net/api/v1/models

JavaScript / Node.js

javascript
const res = await fetch('https://numstack.net/api/calculators/token-cost', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': process.env.NUMSTACK_API_KEY, // optional, for Pro tier
  },
  body: JSON.stringify({
    model: 'gpt-4o',
    inputTokens: 1000,
    outputTokens: 500,
    requestsPerDay: 100,
  }),
});
const data = await res.json();
console.log(`Monthly cost: $${data.costs.perMonth}`);

Error Codes

StatusMeaning
400Bad Request — missing or invalid parameters
403Forbidden — calculator not available on your plan
404Model Not Found — check /api/v1/models for valid IDs
429Rate Limited — daily limit exceeded, see X-RateLimit-Reset
500Server Error — please report to [email protected]

Need more than 10 calls/day?

Pro gives you 1,000 calls/day, all calculators, no ads, and export. $4/month.

See Pricing →