Response Envelope
Most JSON resource responses use the envelope described here. OAuth token responses, MCP JSON-RPC, event streams, and endpoints with an explicitly documented protocol response use their own shapes. Choose the parser for the endpoint you called.
Envelope Structure
interface ApiResponseEnvelope<T> {
data?: T;
meta?: ApiMeta;
error?: ApiError;
}A successful response includes data, and includes meta whenever the endpoint has pagination info or other metadata to report — meta is otherwise omitted, not null. An error response includes error and omits data.
Meta Object
interface ApiMeta {
requestId?: string; // Present on most responses; see "Request correlation" below
limit?: number; // Page size (list endpoints only)
offset?: number; // Current offset (offset-paginated endpoints only)
total?: number; // Total record count (offset-paginated endpoints only)
hasNextPage?: boolean; // Whether more records exist (list endpoints only)
nextCursor?: string; // Cursor for next page (cursor-paginated endpoints only)
}meta is assembled per endpoint — a single-record GET typically has no meta at all, while a list endpoint adds whichever pagination fields apply to it (offset-style or cursor-style, never both). There is no server-side timing field in the body; use the X-Request-Id header and your own client-side timing if you need to measure or report request duration.
Request correlation
Every request that reaches your endpoint's guards and handler gets a X-Request-Id response header, and — for error responses specifically — the same value in meta.requestId. A request rejected before authentication (for example, a missing bearer token) has no request ID yet at that point, so the X-Request-Id header is absent and meta is an empty object on that response. Include your own correlation ID in a X-Request-Id request header if you need one even for rejected requests — the API doesn't generate one until the request has passed initial auth.
Error Object
interface ApiError {
code: string; // Machine-readable error code, e.g. "bad_request", "not_found"
message: string; // Human-readable description
details?: any; // Additional context — shape varies by error type
}When an endpoint does not declare its own code, code is a lowercase snake_case value keyed to the HTTP status: bad_request, unauthorized, forbidden, not_found, request_timeout, conflict, unprocessable_entity, rate_limited, bad_gateway, service_unavailable, gateway_timeout, internal_server_error. Endpoints and shared guards also return more precise codes (for example entitlement_required, missing_idempotency_key or RATE_LIMITED). Codes keep the exact casing the API emits and are not all lowercase, so match them exactly. See Error Codes for the full list.
details is optional and its shape varies by error. In production it is present only when the endpoint attaches structured context (for example featureKey or retryAfterSeconds). Do not rely on details being present.
Examples
Single Record Success
GET /api/v1/ai/sessions/{id} returns 200 OK:
{
"data": {
"id": "00000000-0000-4000-8000-000000000001",
"title": "Research Assistant",
"status": "active",
"startedAt": "2026-10-21T08:00:00.000Z"
}
}Paginated List Success (Offset-based)
GET /api/v1/ai/sessions?limit=2&offset=0 returns 200 OK:
{
"data": [
{
"id": "00000000-0000-4000-8000-000000000001",
"title": "Research Assistant",
"status": "active"
},
{
"id": "00000000-0000-4000-8000-000000000002",
"title": "Developer Pipeline",
"status": "active"
}
],
"meta": {
"limit": 2,
"offset": 0,
"total": 12,
"hasNextPage": true
}
}Cursor-Paginated List Success
GET /api/v1/billing/invoices?limit=2 returns 200 OK:
{
"data": [
{
"id": "inv_001",
"amount": 1999,
"currency": "usd",
"status": "paid",
"createdAt": "2026-03-01T00:00:00.000Z"
},
{
"id": "inv_002",
"amount": 1999,
"currency": "usd",
"status": "paid",
"createdAt": "2026-02-01T00:00:00.000Z"
}
],
"meta": {
"limit": 2,
"hasNextPage": true,
"nextCursor": "<opaque-cursor>"
}
}To fetch the next page, include the cursor: GET /api/v1/billing/invoices?limit=2&cursor=<opaque-cursor>
Validation Error (400)
A request that fails body validation (a missing required field, a value that violates its constraints, or an unrecognized field) returns 400 Bad Request:
{
"error": {
"code": "bad_request",
"message": "password must be shorter than or equal to 128 characters; password should not be empty"
},
"meta": {
"requestId": "00000000-0000-4000-8000-000000000003"
}
}message is every violation joined with ; . There is no per-field structured breakdown: split message on ; if you need to inspect individual failures programmatically.
Rate Limit Error (429)
Endpoints with a rate limit return 429 Too Many Requests once it's exceeded:
{
"error": {
"code": "RATE_LIMITED",
"message": "Too many attempts. Please wait before trying again.",
"details": {
"retryAfterSeconds": 300
}
},
"meta": {}
}The wait is in details.retryAfterSeconds and in the Retry-After HTTP header (seconds until you can retry); X-RateLimit-Limit and X-RateLimit-Remaining are also set. The message varies by endpoint. A request rejected before it has a request ID has an empty meta object.