Skip to main content
createOpenApiTools parses an OpenAPI 3.x spec and returns AI SDK tools, one per operation, with Zod schemas converted from the spec’s JSON schemas.
API reference: OpenAPI lists every OpenAPI export and option, and links to source and tests.

Options

Pass the spec itself as the first argument to createOpenApiTools(input, options); input may be a parsed spec object, file path, URL, or raw OpenAPI text.

Public API

CLI

Generate a reusable AI SDK tools module:
The generated module imports createOpenApiToolsSync, creates the tools from the spec, and exports them as both tools and the default export.
openapi list previews every operationId, method, path, and summary: useful for auditing what an agent can call before wiring it up.

What gets generated

For each operation:
  • A Zod schema for the request body + path/query/header parameters.
  • An execute(args) function that performs the HTTP call.
  • The operation’s summary / description becomes the tool description.

Response handling

  • JSON responses are parsed and returned as objects.
  • Non-JSON responses are returned as strings.
  • HTTP status codes are not special-cased by the tool factory: a JSON or text error body from the server is returned straight to the agent.
  • Request failures, fetch failures, and schema/tool execution exceptions are returned as { error: true, message, status: "failed" } so the agent can react in its loop.

Filtering

include / exclude accept arrays of operationId; if both are set, exclude wins. Useful for limiting an agent’s surface area to a specific feature (“just the inventory endpoints”). namePrefix prefixes generated tool names without changing the operationIds used for filtering. Use operations for per-operation curation keyed by the original operationId: set an entry to false or { include: false } to skip that endpoint, name to rename the generated tool, description to replace the spec summary/description with agent-facing instructions, and responseExamples to append concrete response shapes to the tool description. This lets a connector expose a small curated set instead of dumping every endpoint as an agent-callable tool. include / exclude still use the original operationId, not the curated name.

Observability

OpenAPI tool calls update the exported Effect metrics (openApiToolCallsTotal, openApiToolCallErrorsTotal, openApiToolDuration) and carry Effect log annotations/spans with the operation id, method, and path. The current tool factory does not emit OpenApiToolCalled onto the Smithers run event bus; that event variant is typed/categorized for future event-bus integration.

Notes / Limitations

  • Schema composition (allOf, anyOf, oneOf) is supported; converts to Zod unions/intersections.
  • Nullable fields and defaults from the spec are preserved.
  • Cookie parameters are ignored when generating tool input schemas and requests.
  • JSON is the only request body media type generated today; non-JSON bodies (form data, multipart uploads, binary payloads) are not encoded.
  • Parameter serialization styles are not implemented: path parameters are URL-encoded and substituted directly; query parameters use default URLSearchParams serialization.
  • Swagger 2.0 objects aren’t supported as a first-class input format; use OpenAPI 3.x specs with openapi, paths, and info fields.