Fern | Add SDK code snippets to your documentation

Fern allows you to add SDK code snippets to your documentation. This is useful for showing how to use your SDK in different languages. By default, Fern will generate cURL snippets. By following the steps below, you can add code snippets for other languages.

SDK code snippet selector

SDK snippets automatically populated in your Fern Docs is a paid feature included in the SDK Starter plan.

Language support

TypeScript and Python are the SDK code snippet languages supported today. Our development work is driven by customer requests, so please request support for another language by opening an issue.

Configuring SDK Snippets

To configure SDK snippets, you’ll need to name your SDKs in generators.yml and then reference that name in docs.yml. In the following example, We’ll use your-organization as the package name because it is a common practice. For example, Stripe calls their npm package stripe and Twilio calls their PyPI package twilio.

Step 0: Add examples to your API definition.

In order to generate code snippets, Fern needs to read request examples from your API definition. If you’re using a Fern Definition, you can follow these instructions. If you’re using an OpenAPI Specification, you can follow these instructions.

Step 1: Define a package name for your SDK(s).

2 production:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 0.7.6
6 output:
7 location: pypi
8 token: ${PYPI_TOKEN}
9 package-name: your-organization # <---- add this field
10 ...
11 - name: fernapi/fern-typescript-node-sdk
12 version: 0.9.0
13 output:
14 location: npm
15 token: ${NPM_TOKEN}
16 package-name: your-organization # <---- add this field
17 ...

Step 2: Add the package name to your docs configuration.

2 - api: API Reference
3 snippets:
4 python: your-organization # <---- needs to match the naming in generators.yml
5 typescript: your-organization

Access via API

If you’d like to bring SDK snippets into your own documentation, you can use the Snippets API. API acces requires a a SDK Business plan. is an example of a Fern customer that uses the Snippets API to bring Python code samples into their API Reference.