Skip to main content

Generate Your First Client

The fastest way to use OpenAPI TypeScript is with npx. No installation required.
1

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):
2

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.
3

Configure the Client

Set up your HTTP client with your API’s base URL:
You can also configure headers, interceptors, and other options:
4

Use the Generated SDK

Import and use the generated SDK functions:
Congratulations on creating your first client! 🎉

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:

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