API introspection SDK. Adds endpoints that return all available API procedures with their types, descriptions, and input/output schemas as JSON Schema. Designed for AI agents to autonomously discover and learn how to use your API.
| Package | Description |
|---|---|
@api-introspect/core |
Framework-agnostic types and utilities |
@api-introspect/trpc |
tRPC router introspection |
@api-introspect/fastify |
Fastify route introspection |
api-introspect |
CLI and HTTP client |
pnpm add @api-introspect/trpcimport { withIntrospection } from '@api-introspect/trpc'
const rootRouter = withIntrospection(t, appRouter, {
meta: { name: 'My API' },
})pnpm add @api-introspect/fastifyimport { introspection } from '@api-introspect/fastify'
await app.register(introspection, {
meta: { name: 'My API' },
})# List all endpoints
npx api-introspect http://localhost:3000
# Call an endpoint
npx api-introspect http://localhost:3000 user.getById '{"id":1}'The introspection endpoint returns:
{
"name": "My API",
"baseUrl": "http://localhost:3000",
"description": "tRPC API...",
"auth": {
"type": "header",
"name": "x-api-key"
},
"serializer": "json",
"endpoints": [
{
"path": "user.list",
"type": "query",
"description": "List all users"
},
{
"path": "user.create",
"type": "mutation",
"description": "Create a new user",
"auth": true,
"input": [
{
"in": "body",
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
]
}
]
},
{
"path": "/users/{id}",
"type": "http",
"method": "PATCH",
"input": [
{
"in": "path",
"type": "object",
"properties": {
"id": {
"type": "number"
}
},
"required": [
"id"
]
},
{
"in": "body",
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
]
}
]
}pnpm dev:trpc # tRPC server on http://localhost:3000
pnpm dev:fastify # Fastify server on http://localhost:3001- examples/trpc - tRPC server with queries, mutations, and auth middleware
- examples/fastify - Fastify HTTP server with TypeBox schemas
pnpm dev:trpc # run tRPC example in watch mode
pnpm dev:fastify # run Fastify example in watch mode
pnpm build # build all packages
pnpm test # run all tests
pnpm lint:fix # lint- 0.13.3: Fastify introspection now normalizes
:parampath parameters to{param}format for consistency with OpenAPI conventions. - 0.13.2:
compactSchemanow preserves nullable object/arrayanyOfinstead of flattening totype: [X, "null"]for better toolchain compatibility. - 0.13.1: Rename
InputLocationvalue from'params'to'path'for consistency with OpenAPI conventions. - 0.13.0: Unify input schemas into a single
inputarray withinfield ('path','query','body'). NewInputSchemaandInputLocationtypes exported from core. Meta fields flattened directly into endpoint objects (no moremetawrapper).compactSchemanow retainsdefaultvalues. CLI client routes input byinlocation (path, query, body) when calling HTTP endpoints. - 0.12.0: Add
IntrospectionMetatype with requirednameand extensible fields. Meta fields are now flattened directly into the introspection response instead of cherry-picking known keys.IntrospectionResultuses an index signature for arbitrary top-level fields. - 0.11.2: Custom
meta.descriptionnow replaces the default description instead of appending to it. - 0.11.1: Improve default descriptions: tRPC uses "procedures", Fastify uses "endpoints". CLI help text uses generic "endpoint" terminology covering both tRPC procedures and HTTP routes. CLI summary output uses correct noun ("endpoints" vs "procedures") based on introspection payload. Fix Fastify plugin excluding its own introspection route when using a custom path.
- 0.11.0: Fastify plugin now returns
endpointsinstead ofproceduresin the introspection payload. AddbaseUrlandauthto themetaoption for both tRPC and Fastify plugins, included in the introspection response when provided. CLI client supports bothendpointsandproceduresfields for backward compatibility. Fix default introspection path and URL joining with leading slashes. - 0.10.0: Fastify introspection now returns separate
params,query, andbodyfields instead of a mergedinputfield, matching HTTP semantics more precisely.compactSchemanow strips additional noise keys (pattern,format,title,default,examples,$id) and simplifiesanyOfwithconstvalues intoenum. CoreEndpointInfotype updated:HttpEndpointInfousesparams/query/body,RpcEndpointInforetainsinput. - 0.9.0: Add
metafield support to route and procedure introspection. Custom metadata (e.g.auth,tags) from tRPC.meta()and Fastify routeconfig.metais now included in the introspection payload. - 0.8.0: Breaking: Restructure as monorepo with
@api-introspect/core,@api-introspect/trpc,@api-introspect/fastify, andapi-introspect(CLI). Add Fastify introspection plugin with route and schema extraction. Preserve HTTP methods in endpoint info for REST APIs. Removefilteroption from introspection (use CLI procedure argument instead). Rename CLI fromtrpc-introspecttoapi-introspect. The oldtrpc-introspectnpm package is deprecated. - 0.7.1: Fix TS2742 error for consumers by bundling DTS per entry point.
- 0.7.0: Add
compactSchemaexport that strips noise from JSON Schema output. - 0.6.0: Add
--summaryand--fullCLI flags for output format control. - 0.5.0: Add client module and CLI for discovering and invoking procedures from the terminal.
- 0.4.0: Breaking: Remove
addIntrospectionEndpoint(usewithIntrospectioninstead). - 0.3.0: Strongly type
metaoption. Highlight proceduredescriptionvia.meta(). - 0.2.0: Add
includeoption to filter introspection to specific path prefixes. - 0.1.0: Initial release with core functionality and example server.
MIT