Commands

Learn about the Fern CLI commands.
View as Markdown
CommandDescription
fern initCreate new Fern project from OpenAPI spec or scratch
fern checkValidate API definition & configuration
fern upgradeUpdate Fern CLI & generators to latest versions
fern loginLogin to Fern CLI via GitHub or Google
fern logoutLog out of the Fern CLI
fern exportExport an OpenAPI spec for your API
fern api updateManually update your OpenAPI spec

Documentation commands

CommandDescription
fern docs devRun local documentation preview server
fern generate --docsBuild & publish documentation updates

SDK generation commands

CommandDescription
fern generateBuild & publish SDK updates
fern write-definitionConvert OpenAPI specifications to Fern Definition
fern write-overridesCreate OpenAPI customizations
fern generator upgradeUpdate SDK generators to latest versions

Detailed command documentation

Use fern init to initialize a new Fern workspace in the current folder. By default, you’ll see the IMDb API example.

When initializing with OpenAPI, your project structure will look like this:

fern
fern.config.json
generators.yml# generators you're using
openapi
openapi.json# your OpenAPI specification

For Fern Definition initialization (without OpenAPI), you’ll see this structure:

fern
fern.config.json
generators.yml# generators you're using
definition
api.yml# API-level configuration
imdb.yml# endpoints, types, and errors

openapi

Use --openapi to initialize a project from an OpenAPI specification:

docs

By adding --docs, you’ll also get a sample documentation website for your API with an API Reference section.

The file added will contain:

To publish the API docs, run fern generate --docs.

mintlify

By adding --mintlify PATH_TO_MINT_CONFIG, the CLI will automatically convert your Mintlify docs folder into a Fern docs site, based on the mint.json file.

The CLI will create a fern/ folder with the following structure:

fern
fern.config.json# root-level configuration
docs.yml# docs configuration
...# any other files / pages needed in your docs

readme

The fern init command supports importing Readme generated docs sites. This requires having a local chromium browser instance installed. You can ensure this is installed by installing the fern cli from source, following the instructions here.

By adding --readme URL_TO_README_DOCS_SITE, the CLI will automatically convert the Readme generated docs site into a Fern docs site.

The CLI will create a fern/ folder with the following structure:

fern
fern.config.json# root-level configuration
docs.yml# docs configuration
...# any other files / pages needed in your docs

For more information on getting started, check out our Quickstart Guide

Use fern export to generate an OpenAPI spec for your API.

This command is useful when you’ve defined your API in a format other than OpenAPI (such as the Fern Definition) and need to export it as an OpenAPI spec for integration with other tools or services.

api

Use --api to specify which API to export when you have multiple APIs defined in your fern/apis/ folder.

Use fern generate to run the Fern compiler and create SDKs for your API.

group

Use --group <group> to specify which generator group to run. You can use either a group name or an alias name. Aliases are defined in your generators.yml and map to multiple groups, allowing you to run several groups in parallel with a single command.

You can also set an alias as your default-group in generators.yml, so running fern generate without any arguments will run all groups in that alias.

The --group flag can be combined with other flags like --local for self-hosted SDK generation, --preview for local testing, or --version to specify the SDK version.

preview

Use --preview to test SDK changes locally before publishing. This is especially useful during development:

  • Generates SDK into a local .preview/ folder
  • Allows quick iteration on your Fern definition
  • No changes are published to package managers or GitHub

api

Use --api <api> to specify the API for SDK generation. This is useful when your project contains multiple API definitions. The API name should match the directory name in your fern/apis/ folder.

version

Use --version to specify the SDK version number, typically following semantic versioning (semver) format (MAJOR.MINOR.PATCH). This is particularly useful in CI/CD pipelines when publishing SDK releases.

fernignore

Use --fernignore to specify a custom .fernignore file path for SDK generation. This allows you to temporarily test different ignore configurations without modifying the committed .fernignore in your repository.

Fern will use the specified file instead of the one on the main branch and commit the new .fernignore to your repository as part of the generation process.

local

Use --local to run SDK generation on your own machine instead of using Fern’s cloud infrastructure. This is useful for organizations with strict security or compliance requirements. See self-hosted SDKs for setup instructions.

A Docker daemon must be running on your machine, as SDK generation runs inside a Docker container.

Use fern check to validate your API definition and Fern configuration: fern.config.json, generators.yml, and docs.yml.

When successfully executed, this command will not produce any output.

api

Use --api <api> to specify which API you’d like to check.

warnings

Use --warnings to log warnings in addition to errors.

Use --strict-broken-links to fail the command if any broken links are found in your API docs.

For comprehensive link checking, use the Fern Dashboard, which validates both internal and external links on your live published site. This is recommended over --strict-broken-links because the Dashboard checks your actual published site and can verify external links that the CLI cannot.

Usage in a GitHub Action

Use fern generate --docs to create a documentation site for your API.

instance

Use --instance to specify which instance URL in your docs.yml to generate documentation for.

preview

Use --preview to preview updates to your documentation before publishing changes to your production site.

Use fern docs dev to run a local development server to preview your docs.

port

Use --port <port-number> to specify the port the docs preview will be run on.

Use fern upgrade to upgrade your compiler version in fern.config.json to the latest version. It will also upgrade generators in generators.yml to their minimum-compatible versions.

Use fern login to login to the Fern CLI via GitHub or Google. Logging in allows you join GitHub organizations, gain permissions, and contribute to projects.

device-code

Use --device-code to login via device code authorization.

To enable CI/CD, use fern token.

Use fern logout to log out of the Fern CLI. This will clear your authentication credentials and revoke access to your GitHub organizations and permissions.

After logging out, you’ll need to run fern login again to access protected features.

Use fern token to generate a token for authenticating the Fern CLI in CI/CD environments. The token is specific to your organization defined in fern.config.json and doesn’t expire.

See Publishing your docs for instructions on using this token in automated publishing workflows.

Use fern write-definition to convert your OpenAPI Specification into a Fern Definition. You must have a fern/openapi/ folder that contains an OpenAPI Specification file in .json or .yaml format.

When run, this command creates a new folder within fern/ called .definition/.

fern
fern.config.json
generators.yml
openapi
openapi.json
.definition# your Fern Definition
api.yml
__package__.yml

If you do not see the .definition/ folder, use the appropriate command or configuration to view hidden folders (ls -a in bash and zsh).

If your fern/ folder contains both an openapi/ and a definition/ folder, Fern defaults to reading your OpenAPI Specification. To use your Fern Definition as input, you must:

  • Rename the .definition/ folder to definition/.
  • Remove or rename the openapi/ folder. For example, you can rename it to .openapi/.

api

Use --api to specify the API to write the definition for if you have multiple defined in your fern/apis/ folder.

Use fern write-overrides to generate a basic OpenAPI overrides file. An overrides file allows for reversible revisions to the API specification, including adding request and response examples for code snippets in Fern Docs.

When run, this command creates a new file within fern/openapi/ called openapi-overrides.yml.

fern
fern.config.json
generators.yml
openapi
openapi-overrides.yaml# your overrides file
openapi.json

api

Use --api to specify the API to run the command on if multiple are defined.

exclude-models

Use --exclude-models to stub the models while generating the initial overrides (in addition to the endpoints).

Use fern generator upgrade to update all generators in your generators.yml to their latest versions.

This is different from fern upgrade which updates the Fern CLI version. Use both commands to keep your entire Fern toolchain up to date.

This command will:

  • Check for updates to all generators specified in your generators.yml
  • Update the generator versions to their latest compatible releases
  • Maintain compatibility with your current Fern compiler version

Here’s what you might see when updates are available:

list

Use --list to see the full list of generator upgrades available.

generator

Use --generator to specify a particular generator type to upgrade.

group

Use --group to upgrade generators within a specific group in your generators.yml. If not specified, all generators of the specified type will be upgraded.

include-major

Use --include-major to include major version upgrades. Major versions are skipped by default to prevent breaking changes.

Pulls the latest OpenAPI spec from the specified origin in generators.yml and updates the local spec. Alternatively, you can automate this process by setting up a GitHub Action.

api

Use --api to specify the API to update if there are multiple specs with a defined origin in generators.yml. If you don’t specify an API, all OpenAPI specs with an origin will be updated.