---
title: "oRPC v2 Plugin"
description: "Generate oRPC v2 contracts from OpenAPI with the oRPC plugin for openapi-ts. Fully compatible with validators, transformers, and all core features."
url: "https://heyapi.dev/docs/openapi/typescript/plugins/orpc/v2"
---

Beta[Leave feedback](https://github.com/hey-api/hey-api/issues)·[Contribute](https://heyapi.dev/docs/openapi/typescript/community/contributing)

### About

[Section titled “About”](#about)

[oRPC](https://orpc.dev) combines RPC with OpenAPI, allowing you to define and call remote or local procedures through a type-safe API while adhering to the OpenAPI specification.

The oRPC plugin for Hey API generates contracts from your OpenAPI spec, fully compatible with all core features.

### Collaborators

[Section titled “Collaborators”](#collaborators)

* [![Stephen Zhou](https://heyapi.dev/_astro/hyoban_Z2svglB.webp)Stephen Zhou](https://github.com/hyoban)

## Features

[Section titled “Features”](#features)

* oRPC v2 support
* seamless integration with `@hey-api/openapi-ts` ecosystem
* generated contracts
* minimal learning curve thanks to extending the underlying technology

## Installation

[Section titled “Installation”](#installation)

In your [configuration](https://heyapi.dev/docs/openapi/typescript/get-started), add `orpc` to your plugins and you’ll be ready to generate oRPC artifacts. 🎉

openapi-ts.config.ts

```js
export default {
  input: 'hey-api/backend', // sign up at app.heyapi.dev
  output: 'src/client',
  plugins: [
    // ...other plugins
    {
      name: 'orpc',
      compatibilityVersion: '2',
    },
  ],
};
```

## Output

[Section titled “Output”](#output)

The oRPC plugin will generate the following artifacts, depending on the input specification.

## Contracts

[Section titled “Contracts”](#contracts)

Contracts are generated from all endpoints.

* example

  orpc.gen.ts

  ```ts
  import { oc } from '@orpc/contract';
  import { openapi } from '@orpc/openapi';


  const addPet = oc.meta(
    openapi({
      description: 'Add a new pet to the store.',
      inputStructure: 'detailed',
      method: 'POST',
      operationId: 'addPet',
      path: '/pet',
      summary: 'Add a new pet to the store.',
      tags: ['pet'],
    }),
  );
  ```

* config

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        name: 'orpc',
        compatibilityVersion: '2',
      },
    ],
  };
  ```

### Query Styles

[Section titled “Query Styles”](#query-styles)

When generating oRPC v2 contracts, `queryStyles` metadata is inferred by default for OpenAPI serialization styles supported by oRPC, so arrays and delimited objects keep their original serialization behavior.

orpc.gen.ts

```ts
const getItems = oc.meta(
  openapi({
    inputStructure: 'detailed',
    method: 'GET',
    operationId: 'getItems',
    path: '/items',
    queryStyles: {
      ids: 'array',
      filters: 'comma-delimited-object',
      tags: 'comma-delimited-array',
    },
    tags: ['items'],
  }),
);
```

You can disable this metadata when you want oRPC’s default bracket notation.

oRPC does not currently expose a `queryStyles` value for form-exploded objects, so those parameters use oRPC’s default bracket notation.

openapi-ts.config.ts

```js
export default {
  input: 'hey-api/backend', // sign up at app.heyapi.dev
  output: 'src/client',
  plugins: [
    // ...other plugins
    {
      compatibilityVersion: '2',
      inferQueryStyles: false,
      name: 'orpc',
    },
  ],
};
```

### Validators

[Section titled “Validators”](#validators)

To enable schema validation, set `validator` to `zod` or one of the available [validator plugins](https://heyapi.dev/docs/openapi/typescript/validators). This will automatically add the selected plugin with its default configuration.

For a more granular approach, manually add a validator plugin and set `validator` to the plugin name or `true` to automatically select a compatible plugin. Until you customize the validator plugin, both approaches will produce the same default output.

* example

  orpc.gen.ts

  ```ts
  import { oc } from '@orpc/contract';
  import { openapi } from '@orpc/openapi';


  import { vAddPetBody, vAddPetResponse } from './valibot.gen';


  const addPet = oc
    .meta(
      openapi({
        description: 'Add a new pet to the store.',
        inputStructure: 'detailed',
        method: 'POST',
        operationId: 'addPet',
        path: '/pet',
        summary: 'Add a new pet to the store.',
        tags: ['pet'],
      }),
    )
    .input(v.object({ body: vAddPetBody }))
    .output(vAddPetResponse);
  ```

* config

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        compatibilityVersion: '2',
        name: 'orpc',
        validator: true, // or 'valibot'
      },
      {
        name: 'valibot', // customize (optional)
        // other options
      },
    ],
  };
  ```

You can choose to validate only inputs or outputs.

* inputs

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        name: 'orpc',
        validator: {
          input: 'zod',
        },
      },
    ],
  };
  ```

* outputs

  openapi-ts.config.ts

  ```js
  export default {
    input: 'hey-api/backend', // sign up at app.heyapi.dev
    output: 'src/client',
    plugins: [
      // ...other plugins
      {
        name: 'orpc',
        validator: {
          output: 'zod',
        },
      },
    ],
  };
  ```

Learn more about available validators on the [Validators](https://heyapi.dev/docs/openapi/typescript/validators) page.

## API

You can view the complete list of options in the [UserConfig](https://github.com/hey-api/hey-api/blob/main/packages/openapi-ts/src/plugins/orpc/types.ts) interface.

## Examples

You can view live examples on [StackBlitz](https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples) or on [GitHub](https://github.com/hey-api/hey-api/tree/main/examples).
