Errors and retries
Every v1 API error code, whether to retry it, and how to retry without double counting.
Every /api/v1 endpoint reports problems the same way, so one piece of error handling covers them all. Branch on error.code: it is stable. error.message is written for people and may change.
{ "error": { "code": "invalid_payload", "message": "The request body doesn't match the schema. See details.", "requestId": "req_9mVb2Kx7QwLp3TzA", "details": [{ "path": "params.plan", "issue": "too_long" }] }}details points at the field (path) and names the problem (issue). requestId is also sent in the Request-Id header. Log it, and include it if you contact support: it identifies the exact request.
Error codes
| Code | Status | Retry? | Meaning |
|---|---|---|---|
invalid_payload | 400 | No | The body isn't valid JSON, isn't application/json, or a field breaks a rule. See details. |
stale_event | 400 | No | The eventId or occurredAt is more than 24 hours old or more than 5 minutes ahead. |
unauthorized | 401 | No | The key is missing, unknown, or revoked. |
forbidden | 403 | No | The key is real but has the other purpose. Use a Custom events key for events and a Stripe attribution key for payments. |
identity_mode_limited | 409 | No | Payment attribution only: a visitorId was sent for a cookieless website. Send a userId instead. |
stripe_not_connected | 409 | No | Payment attribution only: connect Stripe for this website first. |
checkout_incomplete | 409 | No | Payment attribution only: the Checkout Session has no completed payment. |
payment_intent_unavailable | 409 | No | Payment attribution only: the connected Stripe account has no such payment. |
metadata_conflict | 409 | No | Payment attribution only: the payment is already linked to a different visitor or user. |
payload_too_large | 413 | No | The body is over the limit: 16 KB for one event, 256 KB for a batch. |
rate_limited | 429 | Yes | Too many requests. Wait for Retry-After. |
quota_exceeded | 429 | After Retry-After | The workspace reached its tracked-event limit. retryAfter in the body gives the same wait in seconds. |
internal_error | 500 | Yes | Something failed on Graytower's side. |
unavailable | 503 | Yes | A service Graytower depends on is briefly unavailable. Wait for Retry-After. |
Network errors, timeouts, and responses you can't read count as temporary: retry them.
How to retry
Retries are safe because each eventId counts once per website for 24 hours. Follow these rules:
| What happened | What to do |
|---|---|
accepted | Done |
duplicate | Done. Graytower already had the event, often from an earlier attempt whose response was lost. |
rejected in a batch, or a 4xx other than 429 | Don't retry. Log the code and details once, and fix the cause. |
rate_limited, unavailable, or any 5xx | Retry every unconfirmed event with the same eventIds, after Retry-After when it's present. |
quota_exceeded | Wait for Retry-After, then retry. Events sent before then are refused, not stored later. |
| Timeout, connection reset, unreadable response | Treat as temporary and retry with the same eventIds. |
Never generate a new eventId for a retry. A new ID is a new event: it counts again and uses more of your allowance.
Back off between attempts, for example 1, 2, 4, then 8 seconds, plus a little randomness, and stop after a few minutes. Because eventIds expire after 24 hours, an event queued for longer than that can no longer be sent.
Response headers
| Header | Meaning |
|---|---|
Request-Id | Unique per request. The same value as error.requestId. |
X-RateLimit-Limit | Requests allowed per minute for this website. |
X-RateLimit-Remaining | Requests left in the current minute. |
X-RateLimit-Reset | When the current minute ends, in Unix seconds. |
Retry-After | On 429 and 503: seconds to wait before retrying. |
Date | The server's clock. Compare it with yours when you see stale_event. |
A batch uses one request from the rate limit per event in it.
Clock problems
Only Graytower judges whether an event is too old or too far ahead, so don't drop events by your own clock. If new events get stale_event with issue: "in_future" or "too_old", compare details.serverTime with details.eventTime: a large gap means the clock of the machine that created the eventId is wrong. Enable time sync on that machine.