@hey-api/sdk plugin generates type-safe functions for each API operation in your OpenAPI specification. It works seamlessly with the TypeScript plugin to provide full type safety.
Installation
The SDK plugin is included when you install@hey-api/openapi-ts:
Configuration
Add the plugin to youropenapi-ts.config.ts:
What It Generates
The SDK plugin generates asdk.gen.ts file containing type-safe functions for each API operation:
Configuration Options
operations
Define the structure of generated SDK operations.
string | object
default:"'flat'"
'flat'- Standalone functions, no container (tree-shakeable)'byTags'- One class per operation tag'single'- All operations in a single class/container- Custom function for full control
- Flat (default)
- Single Container
Advanced Operations Configuration
'class'
default:"'class'"
Type of container for grouped operations (currently only supports
'class').string | function | object
default:"'Sdk'"
Customize container names. For
'single' strategy, sets the root container name. For 'byTags', transforms tag names.'instance' | 'static'
default:"'instance'"
'instance'- Instance methods, requires instantiation:new ClassName()'static'- Static methods, no instantiation required:ClassName.method()
'operationId' | 'id' | function
default:"'operationId'"
'operationId'- Split operationId by delimiters (e.g.,users.list→Users.list())'id'- Use operation id as-is, no nesting- Custom function for full control
RegExp
default:"/[.]/"
Delimiters for splitting operationId (only when
nesting: 'operationId').paramsStructure
Define how request parameters are structured in generated SDK methods.
'grouped' | 'flat'
default:"'grouped'"
'grouped'- Separates parameters by transport layer (body, query, path, header)'flat'- Merges all parameters into a single object
- Grouped (default)
- Flat
responseStyle
Note: This feature works only with the Fetch client.
Define the shape of the return value from SDK calls.
'fields' | 'data'
default:"'fields'"
'fields'- Returns multiple fields (data, error, response, etc.)'data'- Returns only the data field
- Fields (default)
- Data Only
client
Use an internal client instance to send HTTP requests.
string | boolean
default:"true"
true- Automatically choose the client from your defined plugins (defaults to@hey-api/client-fetch)- Client plugin name (e.g.,
'@hey-api/client-axios') false- Don’t use an internal client
auth
Include authentication mechanisms in generated functions.
boolean
default:"true"
Disable if you’re handling auth yourself or defining it globally on the client.
transformer
Transform response data before returning (e.g., convert ISO strings to Date objects).
string | boolean
default:"false"
true- Automatically choose transformer from your defined plugins- Transformer plugin name (e.g.,
'@hey-api/transformers') false- No transformation
validator
Validate request and/or response data against schema.
string | boolean | object
default:"false"
true- Automatically choose validator from your defined plugins- Validator plugin name (e.g.,
'@hey-api/zod') - Object with separate
requestandresponsevalidation settings false- No validation
- Boolean
- String
- Object
examples
Generate code examples for SDK operations and attach them to the input source.
boolean | object
default:"false"
Set to
false to disable example generation entirely, or provide an object for fine-grained control.Common Patterns
Basic API Client
Class-Based SDK with Static Methods
Service-Based Architecture
Flat Structure with Validation
With Transformers
Migration from Legacy Options
Next Steps
HTTP Clients
Choose an HTTP client for making requests.
Transformers
Transform response data at runtime.
Validators
Validate request and response data.
State Management
Integrate with TanStack Query or Pinia Colada.