Generate Your First Client
The fastest way to use OpenAPI TypeScript is withnpx. No installation required.
Run the Generator
Use npx to generate your client directly from your OpenAPI specification:You can also use a URL:Or use the Hey API Registry (sign up at app.heyapi.dev):
Review Generated Files
The generator creates several files in your output directory:
Treat the output folder as a dependency. Don’t manually edit generated files as your changes will be overwritten on the next run.
Configure the Client
Set up your HTTP client with your API’s base URL:You can also configure headers, interceptors, and other options:
Example: Using with React
Here’s a complete example of using OpenAPI TypeScript in a React application:For React applications, consider using the
@tanstack/react-query plugin for automatic data fetching, caching, and state management. See the TanStack Query plugin documentation.Working with Different Input Formats
OpenAPI TypeScript supports multiple input formats:- Local File
- Remote URL
- Hey API Registry
CLI Options
The CLI supports several options for quick configuration:Example with Options
Next Steps
Now that you’ve generated your first client, explore these topics:Installation
Install as a dev dependency for use in scripts
Configuration
Learn about configuration files and advanced options
Plugins
Discover plugins for schemas, hooks, and frameworks
HTTP Clients
Choose the right HTTP client for your project