The Problem
Every REST API endpoint you want an agent to use requires a tool. A tool needs three things: a Zod schema describing the parameters, a description the LLM can read, and an execute function that makes the HTTP request. For a single endpoint that is fine. For an API with forty endpoints, it is tedious and error-prone. OpenAPI specs already contain all the information you need. The parameter types are there. The descriptions are there. The URL patterns and HTTP methods are there. The only question is how to convert that information into tools.The Solution
createOpenApiTools reads an OpenAPI 3.0+ spec and returns a Record<string, Tool> — one tool per operation. Each tool has a Zod schema derived from the operation’s parameters and request body, a description from the operation’s summary, and an execute function that builds the correct HTTP request and returns the response.
tools is now a map of operation IDs to AI SDK tools. Hand them to an agent:
{ limit: z.number().optional() }. It decides which endpoints to call, fills in the parameters, and gets back JSON responses. No glue code required.
How It Works
The conversion follows four steps:-
Parse the spec. Smithers loads the OpenAPI document (JSON object, URL, or file path), resolves
$refpointers, and extracts every operation. -
Convert schemas. Each operation’s path parameters, query parameters, header parameters, and request body are converted from JSON Schema into Zod schemas. Strings become
z.string(), integers becomez.number().int(), objects becomez.object()with the correct shape. When a schema is too complex for clean conversion, Smithers falls back toz.any()with a description so the LLM still knows what to provide. -
Build the tool. Each operation becomes an AI SDK
tool()with the converted schema asinputSchema, the operation summary asdescription, and an execute function that assembles the HTTP request. -
Execute at runtime. When an agent calls the tool, the execute function substitutes path parameters into the URL, appends query parameters, sets headers (including authentication), sends the request via
fetch, and returns the response body.
Authentication
Three authentication methods are supported:Filtering Operations
Most APIs have endpoints you do not want an agent calling. Useinclude or exclude to control which operations become tools:
Single Operation
If you only need one tool from a spec, usecreateOpenApiTool:
Observability
Every OpenAPI tool call emits anOpenApiToolCalled event and updates two metrics:
smithers.openapi.tool_calls— counter of total callssmithers.openapi.tool_duration_ms— histogram of call durations
When to Use OpenAPI Tools
Use them when you have an existing REST API with an OpenAPI spec and you want agents to interact with it. They are particularly good for:- Internal APIs with dozens of endpoints
- Third-party APIs that publish OpenAPI specs
- Rapid prototyping where hand-writing tools is too slow