The example does not stop at selling credits. It also shows how the product consumes them.
Relevant files:
Workspace action
The workspace triggers credit consumption through the browser API client:
const response = await client.credits.consume({
payload: {
amount: 25,
reason: "AI note summarization"
}
})The server then calls:
return (
yield *
sdk.credits.consume({
customerId: asCustomerId(input.user.id),
creditKey: "ai_credits",
amount: input.amount,
idempotencyKey: `${input.user.id}:${Date.now()}:${input.amount}`,
reason: input.reason
})
)Why this matters
Selling credits is easy to demo. Safely consuming them in real product actions is the harder part. This example shows the intended shape for that runtime boundary.