For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Book a demoLog inStart for free
  • Overview
    • Introduction
    • How it works
    • Quickstart
    • Customer showcase
  • Working with SDKs
    • Project structure
    • Adding custom code
    • Migrating to Replay
    • Capabilities
  • Generators
      • Generating an SDK
      • Publishing to npm
      • Configuration
      • Adding custom code
      • Dynamic authentication
      • Enabling the serde layer
      • Changelog
      • Customer showcase
  • Reference
    • generators.yml
Checking status...
SOC2Soc 2 Type II
© 2026 Fern • Birch Solutions, Inc., a Postman company

Documentation

SDKsDocsAsk FernCLI Reference

API Definitions

OpenAPIAsyncAPIOpenRPCgRPC

Resources

BlogSupportPricing

Company

Brand KitPrivacy PolicyTerms of Service
LogoLogo
Book a demoLog inStart for free
On this page
  • Configure SDK package settings
  • Configure GitHub publishing
  • Configure authentication
  • Publish your SDK
  • Migrating from token-based to OIDC publishing
  • Why migrate to OIDC
  • Prerequisites
  • Choose your migration path
  • Verify your migration
  • Migration troubleshooting
GeneratorsTypeScript

Publishing to npm

||View as Markdown|
Was this page helpful?
Edit this page
Previous

Generating an SDK

Next

TypeScript configuration

Publish your public-facing Fern TypeScript SDK to the npmjs registry. After following the steps on this page, you’ll have a versioned package published on npm.

Already publishing to npm?

If you’re using token-based authentication, npm has deprecated long-lived classic tokens. See Migrating from token-based to OpenID Connect (OIDC) publishing to upgrade to the more secure OIDC authentication.

Versioned package published on npmjs.com

This page assumes that you have:

  • An initialized fern folder, a GitHub repository for your TypeScript SDK, and a TypeScript generator group in generators.yml. See Generating an SDK (TypeScript).

Configure SDK package settings

You’ll need to update your generators.yml file to configure the package name, output location, and client naming for npm publishing. Your generators.yml should live in your source repository (or on your local machine), not the repository that contains your TypeScript SDK code.

1

Configure output location

In the group for your TypeScript SDK, change the output location from local-file-system (the default) to npm to indicate that Fern should publish your package directly to the npmjs registry:

generators.yml
1groups:
2 ts-sdk: # Group name for your TypeScript SDK
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 3.69.0
6 output:
7 location: npm
2

Add a unique package name

Your package name must be unique in the npmjs registry, otherwise publishing your SDK will fail.

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 3.69.0
6 output:
7 location: npm
8 package-name: your-package-name
3

Configure namespaceExport

The namespaceExport option controls the name of the generated client. This is the name customers use to import your SDK (import { your-client-name } from 'your-package-name';).

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 3.69.0
6 output:
7 location: npm
8 package-name: your-package-name
9 config:
10 namespaceExport: YourClientName # must be PascalCase

Configure GitHub publishing

Fern can automatically publish your SDK to npmjs via GitHub Actions. Configure your GitHub repository and publishing mode:

Optionally set the mode to control how Fern handles SDK publishing:

  • mode: release (default): Fern generates code, commits to the default branch (or the branch you specify), and tags a release automatically
  • mode: pull-request (recommended): Fern generates code and creates a PR for you to review before release
  • mode: push: Fern generates code and pushes to a branch you specify for you to review before release

You can also configure other settings, like the reviewers or license. Refer to the full github (generators.yml) reference for more information.

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 3.69.0
6 output:
7 location: npm
8 package-name: your-package-name
9 config:
10 namespaceExport: YourClientName
11 github:
12 repository: your-org/your-repository
13 mode: push # or "pull-request"
14 branch: your-branch-name # Required for mode: push

Configure authentication

Choose how you want to authenticate with npmjs when publishing.

npm has deprecated long-lived classic tokens for publishing from CI/CD workflows. OpenID Connect (OIDC) authentication is strongly recommended for security.

OIDC authentication (Recommended)

OIDC-based publishing (also known as “trusted publishing”) is the most secure way to publish. With OIDC, you don’t need to manage authentication tokens - npmjs trusts your GitHub repository to publish directly.

Prerequisites
  • Fern TypeScript SDK generator version 3.12.3 or later
  • Fern CLI version 0.94.0 or later (only required for local generation with --local)
1

Add OIDC to generators.yml

Add token: OIDC to the output section:

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 3.69.0 # Must be 3.12.3 or later
6 output:
7 location: npm
8 package-name: your-package-name
9 token: OIDC
10 config:
11 namespaceExport: YourClientName
12 github:
13 repository: your-org/your-repository
14 mode: push
15 branch: your-branch-name
2

Generate your SDK

Generate your SDK to create the GitHub Actions workflow with OIDC configuration:

$fern generate --group ts-sdk

This creates a .github/workflows/ci.yml file that’s configured to use OIDC for npmjs publishing. Alternatively, you can push your generators.yml changes and let the Fern GitHub Action generate the workflow for you.

This creates a .github/workflows/ci.yml file that’s configured to use OIDC for npm publishing.

3

Authorize your repository on npmjs.com

Configure trusted publishing on npmjs.com to allow your GitHub repository to publish:

  1. Navigate to your package settings on npmjs.com
  2. Find the Trusted Publisher section and click Add trusted publisher
  3. Select GitHub Actions as your provider
  4. Fill in:
    • Organization or user: Your GitHub username or organization
    • Repository: Your TypeScript SDK repository name (e.g., your-org/your-repository)
    • Workflow filename: ci.yml
    • Environment name: Leave blank

For more details, see npm’s trusted publishing documentation.

Troubleshooting

“Unable to authenticate” error

Common causes:

  • Workflow filename doesn’t match exactly (must be ci.yml)
  • Trusted publisher configuration on npmjs.com doesn’t match your repository settings
  • Using self-hosted runners (not supported by npmjs.org)

Solution: Double-check your trusted publisher configuration on npmjs.com matches your repository name and workflow filename exactly.

Private repository limitations

Provenance attestations aren’t generated for packages published from private repositories, even when using trusted publishing. This is a known limitation.

Token-based authentication (Legacy)

npm has deprecated long-lived classic tokens. Long-lived authentication tokens can be exposed in logs, compromised, and are difficult to manage and rotate. OIDC-based authentication is strongly recommended instead.

1

Generate an npm token

  1. Log into npmjs.com
  2. Click on your profile picture and select Edit Profile
  3. Select Access Tokens
  4. Click Generate New Token and choose either Classic Token (select “Automation” type) or Granular Access Token
  5. Save your token securely - it won’t be displayed again
For more information on access tokens, see npm’s About access tokens documentation.
2

Add token to generators.yml

Add token: ${NPM_TOKEN} to the output section:

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 3.69.0
6 output:
7 location: npm
8 package-name: your-package-name
9 token: ${NPM_TOKEN}
10 config:
11 namespaceExport: YourClientName
12 github:
13 repository: your-org/your-repository
14 mode: push
15 branch: your-branch-name
3

Add NPM_TOKEN as a GitHub Actions secret

  1. Open your repository on GitHub and go to Settings
  2. Navigate to Secrets and variables > Actions
  3. Click New repository secret
  4. Name it NPM_TOKEN and paste your npm token
  5. Click Add secret

Publish your SDK

Your SDK will automatically be published to npmjs when you create a GitHub release with a version tag:

  1. Create a GitHub release with a version tag (for example, v1.0.0)
  2. The CI workflow will run automatically and publish to npm
  3. View your package on npmjs.com to confirm the version
Alternative: Manual workflow dispatch

If you prefer to trigger publishes manually, create a .github/workflows/publish.yml file:

.github/workflows/publish.yml
1name: Publish TypeScript SDK
2
3on:
4 workflow_dispatch:
5 inputs:
6 version:
7 description: "Version to publish (e.g., 1.0.0)"
8 required: true
9 type: string
10
11jobs:
12 publish:
13 runs-on: ubuntu-latest
14 steps:
15 - name: Checkout repo
16 uses: actions/checkout@v4
17
18 - name: Install Fern
19 run: npm install -g fern-api
20
21 - name: Generate and publish SDK
22 env:
23 FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
24 run: fern generate --group ts-sdk --version ${{ inputs.version }} --log-level debug

Add your FERN_TOKEN as a repository secret (run fern token to generate one), then trigger the workflow from the Actions tab.


Migrating from token-based to OIDC publishing

If you’re using token-based authentication and need to migrate to OIDC, follow these steps:

Why migrate to OIDC

npmjs is implementing trusted publishing to remove security risks associated with long-lived tokens, which can be:

  • Exposed in logs or configuration files
  • Compromised and used persistently until manually revoked
  • Difficult to manage and rotate

OIDC-based publishing uses short-lived, cryptographically signed tokens that are specific to your workflow and can’t be extracted or reused.

Prerequisites

Before migrating, ensure you have:

  • A package published to npmjs.org
  • A GitHub repository with GitHub Actions configured
  • Access to your package settings on npmjs.com
  • Fern CLI version 0.94.0 or later (for local generation)

Choose your migration path

Select the approach that fits your situation:

Path 1: Upgrade your generator (Recommended)

This is the easiest path if you can upgrade to version 3.12.3 or later of the TypeScript SDK generator.

When to use this path:

  • You’re able to upgrade to Fern TypeScript SDK generator version 3.12.3 or later
  • You haven’t .fernignore’d your CI workflow file
1

Configure trusted publishing on npmjs.com

Follow npm’s “Add a trusted publisher on npmjs.com” instructions:

  1. Navigate to your package settings on npmjs.com
  2. Find the Trusted Publisher section and click Add trusted publisher
  3. Select GitHub Actions as your provider
  4. Configure:
    • Organization or user: Your GitHub username or organization
    • Repository: Your TypeScript SDK repository name
    • Workflow filename: ci.yml (the default Fern workflow file)
    • Environment name: Leave blank (unless you use GitHub environments)
2

Update your generators.yml

Change the output.token field from ${NPM_TOKEN} to OIDC and ensure you’re using version 3.12.3 or later:

generators.yml
1groups:
2 ts-sdk:
3 generators:
4 - name: fernapi/fern-typescript-sdk
5 version: 3.69.0 # Must be 3.12.3 or later
6 output:
7 location: npm
8 package-name: your-package-name
9 token: OIDC # Changed from ${NPM_TOKEN}
10 config:
11 namespaceExport: YourClientName
12 github:
13 repository: your-org/your-repository
3

Regenerate your SDK

Regenerate your SDK with the updated CI configuration. You can do this either:

Locally:

$fern generate --group ts-sdk

Or via GitHub Actions:

If you use the Fern GitHub Action to generate your SDK, simply push your updated generators.yml file and let the workflow regenerate the SDK for you.

This will update your .github/workflows/ci.yml file with the required OIDC permissions.

4

Remove the NPM_TOKEN secret

After verifying the migration works, remove the NPM_TOKEN secret from your GitHub repository settings to prevent accidental use.

Path 2: Manual CI workflow update

Use this path if you can’t upgrade the generator or have customized your CI workflow.

When to use this path:

  • You can’t upgrade due to breaking changes or bugs
  • You’ve customized your CI workflow and added it to .fernignore
  • Path 1 didn’t update your workflow file
1

Configure trusted publishing on npmjs.com

Follow the same instructions as Path 1 to add your repository as a trusted publisher on npmjs.com.

2

Update your CI workflow manually

Open your .github/workflows/ci.yml file and make these changes to the publish job:

.github/workflows/ci.yml
1publish:
2 needs: [ compile, test ]
3 if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
4 runs-on: ubuntu-latest
5 permissions:
6 contents: read # ADD THIS: Required for actions/checkout@v4
7 id-token: write # ADD THIS: Required for OIDC
8 steps:
9 - name: Checkout repo
10 uses: actions/checkout@v4
11
12 - name: Set up node
13 uses: actions/setup-node@v4
14
15 # ADD THIS: Ensure npm 11.5.1 or later is installed for OIDC support
16 - name: Update npm
17 run: npm install -g npm@latest
18
19 - name: Install pnpm
20 uses: pnpm/action-setup@v4
21
22 - name: Install dependencies
23 run: pnpm install
24
25 - name: Build
26 run: pnpm build
27
28 # MODIFY THIS: Remove npm config set and env block
29 - name: Publish to npm
30 run: |
31 if [[ ${GITHUB_REF} == *alpha* ]]; then
32 npm publish --access public --tag alpha
33 elif [[ ${GITHUB_REF} == *beta* ]]; then
34 npm publish --access public --tag beta
35 else
36 npm publish --access public
37 fi
38 # Previously had:
39 # run: |
40 # npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
41 # if [[ ${GITHUB_REF} == *alpha* ]]; then
42 # npm publish --access public --tag alpha
43 # elif [[ ${GITHUB_REF} == *beta* ]]; then
44 # npm publish --access public --tag beta
45 # else
46 # npm publish --access public
47 # fi
48 # env:
49 # NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Key changes:

  • Add permissions block with id-token: write and contents: read to the publish job
  • Add step to update npm to version 11.5.1 or later
  • Remove the npm config set line from the publish step
  • Remove the env block with NPM_TOKEN from the publish step
3

(Optional) Add ci.yml to .fernignore

If you haven’t already, add your CI workflow to .fernignore to prevent future generator updates from overwriting your manual changes:

.fernignore
.github/workflows/ci.yml
4

Remove the NPM_TOKEN secret

After verifying the migration works, remove the NPM_TOKEN secret from your GitHub repository settings.

Verify your migration

After completing either migration path:

  1. Trigger a workflow run by creating a GitHub release with an alpha tag (for example, v1.0.0-alpha)
  2. Check the workflow logs to verify the publish step succeeds
  3. Verify provenance by visiting your package on npmjs.com - you should see a provenance badge

Migration troubleshooting

"Unable to authenticate" error

Common causes:

  • Workflow filename doesn’t match exactly (must be ci.yml with the .yml extension)
  • Missing id-token: write or contents: read permissions in workflow
  • npm CLI version is older than 11.5.1
  • Using self-hosted runners (not supported)

Solution: Double-check your trusted publisher configuration on npmjs.com matches your actual workflow file name and verify all requirements are met.

Workflow still using NPM_TOKEN

If your workflow continues using token-based authentication:

  • Verify you’ve removed the npm config set line and the env: NPM_TOKEN block from the publish step
  • Check that npm CLI version 11.5.1+ is installed (add the update npm step)
  • Ensure you’re using generator version 3.12.3 or later (if using Path 1)
  • When using --local generation, you need to use Fern CLI version 0.94.0 or later