> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI2ODkwNGQwZS03OTdiLTRiZjItOTIzMi02OGYxZmFiOTBiMDIiLCJleHAiOjE3ODQzNTkxOTIsImlhdCI6MTc4NDM1ODg5Mn0.AgPFWZCrVF5DUwyDRIW1O8BbEbv3-Ea1adbFKmSjsLk
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# Self-hosted generation

> Run CLI generation on your own machine using Docker instead of Fern's cloud infrastructure.

The CLI generator is in early access. [Reach out](https://buildwithfern.com/book-demo?type=cli) to get started.

By default, `fern generate` [runs the CLI generator on Fern's cloud infrastructure](/learn/cli-generator/get-started/quickstart). Pass `--local` to run generation on your own machine instead. No API definition data leaves your machine: the only network calls are organization verification and pulling the Docker image (if not cached). This suits organizations with strict security or compliance requirements that need to keep their spec off Fern's infrastructure.

## Comparison with cloud generation

|                 | Cloud (default)                   | Local (`--local`)                  |
| --------------- | --------------------------------- | ---------------------------------- |
| Infrastructure  | Fern-managed                      | Your machine (Docker)              |
| Network calls   | Spec + config sent to Fern        | Org verification + image pull only |
| Output options  | GitHub repo (release/push mode)   | Local file system or GitHub repo   |
| Auth required   | `FERN_TOKEN` or interactive login | `FERN_TOKEN`                       |
| Docker required | No                                | Yes                                |

## Prerequisites

* [Fern CLI](https://www.npmjs.com/package/fern-api) v5.37.9 or later (`npm install -g fern-api`)
* [Docker](https://docs.docker.com/get-docker/) running on your machine
* [Rust toolchain](https://rustup.rs/) (stable) for building the generated output
* A `FERN_TOKEN` for organization verification (generate one with `fern token` or from the [Dashboard](/learn/dashboard/configuration/api-keys))

## Setup

This page assumes you've completed the [Quickstart](/learn/cli-generator/get-started/quickstart), so your `generators.yml` already writes to a [`local-file-system`](/learn/cli-generator/get-started/configuration#output) output path. Adding `--local` runs that same configuration through Docker instead of Fern's cloud.

Self-hosted generation still requires a network call to verify your organization. Generate a token with `fern token` or from the [Fern Dashboard](/learn/dashboard/configuration/api-keys), then export it:

```bash
export FERN_TOKEN=<your-token>
```

```bash
fern generate --group cli --local
```

The CLI pulls the generator's Docker image (cached after the first run), processes your OpenAPI spec, and writes a complete Rust project to the configured output path. Images pull from Docker Hub by default; you can alternatively pull from a [private registry](#custom-container-registry).

```bash
cd ../my-cli
cargo build
./target/debug/my-cli --help
```

## Custom container registry

By default, `--local` pulls generator images from Docker Hub. To pull from a private registry, replace the `name` field with an [`image`](/learn/sdks/reference/generators-yml#image) object:

```yaml title="generators.yml" {4-6}
groups:
  cli:
    generators:
      - image:
          name: fern-cli-generator
          registry: ghcr.io/your-org
        version: 0.23.4
        output:
          location: local-file-system
          path: ../my-cli
        config:
          binaryName: my-cli
```

If your registry requires authentication, log in before running generation:

```bash
echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
fern generate --group cli --local
```