↗

Errors and how to handle them

REST errors always return an error object; branch on code, not on the message text.

Format

{
  "error": {
    "code": "invalid_api_key",
    "message": "This API key does not exist or has been revoked.",
    "docs": "https://tokenearly.com/en/developers/errors"
  }
}

Every REST error uses this shape, including unknown paths (404 not_found), wrong HTTP methods (405 method_not_allowed) and server errors (5xx internal_error). MCP responses stay JSON-RPC: protocol problems (unknown tool, invalid arguments) are a JSON-RPC error; API errors (key, permission, rate limit and so on) come back as a tool result with isError: true whose content is the same {"error": {"code", "message"}}.

HTTP errors

codeHTTPMeaning and handling
missing_api_key401No key sent. Use Authorization: Bearer <key>.
key_expired401The trial key has expired. Apply for a new trial key, or subscribe and create a regular key.
invalid_api_key401The key does not exist, or it was reset or revoked.
plan_required403Your plan does not include the developer API, or this part of it.
ip_not_allowed403The key has an IP allowlist and the request came from an address outside it.
invalid_cursor400after / before is not a valid id (an event id for events, an alert id for my_alerts), both were sent, or (events only) updated_after was combined with before.
invalid_parameter400A parameter has the wrong type or value (e.g. limit out of range).
not_found404No event with this id in your topics (GET /v1/events/{id}), or the requested path does not exist (e.g. a mistyped endpoint).
method_not_allowed405The path exists but not for this HTTP method (e.g. POST /v1/events). REST endpoints are GET only; only MCP uses POST. The Allow header lists the supported methods.
rate_limited429Over this key's request rate (REST and MCP combined; the interval is limits.rest_interval_seconds in /v1/me); wait Retry-After seconds and retry.
internal_error500Server-side error (5xx, same format). Retry with exponential backoff (1, 2, 4… seconds, capped). During a brief restart you may also get 502 / 503 / 504 without a JSON body; retry them the same way.

Stream errors

The stream first sends an op = "error" message, then closes with the matching code; only invalid_message (a bad client frame) leaves the connection open:

codeClose codeMeaning and handling
missing_api_key4001No key sent. Use Authorization: Bearer <key>.
key_expired4001The trial key has expired. Apply for a new trial key, or subscribe and create a regular key.
invalid_api_key4001The key does not exist, or it was reset or revoked.
plan_required4003Your plan does not include the developer API, or this part of it.
ip_not_allowed4003The key has an IP allowlist and the request came from an address outside it.
invalid_cursor4400The after connection parameter is not a valid event id; closed with 4400. Fix it before reconnecting.
too_many_connections4029This key's stream connections are all in use (see limits.streams_per_key in /v1/me), so the new one is refused. Close the old connection, or give the other machine its own key.
invalid_messagestays openA WebSocket client frame was rejected: not a JSON object, no string op, an unknown op, or topics empty / not a list of strings. The connection stays open; fix the frame and resend.
slow_consumer4008Too many undelivered events; reconnect with after to resume.

When to retry

  • 429: wait Retry-After seconds, then retry.
  • 5xx and network errors: retry with exponential backoff (1, 2, 4… seconds, capped).
  • 401 / 403 / 400: do not retry; fix the key, plan or parameters first.