Use from an agent
How an agent invokes, authors, and reasons over stitches — the agent entry point.
StitchAPI is agent-native because of two choices that fall out of the stitch primitive: an agent receives a capability, not a credential — it invokes a stitch and gets back structured, validated, traceable data without ever touching the secret — and it works through one context-frugal tool, not one tool per endpoint, so adding APIs never floods the model's context window.
An agent does three things with a stitch: invokes it, authors it, and reasons over it — one subsection each.
Invoke
An agent drives stitches from a sandbox through a single code-mode tool,
run_stitch, rather than a generated tool per endpoint. The agent writes a small
TypeScript snippet that imports stitchapi, calls the stitch, and returns
the result — list_stitches tells it what is available to call, and
describe_stitch tells it the shape of one before running it.
import { } from 'stitchapi';
import { } from 'zod';
const = ({
: 'https://api.example.com',
: '/users/{id}',
: .({ : .(), : .() }),
});
// The agent writes this in the sandbox; run_stitch executes it.
const = await ({ : { : 7 } });The output schema (raw Zod here, the visible default) means the agent gets a
validated, typed value back, not a guess. One tool keeps the context budget flat
as the catalog grows, and the credential stays behind the boundary — the agent
sees the user, never the token. Three tools make up the code-mode surface:
run_stitch to execute, list_stitches to discover names, and
describe_stitch to understand a stitch's shape, schema, and diagram before
running it.
run_stitch & code-mode
The tool an agent calls, plus list_stitches and describe_stitch.
MCP surface
How those tools reach the agent over MCP.
Author
An agent does not need a spec to add an API. Hand it a single example — a curl
command, a HAR entry, or a snippet from a vendor's docs — and it emits a stitch
declaration: the URL, the input shape, and an output schema inferred from the
one response it saw. For the common curl/HAR case there is also a deterministic
shortcut — stitch from-curl '<curl>' prints the same declaration with no model
in the loop (id-like path segments lifted, credentials replaced with env()).
Either way the declaration is committable code the agent (or you) can review.
Adopt in your project
Drop a short rule into your repo and any agent working in it reaches for a typed
stitch instead of a hand-rolled fetch/axios whenever it adds an external
API. Hand-copy the rule, or run npx stitch init to write it as AGENTS.md, a
Cursor rule, or a CLAUDE.md section.
That rule teaches an agent to write stitches. A companion rule teaches it to look up how — point it at these docs over MCP so it searches the current API before answering instead of guessing from training data.
Adopt in your project
The consumer rule agents follow, plus npx stitch init.
Search the docs over MCP
Give the agent a rule to search_docs before it answers.
Reason over
Two outputs let an agent reason about stitches cheaply. The docs build emits an
auto-generated llms.txt and a per-page llms.mdx, so an agent pulls just the
one page it needs into context instead of the whole manual. And every call is a
typed event stream — start → progress → drift → result → done — so the
agent reads not just the final value but the retry that succeeded, the throttle
that paused, and the field that drifted.
Point an agent at llms.txt
Feed the auto-generated llms.txt and per-page llms.mdx for context-frugal docs.
The event stream
The typed events a stitch emits, and why an agent reads them.
These three pages assume the runtime is already installed and a stitch is declared. Start at the Quickstart if it is not.
See also
Sentry
A Sentry TraceSink that maps the stitch event stream to breadcrumbs and captures error events with the call's context — metadata-only, safe on a secret-bearing seam.
run_stitch & code-mode
Drive stitches from a sandbox with one context-frugal tool instead of flooding the model with per-endpoint tools.