ForLoop Realtime integration guide
ForLoop core service · docs
v1.0.2
llms.txtOpen console

ForLoop core service

ForLoop Realtime integration guide

Publish app events to live and test channels, deliver them to browser viewers and webhook sinks, and meter billable events.

Quickstart

Create an app-subject connection to this service, then exchange the app credential for an assertion.

curl -X POST https://realtime.app.forloop.cc/api/opencode/a2a/connections/<connectionId>/assertion \
  -H "x-api-token: $FLC_APP_CREDENTIAL" \
  -H "content-type: application/json" \
  -d '{"scopes":["realtime.channels:write"],"contractVersion":"1.0.2"}'

The assertion is valid for 300 seconds. Send it as Authorization: Bearer <assertion> on every /v1 call.

  1. Create a live channel with POST /v1/channels.
  2. Publish one event or a batch to the channel.
  3. Mint a viewer token and subscribe to the channel in the browser.
  4. Read GET /v1/usage to inspect billable events and wallet state.

Authentication and tenancy

The service trusts only a verified app assertion. It checks iss, aud, sub=app:<callerSprintId>, appPublicId, env, scopes, and the pinned contractVersion.

Scopes

API reference

MethodPathAccessSuccessToolPurpose
POST/v1/channelswrite201Create channelCreate an app-scoped, ordered, replayable event channel. The channel is live by default; pass mode "test" for an isolated, never-billed sandbox channel. Names are unique per app+env+mode. Define event names in eventCatalog now so the console can generate the event reference.
GET/v1/channelsread200List channelsList channels for one mode in creation order, with an opaque cursor. Live channels are returned by default; pass mode=test to list the test sandbox separately.
GET/v1/channels/{id}read200Get channelRead one channel including mode, version, enabled state, tokenEpoch, retentionHours, allowedOrigins, audience, eventCatalog, strictCatalog, and eventCount24h.
PATCH/v1/channels/{id}write200Update channelUpdate description, retention, enabled state, allowed origins, audience summary, event catalog, strictCatalog, or mode. Requires the current version (body version or If-Match). Mode can change only before the first event.
DELETE/v1/channels/{id}write202Delete channelSoft-delete a channel and remove it from listings and name uniqueness. Test channels are deletable regardless of retained events; retained events expire by TTL.
POST/v1/channels/{id}/pausewrite202Pause channelPause a channel. Publishes return 409 channel_paused and new AppSync connections/subscribes are denied, but replay continues to work because the log is intact.
POST/v1/channels/{id}/resumewrite202Resume channelResume a paused channel so publishing and new AppSync connects are allowed again. Existing cursors and events are untouched.
POST/v1/channels/{id}/eventswrite202Publish eventsAppend one event or an all-or-nothing batch of up to 100 events to a channel, then fan out to AppSync. Returns server-minted evt_ ids in accepted order. The log commits before fan-out, so a fan-out failure still returns 202 and is recovered by replay.
GET/v1/channels/{id}/eventsread200Replay channel eventsRead the ordered log for gap recovery. Accepts an app assertion or a channel viewer token; viewer-token reads are dimension-filtered and the nextCursor advances on scanned events. This is the only authoritative answer to what a client missed.
POST/v1/channels/{id}/viewer-tokenswrite201Mint viewer tokenMint a short-lived, read-only viewer token for one channel and one mode, and return the AppSync connect descriptor (url, namespace, subChannels). The app backend passes it to its browser; the token is returned once and never listed.
POST/v1/channels/{id}/viewer-tokens/revoke-allwrite202Revoke viewer tokensBump the channel tokenEpoch, invalidating every outstanding viewer token for the next connect and the next replay read. Already-open WebSockets keep their grant until disconnect or token expiry.
GET/v1/usageread200Get usageReport events published, bytes, delivery statuses, sub-channels published by kind, quota headroom, and the effective billing state for a window, with live and test reported separately. billableEvents excludes test mode.
POST/v1/endpointswrite201Register endpointRegister a verified HTTPS callback endpoint for signed webhook sink deliveries. Use verificationMethod=platform with a platform Webhook inbox URL (https://webhook.app.<env>.forloop.cc/h/<token>) when the app has no public receiver. The body env must equal the assertion env; appId always comes from the assertion.
GET/v1/endpointsread200List endpointsList app+env callback endpoints in creation order. Never returns signing secrets or challenge tokens.
GET/v1/endpoints/{id}read200Get endpointRead one endpoint and its verification state. The signing secret is never returned here.
POST/v1/endpoints/{id}/verifywrite200Verify endpointComplete endpoint verification and return the 256-bit HMAC signing secret exactly once. A platform endpoint is already verified at registration but still returns its secret here on the first call.
POST/v1/endpoints/{id}/rotate-secretwrite200Rotate endpoint secretIssue a new endpoint HMAC signing secret and keep the previous one valid for a 24 h grace period. The new secret is returned once.
DELETE/v1/endpoints/{id}write202Delete endpointDelete an endpoint and its signing secret. Blocked while any subscription references it.
POST/v1/channels/{id}/subscriptionswrite201Create subscriptionBind a channel to a verified endpoint, optionally filtering by an exact event name or a prefix.* filter.
GET/v1/channels/{id}/subscriptionsread200List subscriptionsList the endpoint bindings for a channel.
DELETE/v1/subscriptions/{id}write202Delete subscriptionRemove a subscription. Future events are no longer delivered to its endpoint; existing delivery records remain.
GET/v1/deliveriesread200List deliveriesList sink deliveries newest first for the app+env+mode, with optional status, channel, subscription, and time filters.
GET/v1/deliveries/{id}read200Get deliveryRead one delivery with its attempt history, status codes, and latency. The event body is omitted unless include=content is requested.
GET/v1/events/{id}/deliveriesread200List event sink deliveriesShow every sink subscription attempt for one event (GSI2): subscription, endpoint, status, attempts, last status code, and next attempt. AppSync live delivery is not tracked per event.
POST/v1/deliveries/{id}/retrywrite202Retry deliveryRe-enqueue a terminal permanent_failure delivery, reusing the same deliveryId. A non-terminal delivery returns 409. Retries are never billed separately.
GET/v1/healthread200Get healthReport service liveness plus the deployed service version and the management contract version. This route requires no authentication.

Create channel

POST /v1/channels · write · success 201

Create an app-scoped, ordered, replayable event channel. The channel is live by default; pass mode "test" for an isolated, never-billed sandbox channel. Names are unique per app+env+mode. Define event names in eventCatalog now so the console can generate the event reference.

Example

POST /v1/channels
Idempotency-Key: create-orders-live
Authorization: Bearer <assertion>
{"name":"orders","mode":"live","retentionHours":24,"allowedOrigins":["https://app.example.com"],"audience":{"dimensions":["userId","groups"]},"eventCatalog":[{"name":"order.paid","description":"An order was paid"}],"strictCatalog":true}

201
{"channel":{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","name":"orders","mode":"live","retentionHours":24,"enabled":true,"tokenEpoch":0,"allowedOrigins":["https://app.example.com"],"strictCatalog":true,"version":1,"eventCount24h":0}}

Output fields: channel

List channels

GET /v1/channels · read · success 200

List channels for one mode in creation order, with an opaque cursor. Live channels are returned by default; pass mode=test to list the test sandbox separately.

Example

GET /v1/channels?mode=live&limit=50
Authorization: Bearer <assertion>

200
{"channels":[],"nextCursor":null}

Output fields: channels, nextCursor

Get channel

GET /v1/channels/{id} · read · success 200

Read one channel including mode, version, enabled state, tokenEpoch, retentionHours, allowedOrigins, audience, eventCatalog, strictCatalog, and eventCount24h.

Example

GET /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA
Authorization: Bearer <assertion>

200
{"channel":{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","name":"orders","mode":"live","version":1,"enabled":true}}

Output fields: channel

Update channel

PATCH /v1/channels/{id} · write · success 200

Update description, retention, enabled state, allowed origins, audience summary, event catalog, strictCatalog, or mode. Requires the current version (body version or If-Match). Mode can change only before the first event.

Example

PATCH /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA
Idempotency-Key: rename-description-1
Authorization: Bearer <assertion>
{"version":1,"description":"Paid order events","retentionHours":48}

200
{"channel":{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","version":2,"retentionHours":48}}

Output fields: channel

Delete channel

DELETE /v1/channels/{id} · write · success 202

Soft-delete a channel and remove it from listings and name uniqueness. Test channels are deletable regardless of retained events; retained events expire by TTL.

Example

DELETE /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA
Idempotency-Key: delete-orders-1
Authorization: Bearer <assertion>

202
{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","deleted":true}

Output fields: channelId, deleted

Pause channel

POST /v1/channels/{id}/pause · write · success 202

Pause a channel. Publishes return 409 channel_paused and new AppSync connections/subscribes are denied, but replay continues to work because the log is intact.

Example

POST /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/pause
Idempotency-Key: pause-orders-1
Authorization: Bearer <assertion>

202
{"channel":{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","enabled":false,"version":2}}

Output fields: channel

Resume channel

POST /v1/channels/{id}/resume · write · success 202

Resume a paused channel so publishing and new AppSync connects are allowed again. Existing cursors and events are untouched.

Example

POST /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/resume
Idempotency-Key: resume-orders-1
Authorization: Bearer <assertion>

202
{"channel":{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","enabled":true,"version":3}}

Output fields: channel

Publish events

POST /v1/channels/{id}/events · write · success 202

Append one event or an all-or-nothing batch of up to 100 events to a channel, then fan out to AppSync. Returns server-minted evt_ ids in accepted order. The log commits before fan-out, so a fan-out failure still returns 202 and is recovered by replay.

Example

POST /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/events
Idempotency-Key: order-123-paid
Authorization: Bearer <assertion>
{"name":"order.paid","data":{"orderId":"ord_123","amountFLC":1500},"dimensions":{"userId":"42","groups":["admins"]}}

202
{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","mode":"live","events":[{"id":"evt_01JAZ8Q3K9M2X7V4T6R8W0Y1Z3","publishedAt":"2026-10-26T09:14:02.531Z"}]}

Output fields: channelId, mode, events

Replay channel events

GET /v1/channels/{id}/events · read · success 200

Read the ordered log for gap recovery. Accepts an app assertion or a channel viewer token; viewer-token reads are dimension-filtered and the nextCursor advances on scanned events. This is the only authoritative answer to what a client missed.

Example

GET /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/events?since=eyJldiI6ImV2dF8wMUpBWjgiLCJsIjo1fQ&limit=100&order=asc
Authorization: Bearer <assertion>

200
{"events":[],"hasMore":false}

Output fields: events, nextCursor, hasMore

Mint viewer token

POST /v1/channels/{id}/viewer-tokens · write · success 201

Mint a short-lived, read-only viewer token for one channel and one mode, and return the AppSync connect descriptor (url, namespace, subChannels). The app backend passes it to its browser; the token is returned once and never listed.

Example

POST /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/viewer-tokens
Idempotency-Key: user-42-session-9
Authorization: Bearer <assertion>
{"subject":"user-42","dimensions":{"userId":"42","groups":["admins"]},"ttlSeconds":3600,"origin":"https://app.example.com"}

201
{"token":"flv_...","expiresAt":"2026-10-26T10:14:02Z","channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","mode":"live","dimensions":{"userId":"42","groups":["admins"]},"transport":{"type":"appsync-ws","url":"wss://example.appsync-realtime-api.ap-southeast-1.amazonaws.com/event/realtime","namespace":"live","subChannels":["live/channel-<sha256(channelId)[0:32]>"]}}

Output fields: token, expiresAt, channelId, mode, dimensions, transport

Revoke viewer tokens

POST /v1/channels/{id}/viewer-tokens/revoke-all · write · success 202

Bump the channel tokenEpoch, invalidating every outstanding viewer token for the next connect and the next replay read. Already-open WebSockets keep their grant until disconnect or token expiry.

Example

POST /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/viewer-tokens/revoke-all
Idempotency-Key: revoke-user-42-1
Authorization: Bearer <assertion>

202
{"channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","tokenEpoch":1}

Output fields: channelId, tokenEpoch

Get usage

GET /v1/usage · read · success 200

Report events published, bytes, delivery statuses, sub-channels published by kind, quota headroom, and the effective billing state for a window, with live and test reported separately. billableEvents excludes test mode.

Example

GET /v1/usage?from=2026-10-25T00:00:00Z&to=2026-10-26T00:00:00Z
Authorization: Bearer <assertion>

200
{"from":"2026-10-25T00:00:00Z","to":"2026-10-26T00:00:00Z","live":{"eventsPublished":10,"bytes":2048,"billableEvents":10},"test":{"eventsPublished":4,"bytes":512,"billableEvents":0}}

Output fields: from, to, live, test, billing

Register endpoint

POST /v1/endpoints · write · success 201

Register a verified HTTPS callback endpoint for signed webhook sink deliveries. Use verificationMethod=platform with a platform Webhook inbox URL (https://webhook.app.<env>.forloop.cc/h/<token>) when the app has no public receiver. The body env must equal the assertion env; appId always comes from the assertion.

Example

POST /v1/endpoints
Idempotency-Key: endpoint-prod-1
Authorization: Bearer <assertion>
{"env":"dev","baseUrl":"https://app.example.com/realtime","verificationMethod":"well_known"}

201
{"endpoint":{"endpointId":"ep_9fK2","env":"dev","baseUrl":"https://app.example.com/realtime","verificationState":"pending"}}

Output fields: endpoint

List endpoints

GET /v1/endpoints · read · success 200

List app+env callback endpoints in creation order. Never returns signing secrets or challenge tokens.

Example

GET /v1/endpoints?limit=50
Authorization: Bearer <assertion>

200
{"endpoints":[]}

Output fields: endpoints, nextCursor

Get endpoint

GET /v1/endpoints/{id} · read · success 200

Read one endpoint and its verification state. The signing secret is never returned here.

Example

GET /v1/endpoints/ep_9fK2
Authorization: Bearer <assertion>

200
{"endpoint":{"endpointId":"ep_9fK2","verificationState":"verified"}}

Output fields: endpoint

Verify endpoint

POST /v1/endpoints/{id}/verify · write · success 200

Complete endpoint verification and return the 256-bit HMAC signing secret exactly once. A platform endpoint is already verified at registration but still returns its secret here on the first call.

Example

POST /v1/endpoints/ep_9fK2/verify
Idempotency-Key: verify-endpoint-1
Authorization: Bearer <assertion>

200
{"endpoint":{"endpointId":"ep_9fK2","verificationState":"verified"},"signingSecret":"whsec_..."}

Output fields: endpoint, signingSecret, signingSecretOmitted, secretVersion

Rotate endpoint secret

POST /v1/endpoints/{id}/rotate-secret · write · success 200

Issue a new endpoint HMAC signing secret and keep the previous one valid for a 24 h grace period. The new secret is returned once.

Example

POST /v1/endpoints/ep_9fK2/rotate-secret
Idempotency-Key: rotate-endpoint-1
Authorization: Bearer <assertion>

200
{"endpoint":{"endpointId":"ep_9fK2"},"signingSecret":"whsec_new_...","previousSecretExpiresAt":"2026-10-27T09:00:00Z"}

Output fields: endpoint, signingSecret, previousSecretExpiresAt

Delete endpoint

DELETE /v1/endpoints/{id} · write · success 202

Delete an endpoint and its signing secret. Blocked while any subscription references it.

Example

DELETE /v1/endpoints/ep_9fK2
Idempotency-Key: delete-endpoint-1
Authorization: Bearer <assertion>

202
{"endpointId":"ep_9fK2","deleted":true}

Output fields: endpointId, deleted

Create subscription

POST /v1/channels/{id}/subscriptions · write · success 201

Bind a channel to a verified endpoint, optionally filtering by an exact event name or a prefix.* filter.

Example

POST /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/subscriptions
Idempotency-Key: sub-orders-paid-1
Authorization: Bearer <assertion>
{"endpointId":"ep_9fK2","eventNameFilter":"order.*"}

201
{"subscription":{"subscriptionId":"sub_9fK2","channelId":"ch_9fK2mQ7xR4tVbN1cZpL3sA","endpointId":"ep_9fK2","eventNameFilter":"order.*"}}

Output fields: subscription

List subscriptions

GET /v1/channels/{id}/subscriptions · read · success 200

List the endpoint bindings for a channel.

Example

GET /v1/channels/ch_9fK2mQ7xR4tVbN1cZpL3sA/subscriptions
Authorization: Bearer <assertion>

200
{"subscriptions":[]}

Output fields: subscriptions

Delete subscription

DELETE /v1/subscriptions/{id} · write · success 202

Remove a subscription. Future events are no longer delivered to its endpoint; existing delivery records remain.

Example

DELETE /v1/subscriptions/sub_9fK2
Idempotency-Key: delete-sub-1
Authorization: Bearer <assertion>

202
{"subscriptionId":"sub_9fK2","deleted":true}

Output fields: subscriptionId, deleted

List deliveries

GET /v1/deliveries · read · success 200

List sink deliveries newest first for the app+env+mode, with optional status, channel, subscription, and time filters.

Example

GET /v1/deliveries?status=permanent_failure&limit=50
Authorization: Bearer <assertion>

200
{"deliveries":[],"nextCursor":null}

Output fields: deliveries, nextCursor

Get delivery

GET /v1/deliveries/{id} · read · success 200

Read one delivery with its attempt history, status codes, and latency. The event body is omitted unless include=content is requested.

Example

GET /v1/deliveries/dlv_01JAZ8Q3?include=content
Authorization: Bearer <assertion>

200
{"delivery":{"deliveryId":"dlv_01JAZ8Q3","status":"permanent_failure","attempts":5}}

Output fields: delivery

List event sink deliveries

GET /v1/events/{id}/deliveries · read · success 200

Show every sink subscription attempt for one event (GSI2): subscription, endpoint, status, attempts, last status code, and next attempt. AppSync live delivery is not tracked per event.

Example

GET /v1/events/evt_01JAZ8Q3K9M2X7V4T6R8W0Y1Z3/deliveries
Authorization: Bearer <assertion>

200
{"deliveries":[]}

Output fields: deliveries, nextCursor

Retry delivery

POST /v1/deliveries/{id}/retry · write · success 202

Re-enqueue a terminal permanent_failure delivery, reusing the same deliveryId. A non-terminal delivery returns 409. Retries are never billed separately.

Example

POST /v1/deliveries/dlv_01JAZ8Q3/retry
Idempotency-Key: retry-dlv-01JAZ8Q3
Authorization: Bearer <assertion>

202
{"delivery":{"deliveryId":"dlv_01JAZ8Q3","status":"pending"}}

Output fields: delivery

Get health

GET /v1/health · read · success 200

Report service liveness plus the deployed service version and the management contract version. This route requires no authentication.

Example

GET /v1/health

200
{"ok":true,"service":"realtime","serviceVersion":"1.0.2","contractVersion":"1.0.2","version":"1.0.2"}

Output fields: ok, service, serviceVersion, contractVersion, version

Errors and retries

CodeMeaningRetry?
invalid_assertion / expiredThe assertion is missing, invalid, or expired.No; exchange a fresh assertion.
insufficient_scopeThe assertion does not carry a required scope.No; update the connection grant.
env_mismatch / audience_mismatchWrong platform environment or target.No; fix the connection.
invalid_requestThe request body or parameters are invalid.No.
not_foundThe resource is absent or belongs to another app.No.
conflictVersion, state, or idempotency conflict.No; read the current state first.
quota_exceeded / rate_limitedPer-app quota or rate limit reached.Yes, after the indicated delay.
internal_error / provider_transportTransient platform or provider failure.Yes, with backoff and the same idempotency key.

Billing

postpaid — see the service contract for the effective price.

The service reserves before billable work and commits only after the success condition in its contract. A failed, filtered, or canceled unit is free. A successful unit that cannot settle is retried durably and is never silently released.

Limits and retention

AI-agent checklist

  1. Discover the target agent card and pin its exact contract version.
  2. Exchange the app credential for a fresh assertion immediately before the call.
  3. Use the generated client types; never hand-write a response type.
  4. Send Idempotency-Key on every write and reuse it only for the same logical request.
  5. Never infer the payer or app ID from a request body; use the verified assertion.
  6. Treat 4xx errors as terminal unless the contract explicitly says otherwise; retry only transient 5xx/transport errors with backoff.
  7. Read the returned job/delivery state before presenting success to a user.