Display SDK snippets
If you use Fern’s SDK Generator, you can automatically show SDK code snippets in your API Reference. SDK languages appear in a drop-down. By default, cURL snippets will be displayed to users.
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
.
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.
Define a package name for your SDK(s)
SDK snippets automatically populated in your Fern Docs is a paid feature included in the SDK Starter plan.
Add the package name to your docs configuration
Add the package name for the corresponding SDK to your docs.yml
file. For Go, use the exact URL where the SDK repository is located.
Trigger generation
As the final step, trigger your docs generation by running fern generate --docs
locally or in CI/CD (i.e., GitHub Actions). The SDK snippets will now appear via a drop-down!
Set default snippet
To set the default snippet shown in the API Reference drop-down, specify the default-language
in your docs.yml
.
Language support
TypeScript, Python, Go, and Ruby are the supported SDK code snippet languages. Our development work is driven by customer requests, so please request support for another language by opening an issue.
Access via API
If you’d like to bring SDK snippets into your own documentation, you can use the Snippets API. API access requires a SDK Business plan or above.
Merge.dev is an example of a Fern customer that uses the Snippets API to bring Python code samples into their API Reference.
Endpoint request and response snippets
Looking for information on generating API endpoint request and response snippets? See our documentation on Endpoint Request Snippets and Endpoint Response Snippets.