Skip to main content
Direct is the default for a product UI. The browser never sees a workspace API key.

1. Create a signing keypair

Generate an RSA (or EC) keypair. The private key signs tokens and never leaves your servers. The public key is what Patchwork uses to verify — it is not a secret.
Allowed algorithms: RS256, RS384, RS512, ES256, ES384, ES512, PS256, PS384, PS512. Symmetric (HS*) is rejected.

2. Publish your public key

Serve the public key as a JWKS document at a stable URL. Patchwork fetches and caches it, matching each token to a key by kid. Rotation is adding a new key alongside the old one.
If you cannot host a JWKS URL, paste the public key in the dashboard instead. In Connections, create a host (name + base_url) and set workspace ingress: JWKS URI, allowed origins, request secret, mint URL. Allowed origins are required so the browser can call Patchwork — no wildcards.

3. Mint a session token

Add one endpoint to your backend, authenticated by your existing user session. It returns a short-lived JWT signed with your private key.
string
required
Your API key public id (key_…), not the secret.
string[]
required
Must include patchwork. Include your own API audience as well so the same token can pass your tool middleware.
string
required
Your user id. Becomes the thread subject.
uuid
Connection id this token may call. A UUID — not a name, not a URL. Required when the agent has unpinned customer tools.
integer
required
Unix timestamp. Keep it short — about 120 seconds. The browser remints as needed.
string
required
JWT header. Names the signing key so we match it in your JWKS.
Do not put a workspace secret (sk_…) in the browser. The session token is the only credential the client holds, and it expires in minutes. A token must authorize no more than the user could do themselves.

4. Call Loom from the browser

The message response is 202 with a run_id. Poll GET /v1/loom/runs/:id or subscribe to the thread channel — see Realtime.

5. Verify tool calls you host

Every call we make to your backend carries the session token and a Patchwork-Signature over your request secret. A stolen token is useless without the secret.
Verify the signature, verify the token, then hydrate your normal request context. Your existing authorization runs unchanged.

React

@usepatchwork/react wraps the browser side. You provide url and a mint function that returns the session token. Optional connection pins the host.
useAgent gives you messages, threads, send, openThread, and newChat. See the package readme.