Release candidate — 1.0.0-rc.1
StitchAPI
GuidesAuthoring & composition

seam

Group stitches under one shared runtime — store, vault, throttle bucket, and trace sink — behind a shared base config, and bind per-principal sessions with seam.as().

Use seam when several stitches hit the same API and should share one runtime — one throttle budget, one store, one trace sink, one auth vault — instead of each carrying its own copy of the config. Build it once, then create members with .stitch() and .graphql().

Example

import { , ,  } from 'stitchapi';
import {  } from 'zod';

const  = .({
    : .(),
    : .(),
    : .(),
    : .(['admin', 'member', 'viewer']),
});

// Build the seam once: its config is the base every member inherits, and its
// runtime — store, vault, throttle bucket, trace sink — is shared across them.
const  = ({
    : 'https://demo.stitchapi.dev',
    : (('API_TOKEN')),
    : { : 3, : [429, 503] },
});

// Members are stitches that belong to the seam.
const  = .({
    : '/users/{id}',
    : 'data',
    : ,
});
const  = .({
    : '/users',
    : 'data',
    : .(),
});

const  = await ({ : { : 7 } });

Options

A seam takes the same fields a stitch does — baseUrl, auth, retry, throttle, timeout, store, trace, and the rest — as the base its members extend, plus a secretStore for a hardened auth vault. See Reference → Config types for every field.

Members extend the base; a member's own throttle stacks on the seam's. Anything a member declares layers on top of the shared config — and a member's own throttle is tighten-only: it gates only that stitch on top of the shared bucket, so it can be stricter than the seam's budget but never escape it.

Per-principal sessions — seam.as(id). Derive a handle whose members carry a principal. The handle binds that principal in the closure, never in the call's input, so a caller can't name another one. Each principal gets its own sessions; the throttle bucket stays shared.

import {  } from 'stitchapi';

const  = ({ : 'https://demo.stitchapi.dev' });

// One handle per request — bind the caller's identity, then create members.
const  = .('tenant-42');
const  = .({ : '/users/{id}', : 'data' });

Anti-pattern: don't build a fresh seam per request — you'd get a new store, throttle bucket, and vault each time, so nothing pools or persists. Build the seam once at startup and derive a per-request identity with seam.as(req.user.id) instead.

Lifecycle — flush / close / invalidate. These act on the shared runtime, so they live on the root seam only (a seam.as(...) handle is lifecycle-free). close() flushes the trace sink and closes the shared store on shutdown; invalidate() bulk-evicts the cache across members.

import {  } from 'stitchapi';

const  = ({ : 'https://demo.stitchapi.dev' });
// ... build members, serve requests ...

await .(); // flush the trace sink, close the shared store

See also

On this page