API Reference

Base URL: https://api.getpaygentic.org/v1. Every request authenticates with a bearer token and returns JSON.

Authentication

Attach your API key to every request as a bearer token in the Authorization header:

Authorization: Bearer pyg_live_xxxxxxxxxxxxxxxxxxxxxx

Endpoints overview

Method Path Description Auth required Rate limit
POST /events Ingest one or more usage events Yes 1,000 events/s
GET /events Query ingested events with filters Yes 60 req/min
POST /customers Create or upsert a customer record Yes 120 req/min
GET /customers/:id Retrieve a customer by ID Yes 120 req/min
GET /customers/:id/usage Get aggregated usage for a customer Yes 60 req/min
POST /meters Create a new meter definition Yes 30 req/min
GET /meters List all meter definitions Yes 60 req/min
GET /billing-periods List billing periods for a customer Yes 60 req/min

POST /events

Ingests one or more events, up to 500 in a single request. A repeated idempotency key is accepted, then discarded rather than counted.

Request body

{
  "events": [
    {
      "idempotency_key": "string",   // required, unique per event
      "customer_id": "string",      // required
      "event_type": "string",       // required, your event type name
      "timestamp": "ISO 8601",     // required, UTC
      "trace_id": "string",        // optional, for multi-agent attribution
      "properties": {}              // optional key-value pairs
    }
  ]
}

Response

{
  "ingested": 1,
  "deduplicated": 0,
  "failed": 0
}

Example

curl -X POST https://api.getpaygentic.org/v1/events \
  -H "Authorization: Bearer pyg_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "idempotency_key": "agent-run-abc-001",
        "customer_id": "cust_9f3k2m",
        "event_type": "model_call",
        "timestamp": "2026-10-15T14:22:00Z",
        "properties": {
          "model": "claude-3-5-sonnet",
          "input_tokens": 1240,
          "output_tokens": 320
        }
      }
    ]
  }'

POST /customers

If no record matches the supplied id, one is created; if it does, that record is updated. The call is an upsert.

Request body

{
  "id": "string",          // required, your internal customer ID
  "name": "string",        // optional
  "email": "string",       // optional
  "metadata": {}         // optional key-value pairs
}

GET /customers/:id/usage

Returns aggregated totals for each meter belonging to the customer. With no query parameters the current billing period is used; pass period_start and period_end to read an earlier window.

Query parameters

Parameter Type Required Description
period_start ISO 8601 No Start of the query window (UTC)
period_end ISO 8601 No End of the query window (UTC)
meter_id string No Filter to a single meter

Response

{
  "customer_id": "cust_9f3k2m",
  "period_start": "2026-10-01T00:00:00Z",
  "period_end": "2026-11-01T00:00:00Z",
  "meters": [
    {
      "meter_id": "mtr_tokens",
      "display_name": "Token usage",
      "value": 4820000,
      "unit": "tokens"
    }
  ]
}

Error codes

HTTP status Code Meaning Action
400 invalid_event A required field is missing or a value is invalid Correct the event payload
401 unauthorized The API key is missing or not valid Check the key in the dashboard
429 rate_limited The endpoint's rate limit has been exceeded Retry with exponential backoff
500 internal_error An unexpected error on the server side Retry; contact support if it repeats

Idempotency

Each event's idempotency_key is what keeps a retry from being counted twice. Keys are scoped to your account and held for 72 hours. Send the same key again inside that window and the API answers with success, but nothing new is ingested.

Some jobs need a longer window, such as reprocessing historical data. The X-Idempotency-Window header takes a value in seconds, capped at 604800 (seven days).