API Overview

Last updated 12 days ago

j17's API is HTTP-first and minimal. POST events, GET aggregates. That's the core. Everything else -- batching, admin, implications -- is built on these primitives.

Base URLs

Production:  https://{instance}.j17.dev
Staging:     https://{instance}-staging.j17.dev
Test:        https://{instance}-test.j17.dev

All requests require HTTPS.

Authentication

Two methods depending on what you're doing:

Method Header Use for
API Key Authorization: Bearer {key} Instance data (events, aggregates)
JWT Authorization: Bearer {token} Admin operations, dashboards

See Authentication for details.

Core operations

Write an event

POST /{aggregate_type}/{aggregate_id}/{event_type}
curl -X POST https://myapp.j17.dev/order/abc123/was_placed \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "data": { "items": [...], "total": 59.99 },
    "metadata": {
      "actor": { "type": "user", "id": "550e8400-e29b-41d4-a716-446655440000" }
    }
  }'

Returns the stream ID of the written event.

Read an aggregate

GET /{aggregate_type}/{aggregate_id}
curl https://myapp.j17.dev/order/abc123 \
  -H "Authorization: Bearer $API_KEY"

Returns current state derived from all events.

Batch operations

POST /{aggregate_type}/{aggregate_id}

Atomic multi-event writes to a single aggregate. See Batch operations.

Inspect erasure requests

The Erasure Requests API provides an authenticated read-only preview of request status, recorded progress, lifecycle history and support guidance. Requests are isolated by instance and environment.

Request format

Event POST body

{
  "data": { ... },           // Required. Validated against event schema
  "metadata": {              // Required
    "actor": {               // Required. Who performed the action
      "type": "user",        // Must be in spec's agent_types
      "id": "550e8400-e29b-41d4-a716-446655440000"
    },
    "target": {              // Optional. What was affected
      "type": "order",
      "id": "target-id"
    },
    "previous_length": 5     // Optional. For OCC
  }
}

Idempotency is handled via the Idempotency-Key request header, not in metadata. See Writing events for details.

Content-Type

Always application/json. j17 rejects other content types with 400.

Response format

Success (201 Created) -- single event

{
  "ok": true,
  "stream_id": "1234567890123-0",
  "implied_count": 2
}
Field Type Description
ok boolean Always true on success
stream_id string Opaque event identifier; use as a cursor when listing events
implied_count integer Number of implied events (omitted if 0)

Success (201 Created) -- batch

{
  "ok": true,
  "stream_ids": ["1234567890123-0", "1234567890123-1"],
  "count": 2,
  "implied_count": 3
}

Error (4xx/5xx)

{
  "ok": false,
  "error": "Event data failed schema validation",
  "path": "data.email"
}

Common error codes:

HTTP Meaning
400 Unparseable request (malformed JSON, JSONL parse error, empty body)
401 Invalid or missing API key
403 Valid auth, but not allowed (wrong environment, read key on write, prod-only restrictions)
404 Aggregate type or event type not in spec, or aggregate has no events written
405 Wrong method on a read-only path (POST /{type}/{id}/length etc.) — response includes Allow: GET
409 OCC conflict (stale previous_length)
413 Event data too large
422 Validation error (bad schema, missing/invalid fields, idempotency key reused with different body)
429 Rate limited
500 Internal error

Query parameters

GET /{type}

Parameter Type Description
resolve flag Return full aggregate data instead of IDs
synchronous boolean Skip cache when resolving, read from event stream
limit integer Page size (default 50, max 200)
cursor string Last ID from previous page for pagination

GET /{type}/{id}

Parameter Type Description
synchronous boolean Bypass cache, compute fresh (?synchronous=true)

GET /{type}/{id}/events

Parameter Type Description
start string Cursor — exclusive in both directions
count integer Events per page. Defaults to 500, capped at 5,000.
direction string forwards (default) or backwards. Selects the window; the array is always oldest-first.

Responses carry count_limit, truncated, and next_start when there is another page. See reading aggregates.

Rate limits

Rate limits use fixed one-minute windows per instance: Free 600, Hobby 6,000, Pro 12,000, and Scale 60,000 write requests. Budgets are shared across keys and environments; reads and deployments have separate budgets. A per-IP safety net also applies. See rate limits for full details.

RateLimit-Remaining: 5400
RateLimit-Scope: instance

Exceeding a rate limit returns 429 with the exhausted scope and Retry-After; instance errors also identify the tier and budget.

Handling interruptions

Any application calling the HTTP API should be prepared for temporary service interruptions, including during scheduled backups. Set connection and request timeouts and a total deadline for the operation.

  • Honor Retry-After on temporary failures. Scheduled maintenance can return 503 Service Unavailable with Retry-After. Wait at least the stated delay before trying again. Rate limits can also send this header on 429. For temporary gateway errors such as 502 or 504, or when a temporary failure has no retry delay, use exponential backoff with jitter where retrying is safe. Bound the number of attempts and report failure if the deadline expires.
  • Retry writes safely. Where supported, give each logical write an Idempotency-Key on the first attempt. Reuse that key with the same request body on retries. A timeout, dropped connection, or proxy error can happen after the write committed. If the endpoint lacks idempotency support, check whether the operation took effect before resending it.
  • Keep permanent errors out of the retry loop. Fix invalid requests, credentials, or permissions before trying again. See the status page for scheduled backups and current incidents.

Idempotency

POST events support idempotency via the Idempotency-Key request header:

curl -X POST https://myapp.j17.dev/order/abc123/was_placed \
  -H "Idempotency-Key: order-123-was_placed-20240101" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data": {...}, "metadata": {"actor": {...}}}'

Same key + same body = cached response replayed (with X-Idempotency-Replayed: true header).

Same key + different body = 422 error.

Keys expire after 24 hours.

CORS

j17 supports cross-origin requests from browser clients:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Authorization, Content-Type

Webhooks (Listeners)

j17 delivers events to your HTTP endpoints via listeners defined in your spec. When a matching event is written, j17 POSTs a signed JSON payload to your URL.

Hosted listener destinations must resolve to public IP addresses. Loopback, private and other non-public addresses are blocked in every environment. Redirects are not followed, and URLs containing credentials are rejected.

Guaranteed deliveries allow up to 3 total attempts, with retries scheduled 5s after the first failure and 25s after the second. Payloads are signed with HMAC-SHA256 using your listener secret, delivered in the j17-signature header. X-J17-Signature is also sent with the same value.

Signature behavior: Guaranteed delivery reads the listener secret from your current spec at delivery time, so pending retries use a rotated secret after you redeploy. If the listener configuration cannot be read, delivery waits without spending an HTTP attempt. A listener configured without a secret sends unsigned payloads. Your endpoint should reject missing signatures if it requires signed requests.

Write limits: Writes that would create guaranteed deliveries can return 429 listener_backlog with Retry-After: 5 when background history publication is backlogged. Exceeding listener fanout or work-preparation limits returns 422 work_preparation_limit without committing the write. Already accepted work is retained.

Admin API

Separate endpoints for instance management, on the console API:

POST   /api/instances/:id/spec    # Deploy spec
GET    /api/instances/:id/keys    # List API keys
POST   /api/instances/:id/keys    # Create API key

See Admin API for details.

Testing

Use staging or test environments:

# Staging
curl https://myapp-staging.j17.dev/order/abc123/was_placed ...

# Production
curl https://myapp.j17.dev/order/abc123/was_placed ...

Different API keys, isolated data. Test freely in staging.

See also

Can't find what you need? support@j17.app