Skip to content

Token API

These routes are available only when FRAMEKIT_AUTH_ENABLED=true. See the access overview for the shared cookie, origin, request, and response rules.

Returns 200 with an array of the signed-in user’s token metadata. Each item contains id, name, tokenPrefix, createdAt, lastUsedAt, and revokedAt. The full secret is not included.

Requires a same-origin session mutation. Send exactly:

{
"name": "image-renderer"
}

Access routes use the session cookie rather than Bearer tokens. Keep the server-side FRAMEKIT_SESSION_COOKIE value private, and send it with a matching Origin:

const origin = process.env.FRAMEKIT_ORIGIN ?? 'http://localhost:3000'
const sessionCookie = process.env.FRAMEKIT_SESSION_COOKIE
if (!sessionCookie) throw new Error('FRAMEKIT_SESSION_COOKIE is required')
const response = await fetch(`${origin}/api/framekit/tokens`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Cookie: `framekit_session=${sessionCookie}`,
Origin: origin
},
body: JSON.stringify({ name: 'image-renderer' })
})
console.log(response.status, await response.json())

The trimmed name must be 1-80 characters. A successful response is 201 and contains the metadata plus token. The generated secret starts with fk_ and is returned only in this response. Store it server-side before discarding the response; it is not returned again.

An owner can revoke an own token. An administrator can revoke any token. A successful response is 200 with { "status": "ok" }. Revocation leaves metadata available with revokedAt set and cannot be undone through the API.