Skip to main content
Needs a keypair, a JWKS document, a minting endpoint, and allowed origins set on the workspace. Work through Direct integration first — this example assumes that setup exists.

Backend: mint a token

Two minutes is deliberate. The browser remints as needed, so a leaked token is worth almost nothing.

Frontend: the SDK

@usepatchwork/react handles minting, realtime subscription, streaming, and the polling fallback.
useAgent gives you messages, threads, send, openThread, and newChat. Assistant content streams in as message.delta events when realtime is enabled, and falls back to polling when it is not.

Without the SDK

The browser calls the same endpoints, minting before each:
Note there is no Patchwork-Subject header here — the subject rides in the token’s sub, and any subject in the body would be ignored.

Handling pauses in a UI

A chat UI is the best place to surface a pause, because the user is right there.
  • pending_elicitation — the agent’s question is just another message. Nothing special to do.
  • pending_confirmation — render summary as an approval prompt with approve and reject buttons, then call the confirm endpoint. See Approving a write.
  • pending_action — do the work in the UI, then post the outcome.

Do not put sk_… in the browser

The workspace key can assert any subject in your workspace. In direct integration it never leaves your servers — that is the entire reason the mode exists.