StitchAPI is an "agent-native" runtime whose core primitive is the stitch: it takes a single API endpoint and returns a callable object. You declare the contract once—input, output, auth, resilience—and thereafter you can call it like a local function. The same definition can be called by your code, the CLI, and AI agents, and each caller receives a capability, not credentials. A service containing multiple endpoints is called a seam, i.e. a group of stitches that share a base URL, auth, and the same runtime (rate-limit budget, storage, trace sink).
StitchAPI is not meant to replace fetch or axios, but to sit above the transport layer and turn endpoints into functions. It does not require an OpenAPI document; a URL and a sample response are enough to get started. It is also not a code generator, not a server that needs to be deployed, not a workflow engine or iPaaS, with no config files or implicit inheritance, only explicit composition.
Key capabilities include:
- Event-stream core: each call produces a typed event stream (start → progress → drift → result → done), and await is syntactic sugar that returns the final validated value.
- Bring your own validation: supports Zod or any Standard Schema validator (Valibot, ArkType, etc.), with types inferred from the schema.
- Tiered drift detection: live responses are compared against the declared schema; missing/incompatible required fields throw an error, while soft drift (coercion, undeclared or default fields) is surfaced as non-fatal warn/info/verbose signals.
- Declarative resilience: retries (with backoff and Retry-After), proactive rate limiting, layered timeouts, circuit breaking, idempotency keys.
- Read-through caching: optional response caching + in-process coalescing, with keys derived and scoped by principal, lazily loaded from stitchapi/cache.
- Auth boundary: supports bearer, apiKey, basic, cookieSession (automatic login/re-login), oauth2; secrets are resolved at call time and never exposed to the caller.
- Arbitrary request styles: http by default; graphql, sse, stream, download, llm, shell, postmessage as peer surfaces imported via subpaths.
- Pluggable state storage: rate-limit state,cache, and sessions are stored via get/set, and can be swapped for Redis/Postgres implementations for distribution.
- Zero-infrastructure observability: tracing is off by default and can be enabled per stitch or via environment variables, with no collector or dashboard required.
- Four front doors, one definition: in-process function, CLI (stitch run), HTTP (stitch serve), MCP (stitch mcp).
- Zero runtime dependencies: "dependencies": {}, built on global fetch, tree-shakeable; the entire entry is about 21 kB (min+gzip), and a typical import { stitch } is about 19 kB.
Usage: install stitchapi via npm, then declare an endpoint with stitch(url | config). Path parameters use RFC 6570 URI templates; params, query, headers, and body are all passed in a single input object. Optional configuration such as resilience, caching, and auth is off by default and enabled as needed. stitch produces a typed event stream, await consumes it and returns the final value, .safe() resolves to { ok, data, error }, and .stream() yields progress, rate-limit waits, retries, and drift in real time.
Use cases: projects that need to quickly turn internal, undocumented, or long-tail APIs into reliable, observable functions; scenarios where you want AI agents to safely call APIs without exposing credentials; integration work that needs unified cross-cutting concerns such as retries, rate limiting, timeouts, and caching.
Limitations: the current version is 1.0.0-rc.8; the core runtime functionality is complete but still undergoing production validation, so pinning an exact version is recommended. Validators must be brought by you; no validation library is bundled. Caching and the OTLP exporter are lazily loaded and are not counted in the above size.