Skip to main content
Receive one signed message event, mark it Read, and send one reply. Verify the token first. Then pick a receive path:
Both transports read the same durable event log, so an agent can run either or both. Deduplicate on event_id whichever you pick.

Before you start

You need: Set the API origin and token:

Verify the Agent Token

Relay returns the agent identity:

Receive and reply

1

Poll for one event

GET /v1/events reads the agent’s durable event log past after. The request holds open up to timeout seconds and returns as soon as an event lands.
While it waits, open the Relay app and message your agent. The poll returns the event:
2

Mark Read and reply

Mark the exact inbound message Read before model or tool work.
Typing is a separate, ephemeral signal. Start it while you work.
Mint the reply’s message_id before you send it. That id names the message and is the send’s idempotency key.
Relay returns 202 Accepted with { message_id, message }: one send is one message. Stop typing after send, failure, or cancellation:
3

Poll again with the cursor

Pass the returned next_cursor as after on the next poll. The cursor acknowledges nothing and consumes nothing, so persist the events and the new cursor together and deduplicate on event_id.
That is the whole loop: poll, handle, persist the cursor, poll again. has_more tells you another page is already waiting. See Long polling for backoff and limits.

Failure and retry behavior

Want a coding agent to build the handler? Copy the prompt on the home page, or hand it the machine-readable contract.

Next steps