Get Started
此内容尚不支持你的语言。
@hey-api/openapi-ts generates TypeScript code from OpenAPI specifications. Point it at your spec, pick your plugins, and get production-grade code in seconds.
Used by companies like Vercel, OpenCode, and PayPal.
“OpenAPI codegen that just works.”
— Guillermo Rauch, CEO of Vercel
Features
Section titled “Features”- production-grade code that compiles
- runs in any Node.js 22+ environment
- accepts any OpenAPI specification
- core plugins for SDKs, types, and schemas
- HTTP clients for Fetch API, Angular, Axios, Next.js, Nuxt, and more
- 20+ plugins to reduce third-party boilerplate
- highly customizable via plugins
- sync with Hey API Registry for spec management
Quick Start
Section titled “Quick Start”The fastest way to use @hey-api/openapi-ts is via npx
npx @hey-api/openapi-ts -i hey-api/backend -o src/clientCongratulations on creating your first client! 🎉 You can learn more about the generated files on the Output page.
Installation
Section titled “Installation”You can download @hey-api/openapi-ts from npm using your favorite package manager.
npm install @hey-api/openapi-ts -D -Epnpm add @hey-api/openapi-ts -D -Eyarn add @hey-api/openapi-ts -D -Ebun add @hey-api/openapi-ts -DVersioning
Section titled “Versioning”This package is in initial development. Please pin an exact version so you can safely upgrade when you’re ready.
We publish migration notes for every breaking release. You might not be impacted by a breaking change if you don’t use the affected features.
Most people run @hey-api/openapi-ts via CLI. To do that, add a script to your package.json file which will make openapi-ts executable through script.
"scripts": { "openapi-ts": "openapi-ts"}The above script can be executed by running npm run openapi-ts or equivalent command in other package managers. Next, we will create a configuration file and move our options from Quick Start to it.
Node.js
Section titled “Node.js”You can also generate output programmatically by calling createClient() in a JavaScript/TypeScript file.
import { createClient } from '@hey-api/openapi-ts';
createClient({ input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client',});If you’re using Vite 5, 6, 7, or 8, you can integrate @hey-api/openapi-ts directly into your build pipeline with @hey-api/vite-plugin. Install it alongside the main package:
npm install @hey-api/vite-plugin -D -Epnpm add @hey-api/vite-plugin -D -Eyarn add @hey-api/vite-plugin -D -Ebun add @hey-api/vite-plugin -DThen add the plugin to your Vite configuration:
import { heyApiPlugin } from '@hey-api/vite-plugin';import { defineConfig } from 'vite';
export default defineConfig({ plugins: [ heyApiPlugin({ config: { input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }, }), ],});See the Vite page for full configuration options.
Configuration
Section titled “Configuration”It’s a good practice to extract your configuration into a separate file. Learn how to do that and discover available options on the Configuration page.
Examples
You can view live examples on StackBlitz or on GitHub.