Events API

The Events API is the core of CLIMeter. Every tool invocation generates an event that drives metering, analytics, and billing. The SDK calls these endpoints automatically — use the raw API only if you need custom integration.

POST /v1/events

Record a single metering event. Requires a valid JWT in the Authorization header.

curl
Bash
curl -X POST https://api.climeter.ai/v1/events \
  -H "Authorization: Bearer <your-jwt>" \
  -H "Content-Type: application/json" \
  -d '{
    "tool_id": "code-search",
    "duration_ms": 142,
    "success": true,
    "metadata": {
      "query_length": 42,
      "results_count": 8
    }
  }'
example.py
Python
import os
import requests

# Get a JWT via POST /v1/auth/login first
response = requests.post(
    "https://api.climeter.ai/v1/events",
    headers={
        "Authorization": f"Bearer {jwt_token}",
        "Content-Type": "application/json",
    },
    json={
        "tool_id": "code-search",
        "duration_ms": 142,
        "success": True,
        "metadata": {"query_length": 42, "results_count": 8},
    },
)
print(response.json())
Use the SDK
The Python SDK handles authentication and event batching automatically. Use the raw API only for custom integrations or languages without an official SDK.

Schema

FieldTypeRequiredDescription
tool_idstringYesTool slug (e.g., "code-search")
duration_msintegerNoExecution time in milliseconds
successbooleanNoWhether the call succeeded (default: true)
metadataobjectNoCustom key-value pairs (max 10 keys, 256 chars per value)
timestampISO 8601 stringNoEvent time (default: server time)
idempotency_keystringNoUnique key to prevent duplicate recording
Timestamp limits
Events older than 24 hours are rejected with 422 Unprocessable Entity. Future timestamps are normalized to the current server time.

Response format

JSON
{
  "event_id": "evt_01HXZ9M3K7P8Q2R4T5V6W7X8Y",
  "tool_id": "code-search",
  "status": "recorded",
  "timestamp": "2025-03-07T12:34:56.789Z"
}

Error codes

HTTP statusCodeDescription
400invalid_requestMissing required fields or malformed JSON
401unauthorizedInvalid or expired JWT token
404tool_not_foundtool_id does not match any registered tool
422event_expiredEvent timestamp older than 24 hours
429rate_limit_exceededExceeded 100 req/sec per API key. See X-RateLimit-Remaining header. Retry after Retry-After seconds.
500server_errorTransient error — retry with backoff
Events API — CLIMeter Docs