Skip to content

Runtime auth

capa’s default deployment stays simple: one capability Worker, one upstream credential stored as a Worker secret.

Terminal window
wrangler secret put STRIPE_API_KEY

That is a good fit when you deploy the capability for yourself.

Workflow builders and SaaS platforms need a second mode: deploy one shared capability Worker, then choose the tenant credential for each RPC call.

await env.STRIPE.paymentIntents.create(
{ amount: 2500, currency: "usd" },
{ auth: { apiKey: tenant.stripeKey } },
);

Static Worker secrets remain the default. Runtime auth is an opt-in override for that single call.

Deployment modeCredential sourceFit
Static secretSTRIPE_API_KEY Worker secretone app / one provider account
Runtime authoptions.auth.apiKeyone shared capability / many tenant accounts

The options bag should stay small:

interface CallOptions {
auth?: {
apiKey?: string;
headers?: Record<string, string>;
};
}

Generated methods keep their current shape and add options? at the end:

retrieve(id, options?)
create(body, options?)
update(id, body, options?)

Some APIs need more than the primary token. Twitch Helix requires both:

Authorization: Bearer <token>
Client-Id: <client id>

The target runtime shape is:

await env.TWITCH.channels.list(input, {
auth: {
apiKey: tenant.twitchToken,
headers: { "Client-Id": tenant.twitchClientId },
},
});

The same pattern covers provider-specific secondary auth/context headers without inventing a new auth mode for every API.

Runtime auth is for credentials, not arbitrary request routing.

AllowedNot part of this feature
Per-call provider API key/tokenPer-call upstream base URL
Per-call provider-required auth headersTenant database inside capa
Existing Worker secret fallbackOAuth refresh orchestration
Credentials excluded from returned receiptsCredential values echoed in evidence

Per-call provider secrets already exist in the calling platform, so capa should avoid amplifying exposure:

  • never include auth.apiKey or auth.headers values in evidence receipts
  • never echo credential values in runtime errors
  • keep per-call headers constrained to auth/context use, not a generic proxy feature
  • use narrowly scoped provider credentials where the provider supports them

A workflow product can model each capability as a node:

Stripe node
GitHub node
Slack node
Twitch node

and run them through one deployed capability Worker per API, while each workflow invocation uses that customer’s provider credential.