Examples
Recipes for common integrations, plus runnable examples in the repository.
Recipes
Each recipe is a complete pattern you can adapt. Rules and URLs are illustrative; set limits from your provider's documented quota.
HTTP clients
fetch, undici, axios, and got, with provider feedback.
Batch scripts
Process a large list within a quota, with progress and failures.
Queue workers
Share one quota across BullMQ worker processes.
Request handlers
Call a provider from a web server and fail fast when busy.
Per-tenant budgets
One valve per customer credential, created on demand.
Layered quotas
Per-second and daily limits, with weighted endpoints.
Runnable examples
The repository includes small, self-checking programs under
examples/. Each
asserts its own result and needs no provider credentials.
| Example | Shows | Needs Redis |
|---|---|---|
memory | Spacing calls in one process with the default memory store. | No |
priorities | Interactive work starting before background work. | No |
observe | Feeding an axios-shaped response into shared feedback. | No |
shutdown | Rejecting queued work and finishing running work on close. | No |
shared | Six valve instances sharing one Redis budget. | Yes |
feedback | A 429 in one valve pausing another valve on the same budget. | Yes |
Build the workspace once, then run any example by name:
pnpm install
pnpm build
pnpm --filter @valve/example-memory startFor the Redis examples, start a server and set REDIS_URL:
docker compose -f compose.test.yml up -d
REDIS_URL=redis://127.0.0.1:6379 pnpm --filter @valve/example-feedback startpnpm examples runs all six in sequence.