When to use this
Use OpenAPI client generation when:- Your API has an OpenAPI 2.0 (Swagger) or OpenAPI 3.x specification
- The API has many endpoints and you want type-safe access to all of them
- You want the AI to understand the full API surface so it can generate accurate code
- You have an internal service with a published spec
| Approach | Best for |
|---|---|
| OpenAPI client | Complex APIs with many endpoints, typed requests/responses, internal services with specs |
| Custom API | Simple key-based access, APIs with a few endpoints, services without an OpenAPI spec |
How it works
Provide the OpenAPI spec
Tell the AI where to find your API’s OpenAPI specification. You can either:
- Share a URL: Give the AI the URL to your spec (e.g.,
https://api.example.com/openapi.json) - Paste the spec: Copy and paste the YAML or JSON spec directly into the chat
Generate a typed API client from this OpenAPI spec: https://api.example.com/openapi.json
AI generates the client
The AI reads the specification and generates a TypeScript client that includes:
- Type definitions for all request and response schemas
- Client functions for every endpoint in the spec
- Authentication handling using your configured credentials
- Error types for documented error responses
What gets generated
The AI generates a client tailored to your API’s specification. A typical generated client includes:Type-safe request and response types
Every endpoint’s request body, query parameters, path parameters, and response type are defined as TypeScript interfaces. This means your editor provides auto-complete and the compiler catches type mismatches.Endpoint functions
Each API endpoint becomes a typed function. For example, an API with aGET /users/{id} endpoint would get a function like:
Authentication handling
The client includes authentication based on the spec’s security definitions. If your API uses Bearer tokens, API keys, or OAuth, the generated client handles the headers automatically using your configured credentials.Example workflow
Here is a typical workflow for using OpenAPI client generation:- You: “I have an internal inventory API at https://inventory.internal.io. Here is the OpenAPI spec: [paste or URL]”
- AI: Reads the spec, identifies the endpoints, and generates a typed client.
- You: “Build a page that shows all products with low stock and lets me reorder them.”
-
AI: Uses the generated client to call the
GET /products?stock_level=lowendpoint and thePOST /ordersendpoint, with full type safety.
Updating the client
If your API spec changes — new endpoints, updated schemas, or modified parameters — you can ask the AI to regenerate the client:The inventory API spec has been updated. Regenerate the TypeScript client from https://inventory.internal.io/openapi.jsonThe AI will update the generated types and functions to match the new spec. Any app code that uses removed or changed endpoints will surface as TypeScript errors, making it easy to identify what needs to be updated.
Combining with Custom APIs
You can use OpenAPI client generation together with Custom APIs. A common pattern is:- Create a Custom API to securely store your API credentials (API key, Bearer token, etc.)
- Generate an OpenAPI client for type-safe endpoint access
- The generated client uses the Custom API’s environment variable for authentication
Supported specifications
The AI can generate clients from:| Format | Versions |
|---|---|
| OpenAPI | 3.0.x, 3.1.x |
| Swagger | 2.0 |
Limitations
- Server-side only — Generated clients are used in API routes and server components. They cannot be called from client-side code.
- REST APIs — OpenAPI client generation works with REST APIs. For GraphQL APIs, the AI can generate queries directly without a client generator.
- Spec quality matters — The accuracy of the generated client depends on the quality of the OpenAPI spec. Specs with incomplete type definitions or missing endpoint documentation will produce less useful clients.