Self-hosted generation

Beta
View as Markdown
Early access

The CLI generator is in early access. Reach out to get started.

By default, fern generate runs the CLI generator on Fern’s cloud infrastructure. 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)
InfrastructureFern-managedYour machine (Docker)
Network callsSpec + config sent to FernOrg verification + image pull only
Output optionsGitHub repo (release/push mode)Local file system or GitHub repo
Auth requiredFERN_TOKEN or interactive loginFERN_TOKEN
Docker requiredNoYes

Prerequisites

  • Fern CLI v5.37.9 or later (npm install -g fern-api)
  • Docker running on your machine
  • Rust toolchain (stable) for building the generated output
  • A FERN_TOKEN for organization verification (generate one with fern token or from the Dashboard)

Setup

This page assumes you’ve completed the Quickstart, so your generators.yml already writes to a local-file-system output path. Adding --local runs that same configuration through Docker instead of Fern’s cloud.

1

Set your Fern token

Self-hosted generation still requires a network call to verify your organization. Generate a token with fern token or from the Fern Dashboard, then export it:

$export FERN_TOKEN=<your-token>
2

Run local generation

$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.

3

Build and run

$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 object:

generators.yml
1groups:
2 cli:
3 generators:
4 - image:
5 name: fern-cli-generator
6 registry: ghcr.io/your-org
7 version: 0.23.4
8 output:
9 location: local-file-system
10 path: ../my-cli
11 config:
12 binaryName: my-cli

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

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