Poppy LabTry the live demoLive demo

The agent's API

The Personal Agent's own HTTP API, for building a client of it: a phone app, a messaging channel, anything that isn't the playground's page. Every client, the page too, works in the same conversations, so what one does, the others see.

Personal Agent API 1.0.0 · OpenAPI 3.1.0 · /api/v1/openapi.json

What it is for

HTTP API for building clients on top of the Personal Agent over Personal Agent Protocol (Poppy 1.0): multi-company conversations, quick replies, Operations v3 approval workflows, Company OAuth sign-in, real-time SSE events, and passkey-backed multi-device accounts. Browser clients authenticate via same-origin cookies; native apps send no Origin header and authenticate with Authorization: Bearer <accessToken>.

Everything is under https://poppylab.dev/api/v1, and every body is JSON except the event stream's. The version is in the path: v1 is still changing, and a member or a route can still be added, renamed or removed until it is frozen. Until then, a client ignores a member it doesn't know, and reads the document again when it is updated.

This page is built from the same document the API serves at /api/v1/openapi.json, so every operation and type on it is the document's. To build an app on it step by step, read Build a native client.

Authentication

A request is a browser's or a client app's, and the two prove who they are differently.

  • A browser on the playground's own origin uses cookies: the visitor's, which needs no account, or __Host-poppy_account once it signs in to an agent account. A request that changes anything must come from the playground's origin; one from another origin is refused with 403 before its body is read.
  • A client app sends no Origin. It creates an account or signs in with a passkey, in two requests each: the WebAuthn options (POST /accounts/options or POST /sessions/options), then the authenticator's answer to them (POST /accounts or POST /sessions). The answer carries the device's tokens: an access token, sent as Authorization: Bearer, which lasts 15 minutes, and a refresh token, exchanged at POST /sessions/refresh for a new pair. Each refresh token works once; one used twice ends the session on every device that holds it.

Passkeys are for poppylab.dev, discoverable, with user verification and no attestation, so signing in needs no username. An account has no email, password or name. A session unused for 30 days ends, and every session ends after a year.

apiSession http, bearer

Short-lived access token from SessionTokens (Authorization: Bearer <accessToken>). Browser clients on the playground's origin authenticate with HttpOnly cookies instead.

Errors

A refusal has a status and an Error body, { code, error }. error is written for the person and can be shown as it is; code is what a client acts on. Each operation below lists the statuses it answers. These are the codes a client most needs to tell apart:

invalid_token 401

Access token expired, rotated, or invalid. Call POST /api/v1/sessions/refresh and retry.

session_revoked 401

Device session ended (signed out, passkey removed, or refresh token reused). Sign in again with a passkey.

not_signed_in 401

Endpoint requires an authenticated agent account.

passkey_not_verified 400

WebAuthn verification failed. Returned uniformly whether the account or passkey exists.

ceremony_expired 400

WebAuthn ceremony expired (5-minute TTL) or was already consumed. Request fresh options.

rate_limited 429

Rate limit exceeded. Wait the number of seconds given in the Retry-After header.

too_many_streams 429

Open SSE stream limit reached (10 concurrent streams per signed-in account, or 4 per anonymous visitor).

last_passkey 409

Cannot delete the only remaining passkey on an account.

company_not_connected 400

The conversation does not have a Company connected at that origin.

conversation_ended 410

The conversation has ended and is read-only.

Conversations

Create and interact with conversations across up to three connected Companies. Each turn returns newly added messages alongside the updated ConversationState.

POST /api/v1/conversations

startConversation

Start a conversation

Creates an empty conversation, or connects an initial Company signed out when company is provided.

Request body object

company string optional

Optional Company origin URL to discover and connect immediately.

Responses

201 ConversationState

Conversation created.

400 Error

Invalid request payload or precondition failed.

403 Error

Cross-origin browser request rejected.

404 Error

Conversation not found for this caller.

409 Error

Conversation is busy with another request, or the Company cannot be added.

410 Error

Conversation has ended and is now read-only.

422 Error

Company discovery failed.

Example request & response
POST /api/v1/conversations
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Content-Type: application/json

{
  "company": "https://food-demo.poppylab.dev"
}
HTTP/1.1 201
Content-Type: application/json

{
  "id": "hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j",
  "active": true,
  "companies": [
    {
      "origin": "https://food-demo.poppylab.dev",
      "name": "Lantern Noodle Bar",
      "url": "https://food-demo.poppylab.dev/",
      "signedIn": false,
      "signingIn": false,
      "consentVersion": 0,
      "accessLost": false,
      "direct": {
        "open": false,
        "invitation": null
      }
    }
  ],
  "removed": [],
  "messages": [],
  "proposals": []
}

GET /api/v1/conversations/{id}

getConversation

Retrieve a conversation

Returns the current ConversationState, including connected Companies, transcript messages, and all proposals.

Parameters

id string, path required

Conversation ID.

Responses

200 ConversationState

Current conversation state.

404 Error

Conversation not found for this caller.

POST /api/v1/conversations/{id}/messages

sendMessage

Send a message

Submits a user message and runs one agent turn. If company is omitted in a multi-company conversation, the agent routes automatically or replies with disambiguation choices.

Parameters

id string, path required

Conversation ID.

Request body object

text string required

User message text.

company string optional

Optional target Company origin URL to scope this turn.

model ModelChoice optional

Model configuration for this turn. Defaults to demo.

Responses

200 TurnResult

Turn completed. As JSON, the TurnResult. With Accept: text/event-stream, Server-Sent Events (TurnEvent): one message.delta per sentence of the agent's as it is written, then turn with the same result, or error. A request refused before anything was said is answered as without the header, with its status and an Error.

400 Error

Invalid request payload or precondition failed.

403 Error

Cross-origin browser request rejected.

404 Error

Conversation not found for this caller.

409 Error

Conversation is busy with another request, or the Company cannot be added.

410 Error

Conversation has ended and is now read-only.

Example request & response
POST /api/v1/conversations/hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j/messages
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Content-Type: application/json

{
  "text": "What can you do?"
}
HTTP/1.1 200
Content-Type: application/json

{
  "conversation": "hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j",
  "messages": [
    {
      "from": "user",
      "text": "What can you do?"
    },
    {
      "from": "agent",
      "text": "Demo mode runs the examples below, without a model. To ask anything in your own words, press “Use your own model”.",
      "spoken": "Demo mode runs the examples below, without a model. To ask anything in your own words, press “Use your own model”.",
      "choices": [
        {
          "label": "What’s on the menu?",
          "answer": {
            "message": "What’s on the menu?"
          }
        }
      ]
    }
  ],
  "replaced": false,
  "state": {
    "id": "hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j",
    "active": true,
    "companies": [
      {
        "origin": "https://food-demo.poppylab.dev",
        "name": "Lantern Noodle Bar",
        "url": "https://food-demo.poppylab.dev/",
        "signedIn": false,
        "signingIn": false,
        "consentVersion": 0,
        "accessLost": false,
        "direct": {
          "open": false,
          "invitation": null
        }
      }
    ],
    "removed": [],
    "messages": [
      "…"
    ],
    "proposals": []
  }
}

POST /api/v1/conversations/{id}/answers

answerChoice

Submit a quick-reply answer

Submits the structured answer payload from a previous message's Choice without free-text parsing.

Parameters

id string, path required

Conversation ID.

Request body object

answer Answer required

Exact answer object from a Choice.

model ModelChoice optional

Model configuration if the choice triggers a turn.

Responses

200 TurnResult

Answer applied. As JSON, the TurnResult. With Accept: text/event-stream, Server-Sent Events (TurnEvent): one message.delta per sentence of the agent's as it is written, then turn with the same result, or error. A request refused before anything was said is answered as without the header, with its status and an Error.

400 Error

Invalid request payload or precondition failed.

403 Error

Cross-origin browser request rejected.

404 Error

Conversation not found for this caller.

409 Error

Conversation is busy with another request, or the Company cannot be added.

410 Error

Conversation has ended and is now read-only.

Example request & response
POST /api/v1/conversations/hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j/answers
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Content-Type: application/json

{
  "answer": {
    "message": "What’s on the menu?"
  }
}

POST /api/v1/conversations/{id}/proposals/{proposal}/decision

decideProposal

Approve or decline a proposal

Approves or declines a pending Operations v3 proposal. Approvals bind strictly to revision and execute at most once; if the Company's terms changed, the proposal transitions to superseded.

Parameters

id string, path required

Conversation ID.

proposal string, path required

Proposal (operation) ID.

Request body object

company string required

Origin URL of the Company holding the proposal.

revision string required

Exact revision token from the proposal shown to the user.

decision "approve" | "decline" required

User decision (approve or decline).

Responses

200 Decision

Decision recorded.

400 Error

Invalid request payload or precondition failed.

403 Error

Cross-origin browser request rejected.

404 Error

Conversation not found for this caller.

409 Error

Conversation is busy with another request, or the Company cannot be added.

410 Error

Conversation has ended and is now read-only.

Example request & response
POST /api/v1/conversations/hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j/proposals/op_4UNgDhnV1Y8lgsDmZCAV2pt3/decision
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Content-Type: application/json

{
  "company": "https://food-demo.poppylab.dev",
  "revision": "1795772788-peanO34panWBIb-5",
  "decision": "approve"
}
HTTP/1.1 200
Content-Type: application/json

{
  "proposal": {
    "id": "op_4UNgDhnV1Y8lgsDmZCAV2pt3",
    "company": {
      "origin": "https://food-demo.poppylab.dev",
      "name": "Lantern Noodle Bar"
    },
    "revision": "1795772788-peanO34panWBIb-5",
    "summary": "Change order ord_LNB1001 for Elena Maren. Delivery stays Friday 18:30–19:00. New dishes: 2 × Shoyu ramen, 1 × Salted edamame, 1 × Matcha ice cream. New total USD 43.00 (was USD 37.00; USD 6.00 more, charged — simulated, no real payment).",
    "terms": {
      "order_id": "ord_LNB1001",
      "order_version": 1,
      "lines": {
        "shoyu-ramen": 2,
        "edamame": 1,
        "matcha-ice": 1
      },
      "before_total_cents": 3700,
      "new_total_cents": 4300,
      "currency": "USD"
    },
    "state": "succeeded",
    "expiresAt": "2026-11-27T09:56:28.685Z",
    "spoken": "Lantern Noodle Bar wants to change your order, for a new total of 43 dollars, 6 more."
  },
  "state": {
    "id": "hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j",
    "active": true,
    "companies": [
      {
        "origin": "https://food-demo.poppylab.dev",
        "name": "Lantern Noodle Bar",
        "url": "https://food-demo.poppylab.dev/",
        "signedIn": true,
        "scopes": "orders:read orders:write",
        "signingIn": false,
        "consentVersion": 1,
        "accessLost": false,
        "direct": {
          "open": false,
          "invitation": null
        }
      }
    ],
    "removed": [],
    "messages": [
      "…"
    ],
    "proposals": [
      "…"
    ]
  }
}

The answer as it is written

With Accept: text/event-stream, POST …/messages and POST …/answers answer Server-Sent Events: a message.delta for each of the agent's sentences as soon as the model has written it, then turn with the same TurnResult as the JSON answer, or error. Each agent message of the result carries as id the ID its sentences came under; drop shown sentences whose ID no message carries. Demo mode and the agent's own lines come as sentences too, all together before turn, so a client has one path. A Company's own words never come as sentences: they are in the result, as the Company's message.

A voice client says each sentence's spoken as it arrives and doesn't say the message's spoken again. A request refused before anything was said is answered as without the header, with its status and an Error. The sentences go only to the request that sent the message; the event stream below carries the message whole, as message, to the account's other devices.

POST /api/v1/conversations/hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j/messages
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Accept: text/event-stream
Content-Type: application/json

{
  "text": "What's on the menu tonight?",
  "model": {
    "provider": "free",
    "turnstile": "0.Kx3…"
  }
}
HTTP/1.1 200
Content-Type: text/event-stream

event: message.delta
data: {"type":"message.delta","message":"q7Vb2YxkS1mR0cJtE4uWnA","index":0,"text":"Lantern Noodle Bar has shoyu ramen for $14.00 and salted edamame for $5.50 tonight. ","spoken":"Lantern Noodle Bar has shoyu ramen for 14 dollars and salted edamame for 5 dollars 50 tonight."}

event: message.delta
data: {"type":"message.delta","message":"q7Vb2YxkS1mR0cJtE4uWnA","index":1,"text":"The matcha ice cream is back too. ","spoken":"The matcha ice cream is back too."}

event: message.delta
data: {"type":"message.delta","message":"q7Vb2YxkS1mR0cJtE4uWnA","index":2,"text":"Shall I add anything to your order?\n\n","spoken":"Shall I add anything to your order?"}

event: turn
data: {"type":"turn","result":{"conversation":"hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j","messages":[{"from":"user",…},{"id":"q7Vb2YxkS1mR0cJtE4uWnA","from":"agent","text":"Lantern Noodle Bar has shoyu ramen…",…}],…}}

sendMessage in the reference

Company sign-ins

Authenticate a user directly on a Company's own consent page without exposing credentials to the agent. Final outcomes arrive over the SSE event stream.

POST /api/v1/conversations/{id}/sign-ins

startSignIn

Start a Company sign-in

Initiates Direct Sign-In (§4.2) at a connected Company. Browser callers receive the Company's consent URL; bearer-authenticated apps receive a single-use agent link (SignIn.url) to open in an in-app browser session. Completion emits signin.completed or signin.failed on the event stream.

Parameters

id string, path required

Conversation ID.

Request body object

company string required

Origin URL of the connected Company.

access "read" | "write" optional

Permission tier to request (read default, or write to propose changes).

Responses

200 SignIn

Sign-in launch details.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

404 Error

Conversation not found for this caller.

409 Error

Conversation is busy with another request, or the Company cannot be added.

410 Error

Conversation has ended and is now read-only.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
POST /api/v1/conversations/hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j/sign-ins
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Content-Type: application/json

{
  "company": "https://food-demo.poppylab.dev",
  "access": "write"
}
HTTP/1.1 200
Content-Type: application/json

{
  "url": "https://poppylab.dev/api/v1/sign-ins/Wq3v0mA4…",
  "expiresAt": 1795772968698,
  "endUrl": "https://poppylab.dev/playground/sign-in/app"
}

Events

Real-time Server-Sent Events stream delivering sign-in outcomes, proposal updates, cross-device activity, and Direct Conversation messages.

GET /api/v1/conversations/{id}/events

conversationEvents

Stream conversation events

Opens a Server-Sent Events stream starting with state, followed by incremental changes polled every 2 seconds. Closes automatically after 5 minutes or when the conversation ends; reconnect and resync from state. Signed-in streams emit session.ended if the session or access token becomes invalid. Concurrency is capped at 10 open streams per account (4 per anonymous visitor, too_many_streams).

Parameters

id string, path required

Conversation ID.

Responses

200 AgentEvent as text/event-stream

SSE stream (text/event-stream); each data payload is an AgentEvent.

404 Error

Conversation not found for this caller.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
GET /api/v1/conversations/hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j/events
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Accept: text/event-stream
HTTP/1.1 200
Content-Type: text/event-stream

retry: 3000

event: state
data: {"type":"state","state":{"id":"hKhgaC-veINpeBH3fJQO4-ewBMbIdw9j","active":true,…}}

: read

event: signin.completed
data: {"type":"signin.completed","company":{"origin":"https://food-demo.poppylab.dev","name":"Lantern Noodle Bar"}}

event: proposal.created
data: {"type":"proposal.created","proposal":{"id":"op_4UNgDhnV1Y8lgsDmZCAV2pt3",…}}

The stream and its events

The stream sends retry: 3000, then each event with its type as the SSE event name and the whole AgentEvent as its data, and a comment after every reading of the conversation. It reads the stored conversation every two seconds, so it learns of what another device or the browser did without being told. It closes after five minutes or when the conversation ends: open it again and start from the new state.

state with state

Initial snapshot emitted when the stream opens. Every subsequent event describes a delta from this state.

message with message

A new message appended by the user, agent, or Company.

messages.replaced with state

Earlier messages were withdrawn (for example, after losing access or disconnecting a Company). Replace your local transcript with state.messages.

signin.completed with company

The user completed OAuth consent at the Company.

signin.failed with company

A pending Company sign-in was declined, failed, or expired after 5 minutes. No grant changed.

access.lost with company

The Company rejected or revoked the stored grant. Prompt the user to sign in again.

signout with company

The user signed out of the Company in this conversation.

proposal.created with proposal

A Company returned a new Operations v3 proposal awaiting user approval.

proposal.expired with proposal

The proposal passed expiresAt without approval. Nothing was executed.

proposal.replaced with proposal

The Company returned a fresh revision with updated terms that require new approval.

proposal.updated with proposal

The proposal moved to a terminal state (succeeded, declined, refused, or uncertain).

company.added with company

A Company was connected to the conversation.

company.removed with company

A Company was disconnected from the conversation.

conversation.ended with keptUntil

The conversation is now read-only and will be purged at keptUntil. The stream closes.

session.ended with code

The caller's session is no longer valid and the stream closed. On invalid_token, refresh the access token and reconnect; on session_revoked, sign in again.

Accounts

Create passwordless, passkey-backed agent accounts and inspect or claim conversations across devices.

POST /api/v1/accounts/options

accountOptions

Create registration options

Starts passkey account creation. Returns WebAuthn options (discoverable, user verification required, no attestation) and a single-use ceremony ID valid for 5 minutes.

Request body object

label string optional

Optional user-chosen display label for the account.

Responses

200 CreationOptions

WebAuthn creation options and ceremony ID.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
POST /api/v1/accounts/options
Content-Type: application/json

{
  "label": "Home"
}
HTTP/1.1 200
Content-Type: application/json

{
  "ceremony": "DMz80NY0PzjiwanwGamYKA",
  "options": {
    "challenge": "U3l0bkxYSjE4cU9jT2xqVDFPaTNTMUpRbXM2RTdVdU04andPa3d1cC1kbw",
    "rp": {
      "name": "poppylab.dev",
      "id": "poppylab.dev"
    },
    "user": {
      "id": "c0rOAOzr0jtlGGeGpluvjQ",
      "name": "Home",
      "displayName": "Home"
    },
    "pubKeyCredParams": [
      {
        "alg": -7,
        "type": "public-key"
      },
      {
        "alg": -257,
        "type": "public-key"
      }
    ],
    "timeout": 300000,
    "attestation": "none",
    "excludeCredentials": [],
    "authenticatorSelection": {
      "residentKey": "required",
      "userVerification": "required",
      "requireResidentKey": true
    },
    "extensions": {
      "credProps": true
    },
    "hints": []
  }
}

POST /api/v1/accounts

createAccount

Create an account

Verifies the passkey registration response, creates the account, and starts a signed-in session for the calling device.

Request body PasskeyAnswer

Responses

201 SignedIn

Account created and signed in.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
POST /api/v1/accounts
Content-Type: application/json

{
  "ceremony": "DMz80NY0PzjiwanwGamYKA",
  "credential": {
    "id": "dwA7sfRJQDk5IN4eJgtesA",
    "rawId": "dwA7sfRJQDk5IN4eJgtesA",
    "type": "public-key",
    "response": {
      "clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIiwiY2hhbGxlbmdlIjoi…",
      "attestationObject": "o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YViU…",
      "transports": [
        "internal",
        "hybrid"
      ]
    },
    "clientExtensionResults": {}
  },
  "device": "iPhone"
}
HTTP/1.1 201
Content-Type: application/json

{
  "account": {
    "id": "c0rOAOzr0jtlGGeGpluvjQ",
    "label": "Home",
    "created": 1795772788698,
    "passkeys": [
      {
        "id": "dwA7sfRJQDk5IN4eJgtesA",
        "name": "iPhone",
        "created": 1795772788698,
        "synced": true
      }
    ],
    "channels": [],
    "session": "nsDf4rxOjzq3NFKVJdG2AQ"
  },
  "tokens": {
    "session": "nsDf4rxOjzq3NFKVJdG2AQ",
    "accessToken": "poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo",
    "accessTokenExpiresAt": 1795773688698,
    "refreshToken": "poppy_rt.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.65P8qaJ8Pl2zhzDf8eD1JXRCBGpxYiJhI3aokMn9hhE",
    "refreshTokenExpiresAt": 1798364788698
  }
}

GET /api/v1/account

getAccount · apiSession

Retrieve the current account

Returns the account, passkeys, linked channels, and current session ID for the authenticated device.

Responses

200 Account

Authenticated account.

401 Error

Authentication required, or the access token has expired or been revoked.

POST /api/v1/account/claim

claimConversations

Claim browser conversations

Browser-only. Moves anonymous pre-sign-in conversations from the visitor cookie into the signed-in account so they sync across devices. Busy conversations stay behind and are counted in skipped.

Request body object

An empty object, {}.

Responses

200 object

Migration counts and updated account.

moved integer required

Number of conversations moved into the account.

skipped integer required

Number of busy conversations left unclaimed.

account Account required

Updated account state.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Sessions

Authenticate devices with discoverable WebAuthn passkeys and rotate short-lived bearer and refresh tokens.

POST /api/v1/sessions/options

signInOptions

Create sign-in options

Starts usernameless passkey sign-in. Returns WebAuthn request options and a single-use ceremony ID valid for 5 minutes.

Request body object

An empty object, {}.

Responses

200 RequestOptions

WebAuthn request options and ceremony ID.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
POST /api/v1/sessions/options
Content-Type: application/json

{}
HTTP/1.1 200
Content-Type: application/json

{
  "ceremony": "wCo3tWEijhywKSPwr2Ko-g",
  "options": {
    "rpId": "poppylab.dev",
    "challenge": "SEROTUthMEJBYzQ0Qy10aWNhc2Z5OFBkMElHcjB5VGpBOHVaaGtwZlozZw",
    "timeout": 300000,
    "userVerification": "required"
  }
}

POST /api/v1/sessions

signIn

Sign in with a passkey

Verifies a passkey assertion and starts a new device session. Returns SessionTokens to native apps or sets an HttpOnly cookie for browsers.

Request body PasskeyAnswer

Responses

201 SignedIn

Signed in.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
POST /api/v1/sessions
Content-Type: application/json

{
  "ceremony": "wCo3tWEijhywKSPwr2Ko-g",
  "credential": {
    "id": "dwA7sfRJQDk5IN4eJgtesA",
    "rawId": "dwA7sfRJQDk5IN4eJgtesA",
    "type": "public-key",
    "response": {
      "clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoi…",
      "authenticatorData": "SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MFAAAAAA",
      "signature": "MEUCIQDMwoQt0_I1bv5nZsegi8Rr5lxSIXVLj5vKbUN5x3Du_QIg…",
      "userHandle": "c0rOAOzr0jtlGGeGpluvjQ"
    },
    "clientExtensionResults": {}
  },
  "device": "iPad"
}
HTTP/1.1 201
Content-Type: application/json

{
  "account": {
    "id": "c0rOAOzr0jtlGGeGpluvjQ",
    "label": "Home",
    "created": 1795772788698,
    "passkeys": [
      {
        "id": "dwA7sfRJQDk5IN4eJgtesA",
        "name": "iPhone",
        "created": 1795772788698,
        "synced": true
      }
    ],
    "channels": [],
    "session": "nsDf4rxOjzq3NFKVJdG2AQ"
  },
  "tokens": {
    "session": "nsDf4rxOjzq3NFKVJdG2AQ",
    "accessToken": "poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo",
    "accessTokenExpiresAt": 1795773688698,
    "refreshToken": "poppy_rt.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.65P8qaJ8Pl2zhzDf8eD1JXRCBGpxYiJhI3aokMn9hhE",
    "refreshTokenExpiresAt": 1798364788698
  }
}

POST /api/v1/sessions/refresh

refreshSession

Refresh session tokens

Exchanges a native app's refresh token for a fresh access and refresh token pair. Each refresh token is single-use; replaying a spent token revokes the entire session (session_revoked).

Request body object

refreshToken string required

Current refresh token from SessionTokens.

Responses

200 SessionTokens

Rotated token pair.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
POST /api/v1/sessions/refresh
Content-Type: application/json

{
  "refreshToken": "poppy_rt.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.65P8qaJ8Pl2zhzDf8eD1JXRCBGpxYiJhI3aokMn9hhE"
}
HTTP/1.1 200
Content-Type: application/json

{
  "session": "nsDf4rxOjzq3NFKVJdG2AQ",
  "accessToken": "poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.naUO0cj7F9IBYr8d8ezzoJiKRwUtyk5VVmN5V1BHADk",
  "accessTokenExpiresAt": 1795774588698,
  "refreshToken": "poppy_rt.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.bo44NTfc5jOxs2-yDukmbRzcI2rgfPBV8j9g8y9FzRc",
  "refreshTokenExpiresAt": 1798364788698
}

Passkeys

Register additional WebAuthn passkeys on an account or remove compromised ones (ending every session they started).

POST /api/v1/account/passkeys/options

passkeyOptions · apiSession

Create passkey options

Starts adding a new passkey to the authenticated account. Accounts hold up to 10 passkeys.

Request body object

An empty object, {}.

Responses

200 CreationOptions

WebAuthn creation options and ceremony ID.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

409 Error

Account already holds the maximum number of passkeys.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

POST /api/v1/account/passkeys

addPasskey · apiSession

Add a passkey

Verifies the WebAuthn registration response and attaches the new passkey to the account.

Request body PasskeyAnswer

Responses

201 object

Passkey registered.

passkey Passkey required

Newly added passkey.

account Account required

Updated account state.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

409 Error

Passkey is already registered on this account.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

DELETE /api/v1/account/passkeys/{passkey}

removePasskey · apiSession

Remove a passkey

Deletes a passkey and immediately revokes every session started with it (including the current one). Fails with 409 last_passkey if it is the account's only remaining passkey.

Parameters

passkey string, path required

Passkey ID from Account.passkeys.

Responses

200 Account

Passkey removed.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

404 Error

Passkey not found on this account.

409 Error

Cannot remove the account's last remaining passkey.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Devices

List active browser and app sessions (up to 25 per account) and revoke one or all devices.

GET /api/v1/account/sessions

listSessions · apiSession

List active sessions

Returns all active device sessions ordered by most recently used. Accounts keep up to 25 sessions; signing in on a 26th device evicts the least recently used session.

Responses

200 object

Active device sessions.

sessions array of Session required

Active sessions, newest first.

401 Error

Authentication required, or the access token has expired or been revoked.

DELETE /api/v1/account/sessions

revokeAllSessions · apiSession

Revoke all sessions

Signs out every device on the account, including the device making this request.

Responses

200 object

All sessions revoked.

revoked integer required

Number of sessions revoked.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

DELETE /api/v1/account/sessions/{session}

revokeSession · apiSession

Revoke a session

Signs out a single device session without affecting other signed-in devices.

Parameters

session string, path required

Device session ID from GET /api/v1/account/sessions.

Responses

200 object

Session revoked.

revoked integer required

Number of sessions revoked.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

404 Error

Session not found on this account.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

POST /api/v1/account/sign-out

signOut · apiSession

Sign out the current device

Revokes the calling device's session (and clears the browser cookie) while leaving other devices signed in.

Request body object

An empty object, {}.

Responses

200 object

Current device signed out.

revoked integer required

Number of sessions revoked.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Example request & response
POST /api/v1/account/sign-out
Authorization: Bearer poppy_at.c0rOAOzr0jtlGGeGpluvjQ.nsDf4rxOjzq3NFKVJdG2AQ.KNGQT617OSA3c-i9As0a4HxastNzn0rb3CX977GSDSo
Content-Type: application/json

{}
HTTP/1.1 200
Content-Type: application/json

{
  "revoked": 1
}

Channels

Link external messaging channels to an account using short-lived, single-use codes.

POST /api/v1/account/link-codes

createLinkCode · apiSession

Create a channel link code

Issues an 8-character single-use code valid for 5 minutes. Entering it in a supported channel links that channel user to this account.

Request body object

An empty object, {}.

Responses

201 LinkCode

Link code created.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

POST /api/v1/link-codes/redeem

redeemLinkCode

Redeem a channel link code

Called by a configured external channel backend (using its channel authentication) to redeem a user's one-time code and link the channel user ID to the account.

Request body object

channel string required

Configured external channel identifier.

user string required

User identifier within that channel.

code string required

8-character one-time link code provided by the user.

Responses

200 object

Channel linked.

account string required

Linked agent account ID.

linked boolean required

Always true on success.

400 Error

Invalid request payload or precondition failed.

401 Error

Authentication required, or the access token has expired or been revoked.

403 Error

Cross-origin browser request rejected.

429 Error · Retry-After

Rate limit exceeded. Retry after the Retry-After delay.

Schema

Machine-readable OpenAPI 3.1 contract for /api/v1.

GET /api/v1/openapi.json

getOpenApi

Retrieve the OpenAPI schema

Returns this OpenAPI 3.1.0 specification as JSON.

Responses

200 object

OpenAPI 3.1.0 document.

Types

The named types of the document, which the operations above link to. A member marked optional can be absent; a client ignores members it doesn't know.

CompanyRef

Identifies a Company by its origin and display name.

origin string required

Company origin URL, such as https://food-demo.poppylab.dev.

name string required

Human-readable company name for display.

ProposalRef

References a specific proposal at an exact revision. Approvals bind strictly to revision.

company string required

Origin URL of the Company holding the proposal.

proposal string required

Unique proposal ID issued by the Company.

revision string required

Exact revision token shown to the user for approval.

Answer

Structured payload carried by a quick-reply Choice. Must contain exactly one member; Companies are referenced by origin and values are never parsed as free text. approve and decline decide a proposal at its exact revision; signin tells the client to call POST /api/v1/conversations/{id}/sign-ins; signout signs out of that Company; resume retries the request that waited for sign-in; invitation accepts or declines a Direct Conversation.

Exactly one of these shapes:

company string required

Selects an already-connected Company by origin.

connect string required

Connects a new Company by origin URL.

remove array of string required

Disconnects the listed Company origins.

keep array of string required

Keeps only the listed Company origins when replacing a full conversation.

message string required

Sends a scripted prompt text as the user's turn.

approve ProposalRef required

Approves the referenced proposal.

decline ProposalRef required

Declines the referenced proposal.

signin object required

Prompts the client to start a Company sign-in flow.

company string required

Origin URL of the Company to sign in to.

access "read" | "write" required

Permission level to request (read or write).

signout string required

Origin URL of the Company to sign out from.

resume string required

Origin URL of the Company whose pending request should resume after sign-in.

invitation object required

Responds to a Company's invitation to speak directly with the user.

company string required

Origin URL of the Company that sent the invitation.

accept boolean required

true to open a Direct Conversation; false to decline.

Choice

A quick-reply button attached to an agent message. Render label and submit answer verbatim; users may also reply in free text.

label string required

Short button label to display to the user.

answer Answer required

Structured payload to submit to POST /api/v1/conversations/{id}/answers when chosen.

AgentStep

One protocol action taken during a turn, shown in the activity trace.

text string required

Plain-language summary of what the agent did.

how "API" | "Company's agent" | "sign-in" | "setup" required

Channel or phase used for this step.

access "view" | "view and change" | null required

Access level used for this step, or null for signed-out calls.

state "done" | "failed" | "waiting" required

Outcome of this step.

company string optional

Origin URL of the Company involved, when applicable.

args string optional

Sanitized JSON summary of arguments sent to the Company.

AgentMessage

A single message in the conversation transcript.

id string optional

Only in a turn streamed with Accept: text/event-stream, on each of the agent's messages: the ID its message.delta events named. Match it to the sentences shown, and drop shown sentences whose ID no message carries.

from "user" | "agent" | "company" required

Speaker role. agent without company is the agent's own system voice; company is untrusted Company content.

text string required

Message body in plain text or light Markdown.

spoken string optional

Voice-ready version of text (one or two short sentences, no Markdown or IDs, spoken currency). Generated deterministically, never by a model.

company CompanyRef optional

Company this message is from or about.

using array of CompanyRef optional

Companies consulted while producing this reply.

author string optional

Company-provided author label, such as a support agent.

direct boolean optional

true when sent inside a Direct Conversation (§8.10).

choices array of Choice optional

Quick-reply actions for the user.

links array of string optional

Safe HTTPS links surfaced by the turn.

steps array of AgentStep optional

Protocol steps executed during this turn.

data string optional

Pretty-printed structured payload attached to a message.

CompanyState

Connection, authentication, and Direct Conversation state for one Company.

origin string required

Company origin URL.

name string required

Company display name.

url string required

Company homepage URL.

signedIn boolean required

true when the user has an active OAuth grant.

scopes string optional

Space-separated OAuth scopes currently granted.

signingIn boolean required

true while a sign-in flow is in progress.

consentVersion integer required

Monotonic counter incremented each time consent is granted or upgraded.

accessLost boolean required

true when the Company revoked or rejected the stored grant.

direct object required

Direct Conversation status for this Company.

open boolean required

true while a Direct Conversation is active.

invitation string or null required

Reason text for a pending Direct Conversation invitation, or null.

Proposal

A state-changing operation held by a Company for explicit user approval (Operations v3). Nothing executes until approved.

id string required

Operation ID issued by the Company.

company CompanyRef required

Company holding the pending change.

revision string required

Exact revision token required when approving. Changes if terms shift.

summary string optional

Company-authored plain-text summary of the change.

terms object required

Authoritative structured terms computed by the Company (amounts, dates, balances).

state "proposed" | "succeeded" | "declined" | "refused" | "expired" | "superseded" | "uncertain" required

Current lifecycle state of the operation.

expiresAt string required

ISO 8601 timestamp after which the proposal cannot be approved.

result string optional

Outcome message or refusal reason once resolved.

spoken string required

Agent-generated spoken description derived from terms (never the Company's summary).

ConversationState

Complete snapshot of a conversation, its connected Companies, transcript, and proposals.

id string required

Unique conversation identifier.

active boolean required

true while open; false once ended and read-only.

keptUntil integer optional

Unix timestamp (ms) when an ended conversation is purged from storage.

companies array of CompanyState required

Currently connected Companies (up to 3).

removed array of CompanyRef required

Companies previously disconnected from this conversation.

messages array of AgentMessage required

Ordered conversation transcript.

proposals array of Proposal required

All proposals raised in this conversation.

TurnResult

Result of a completed message or quick-reply turn.

conversation string required

Conversation ID.

messages array of AgentMessage required

Messages added during this turn (or the full list when replaced is true).

replaced boolean required

true when earlier messages were withdrawn (for example after losing access or disconnecting a Company).

state ConversationState required

Full updated conversation state.

MessageDelta

One sentence of one of the agent's messages, sent as soon as it is written. A voice client speaks spoken as each one arrives.

type "message.delta" required

Always message.delta; also the SSE event name.

message string required

ID of the agent message this sentence belongs to; the turn event's message with this id holds the whole text.

index integer required

Position of the sentence within its message, from 0.

text string required

The sentence as written, with the whitespace around it, so the texts of one message joined are its text. Ends at a stop, a line's end, or a clause or space before about 220 characters; never inside a word.

spoken string required

The sentence to read aloud, made by the same fixed rules as a message's spoken. Empty when it holds nothing to say, such as a table row or a link.

TurnEvent

One Server-Sent Event of a turn streamed with Accept: text/event-stream; type matches the SSE event: field. message.delta events come first, one per sentence, then exactly one turn or error. Only the agent's words come as sentences: Company content comes whole in the result as its own message (§10.1). Demo-mode answers and the agent's own lines, which are ready at once, come as sentences too, all together just before turn.

Exactly one of these shapes:

MessageDelta

type "turn" required

Always turn; the last event of a turn that ended.

result TurnResult required

The same result as the JSON answer; each agent message carries the id its sentences named.

type "error" required

Always error; the last event of a turn that failed after it began.

status integer required

The HTTP status the JSON answer would have had.

code string optional

Machine-readable error code, when there is one.

error string required

User-facing explanation that can be shown as is.

ModelChoice

Selects which model handles a turn. Defaults to demo when omitted.

provider "demo" | "free" | "openai-compatible" | "anthropic" required

Model backend: demo (scripted examples, no LLM), free (deployment's Workers AI model), or bring-your-own-key (openai-compatible, anthropic).

apiKey string optional

Provider API key for openai-compatible or anthropic. Sent per request and never stored.

model string optional

Optional model identifier for bring-your-own-key providers.

turnstile string optional

Single-use Cloudflare Turnstile token required for free turns. Missing, invalid, or over-quota turns fall back to demo with an explanatory note.

Decision

Outcome of approving or declining a proposal.

proposal Proposal required

Updated proposal after applying the decision.

state ConversationState required

Full updated conversation state.

SignIn

Details for launching a Company OAuth sign-in flow. The agent never sees the user's password; final status arrives on the SSE event stream.

url string required

URL to open for consent. For browsers: the Company's consent page. For apps: a single-use agent link to open in ASWebAuthenticationSession (or equivalent).

expiresAt integer optional

Unix timestamp (ms) when an app sign-in link expires (3 minutes).

endUrl string optional

Fixed callback completion URL an app watches for (?result=done or ?result=failed).

AgentEvent

One Server-Sent Event payload. type matches the SSE event: field; the initial event is always state.

type "state" | "message" | "messages.replaced" | "signin.completed" | "signin.failed" | "access.lost" | "signout" | "proposal.created" | "proposal.expired" | "proposal.replaced" | "proposal.updated" | "company.added" | "company.removed" | "conversation.ended" | "session.ended" required

Event type and SSE event name.

state ConversationState optional

Present on state and messages.replaced.

message AgentMessage optional

Present on message.

company CompanyRef optional

Present on signin.*, access.lost, signout, and company.*.

proposal Proposal optional

Present on proposal.*.

keptUntil integer optional

Unix timestamp (ms) until an ended conversation is purged. Present on conversation.ended.

code "invalid_token" | "session_revoked" optional

Present on session.ended: invalid_token means refresh the access token and reconnect; session_revoked means sign in again.

Error

Standard error envelope returned on 4xx and 5xx responses.

code string optional

Stable machine-readable error code for programmatic handling.

error string required

Plain-language error message safe to show to the user.

Passkey

Metadata for a WebAuthn passkey registered on an account. Public keys are never returned.

id string required

Unique passkey identifier within the account.

name string required

Device description captured when the passkey was registered.

created integer required

Unix timestamp (ms) when the passkey was added.

lastUsed integer optional

Unix timestamp (ms) when the passkey was last used to sign in.

synced boolean required

true when the authenticator reports multi-device passkey backup.

Account

An anonymous passkey-backed agent account. Holds no email or password.

id string required

Opaque account identifier.

label string optional

Optional user-chosen label for the account.

created integer required

Unix timestamp (ms) when the account was created.

passkeys array of Passkey required

Passkeys registered on this account.

channels array of object required

External channels linked via one-time link codes.

channel string required

Linked external channel name.

linked integer required

Unix timestamp (ms) when the channel was linked.

session string required

Session ID authenticating the current request.

unclaimed integer optional

Browser-only count of anonymous pre-sign-in conversations available to claim.

SessionTokens

Bearer and rotating refresh tokens issued to native client apps. Store in the OS keychain; never log or place in URLs.

session string required

Device session identifier.

accessToken string required

Short-lived bearer token (~15 min). Send in Authorization: Bearer <token>.

accessTokenExpiresAt integer required

Unix timestamp (ms) when accessToken expires.

refreshToken string required

Single-use rotating refresh token. Reusing a spent token revokes the entire session.

refreshTokenExpiresAt integer required

Unix timestamp (ms) when refreshToken expires.

SignedIn

Returned after creating an account or signing in with a passkey.

account Account required

The authenticated account.

tokens SessionTokens optional

Returned only to native apps (requests without an Origin header); browsers receive an HttpOnly cookie.

CreationOptions

Challenge and WebAuthn creation options for registering a new passkey.

ceremony string required

Opaque single-use ceremony ID to echo back within 5 minutes.

options object required

WebAuthn PublicKeyCredentialCreationOptionsJSON for navigator.credentials.create.

RequestOptions

Challenge and WebAuthn request options for usernameless passkey sign-in.

ceremony string required

Opaque single-use ceremony ID to echo back within 5 minutes.

options object required

Discoverable WebAuthn PublicKeyCredentialRequestOptionsJSON for navigator.credentials.get.

PasskeyAnswer

Completes a passkey registration or sign-in ceremony.

ceremony string required

Ceremony ID received from the corresponding /options call.

credential object required

Authenticator response (RegistrationResponseJSON or AuthenticationResponseJSON).

device string optional

Optional device label shown in the sessions list (e.g. "iPhone" or "Chrome on macOS").

Session

An active device session signed in to an account.

id string required

Unique device session identifier.

kind "browser" | "app" required

browser (cookie-backed) or app (token-backed).

device string required

Device description recorded at sign-in.

created integer required

Unix timestamp (ms) when the session started.

lastUsed integer required

Unix timestamp (ms) of the last authenticated request.

expires integer required

Unix timestamp (ms) when the session expires.

current boolean required

true for the session authenticating this request.

LinkCode

Single-use code linking an external messaging channel to an account.

code string required

Formatted 8-character one-time code to enter in the channel.

expiresAt integer required

Unix timestamp (ms) when the code expires (5 minutes).