> ## Documentation Index
> Fetch the complete documentation index at: https://docs.priceos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generating Types

> Make your life easier by autogenerating types for your features.

<Steps>
  <Step title="Install SDK and add API key">
    <CodeGroup>
      ```bash npm theme={null}
      npm i priceos
      ```

      ```bash pnpm theme={null}
      pnpm add priceos
      ```

      ```bash yarn theme={null}
      yarn add priceos
      ```

      ```bash bun theme={null}
      bun add priceos
      ```
    </CodeGroup>

    [Create an API key](https://app.priceos.com/settings/api-keys) and add to your .env file.

    ```bash title=".env" theme={null}
    PRICEOS_API_KEY=pos_ab234cdef...
    ```
  </Step>

  <Step title="Generate types">
    <CodeGroup>
      ```bash npm theme={null}
      npx priceos generate-types
      ```

      ```bash pnpm theme={null}
      pnpm dlx priceos generate-types
      ```

      ```bash yarn theme={null}
      yarn dlx priceos generate-types
      ```

      ```bash bun theme={null}
      bunx priceos generate-types
      ```
    </CodeGroup>

    This command creates a local `priceos.types` file with the `MyFeatures` type that you can import and use in your hooks or [SDK](https://www.npmjs.com/package/priceos).

    Run with `--help` to see more options.
  </Step>

  <Step title="Use generated types">
    <CodeGroup>
      ```tsx React theme={null}
      import { useFeatureAccess } from "priceos/react";
      import type { MyFeatures } from "./priceos.types";

      const { hasAccess } = useFeatureAccess<MyFeatures>("priority_support");
      ```

      ```ts Node.js theme={null}
      import { PriceOS } from "priceos";
      import type { MyFeatures } from "./priceos.types";

      export const priceos = new PriceOS<MyFeatures>(process.env.PRICEOS_API_KEY!);
      ```
    </CodeGroup>

    <Note>
      Regenerate types whenever you add, remove, or rename a feature.
    </Note>
  </Step>
</Steps>

## CLI options

<ParamField path="--api-key <key>" type="string">
  PriceOS API key. If omitted, the CLI checks `PRICEOS_API_KEY` in `.env.local`, then `.env`, then process env.
</ParamField>

<ParamField path="--out <path>" type="string">
  Write the generated types file to a specific file path.
</ParamField>

<ParamField path="--out-dir <path>" type="string">
  Write the generated file into a specific directory (ignored when `--out` is provided).
</ParamField>

<ParamField path="-h, --help" type="flag">
  Show the CLI help output with all available options.
</ParamField>

```bash theme={null}
# Explicit API key and output file
npx priceos generate-types --api-key pos_ab234cdef... --out ./src/priceos.types.d.ts

# Output to a directory
npx priceos generate-types --out-dir ./src/types
```
