Turn any REST, GraphQL, SSE, or LLM API into a typed, resilient function.
Declare an external API once; call it like a function, the network out of sight. That same definition is a tool an AI agent can call — and it inherits the whole runtime: retries, streaming, and responses trimmed to the fields that matter, so they spend far fewer tokens — never the credential, only the capability.
import { stitch } from 'stitchapi';
import { z } from 'zod';
const User = z.object({ id: z.string(), name: z.string() });
// Declare once — types, validation, resilience.
const getUser = stitch({
path: 'https://demo.stitchapi.dev/users/{id}',
output: User, // validator of your choice
retry: 3,
timeout: '5s',
cache: '1m',
});
// Call it like a local function.
const user = await getUser({ params: { id: '42' } });
// → typed · validated · retried · cachedWhen the caller is an agent, it inherits the whole runtime
A hand-wrapped MCP tool forwards raw bytes and a stored key. The same stitch hands an agent a production runtime — and never the secret behind it.
Responses sized for context
Output comes back unwrapped, validated, and trimmed to the fields you declared — the model reads structured data, not an 8 KB raw payload. Fewer tokens, less noise.
Streaming it can act on
Typed start → progress → drift → result events stream back, so an agent reacts to partial results instead of blocking on opaque bytes.
Resilience off the prompt
Retries with backoff, throttling, and timeouts are the runtime’s job, not the model’s — reliability never has to live in the reasoning.
A capability, not a credential
Auth lives at the stitch. The agent invokes it and receives data, never the token behind it — safe to hand to a caller you don’t fully trust.
Built on the platform’s global fetch — nothing to install, nothing to audit, nothing in your transitive tree.
The whole stitchapi entry, tree-shaken — and it is an enforced budget in CI, not an aspiration.
Pay only for what you import: every surface beyond http lives behind its own subpath, so the core trims down.
fetch hands you bytes. Everything that makes it reliable, you write yourself.
A stitch folds it into the call — validation, retries, timeouts, throttling, drift, and traces — declared once and uniform across every endpoint, so you stop re-solving them per integration.
Define the stitch once. Reach it four ways.
The same typed unit is a function, a CLI command, an HTTP route, and an MCP tool — so humans and agents call exactly the same validated, observable thing.
In-process function
await getUser({ params: { id: '42' } })Import the stitch and call it like any typed function — awaitable or streamable.
CLI command
$ stitch run getUser --id 42Run the same definition from a shell or a script, no app boot required.
HTTP endpoint
GET /get-user?id=42Serve a stitch as a route — validated in, validated out, traced by default.
MCP / agent tool
tool: get_userAgents invoke it directly and receive a capability — never the underlying secret.
Everything fetch left to you — declared, defaulted, and observable
Progressive disclosure: stitch('https://…') just works, and every capability reveals its knobs only when you reach for them.
Runtime drift detection
Every response is validated against its contract, so a vendor silently renaming a field surfaces immediately — not hours later as a downstream undefined.
Validation, then re-prompt
Schemas guard params, query, body, and output. On a mismatch the stitch can re-prompt instead of handing garbage back to a model.
Reliability built in
Retries with backoff + jitter, Retry-After, idempotency keys, throttling, and circuit breaking — declared per stitch, not bolted on.
Layered timeouts
Total, step, and chunk timeouts plus AbortSignal, so a slow upstream never quietly hangs your call.
The event stream is the spine
start → progress → drift → result → done. Streaming output, observability, and drift all read the same stream a stitch emits.
Capability, not credential
Auth lives at the stitch. Callers — including agents — get data without ever seeing the secret behind it.
Compose, don’t configure
baseUrl, auth, retry, throttle, and hooks are named, shareable values you compose with .with() and extends — no central config object.
Observable by default
gen_ai.* and mcp.* spans carry tokens, cost, and latency, turning the agent-native layer into your integration-health layer.
What StitchAPI is not
Knowing what a tool refuses to be is how you trust what it is. StitchAPI holds a hard line on scope.
Not an HTTP client or fetch replacement
fetch and axios are the substrate underneath — bring your own adapter. A stitch sits above the transport and turns an endpoint into a function; it never reimplements the call.
Not a code generator
There's no SDK to commit, diff, and regenerate. The declaration is the runtime, validated live on every call — so it can't fall out of date with the API.
Not spec-first
No OpenAPI document required. A URL and one example response is enough — so it reaches the internal and undocumented long tail codegen never covers.
Not a server to deploy
Nothing to run or operate, and you don't own both ends. It's a zero-dependency library you import — for the APIs you don't control.
Not a workflow engine or iPaaS
No orchestration, queues, or visual builder. Composition is plain TypeScript; the stitch is the boundary and nothing more.
No config files or hidden inheritance
Nothing ambient or global a stitch silently reads — everything that shapes a call is composed in explicitly. Read one stitch and you know exactly what it does.
No server, no codegen, no config files, no implicit inheritance — only explicit composition.
Built for the two quadrants nobody else covers
tRPC-grade ergonomics for the APIs you don’t own — declared once, called like a local function. These are the two gaps every other approach leaves open.
Spec-less long tail
Every serious competitor needs an OpenAPI spec. A stitch needs one endpoint — or one example. Author from the response you already have.
Heterogeneous & agent-native
A lightweight library where HTTP, GraphQL, shell, and LLM are symmetric, declared primitives — kind-agnostic today, composable into bigger stitches tomorrow.
Notes on stitching APIs
Field notes on API stitching, agent-native integrations, and cutting AI cost.
Keep Coding Agents on Your API Layer
An agent that has never seen StitchAPI hand-rolls fetch and rediscovers your conventions every session. One committed rule — written by npx stitch init — teaches it the habit for the price of a ~300-token file it reads once, instead of the ~115k-token docs corpus or a repo-exploration detour it pays every time.
Validate Calls Against Schemas You Obtain at Runtime
Sometimes the schema you validate against shows up at runtime — you fetch it, a tenant registers it, a config push delivers it — as JSON Schema you didn't have when you compiled. You can't generate types for it; validate the incoming data at the boundary instead, and return structured errors the sender can act on.
Run Independent API Calls in Parallel: all, any, race
When API calls do not depend on each other, running them as a ladder of awaits is wasted latency — and Promise.all drops the trace, the cancellation, and the per-call resilience. all, any, and race run independent stitches concurrently as one traced, fail-fast group, and because each returns the same callable shape a stitch does, they nest.
Adopt StitchAPI Without a Rewrite
Wrap one endpoint as a stitch, leave the rest of your fetch and axios code untouched, and grow the typed-resilient surface one call at a time.
Stitch your first API. Start with one endpoint.
Declare your first stitch and call it as a typed function in five minutes — then reach the same definition from the CLI, HTTP, or an agent.