Skip to navigation

Self-hosted generation

View as Markdown

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 pulling the Docker image (if not cached) and, when a Fern token is available, organization verification. 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 FernImage pull, plus org verification when a token is set
Output optionsGitHub repo (release/push mode)Local file system or GitHub repo
Auth requiredFERN_TOKEN or interactive loginNone for local file system output; FERN_TOKEN or fern login for GitHub output
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 if you output to a GitHub repository (optional for local file system output; 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 (optional)

Local file system output doesn’t require a token. When a token is set, the CLI verifies your organization and applies its settings, such as white-labeling, to the generated output. 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
groups:
cli:
generators:
- image:
name: fern-cli-generator
registry: ghcr.io/your-org
version: 0.61.1
output:
location: local-file-system
path: ../my-cli
config:
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