Display SDK snippets
When you use Fern’s SDK Generator, you can automatically display SDK code snippets in your API Reference. These snippets are generated from your API definition examples and appear in a language selector dropdown, with cURL as the default option.
Dynamic snippets
By default, SDK snippets are static code examples. Alternatively, you can use dynamic SDK snippets that allow users to modify parameters and see code examples update in real time.
To use dynamic snippets, enable them in your docs.yml
and then complete the setup instructions on this page.
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
.
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)
Configure package names in your generators.yml
file:
- For Python, TypeScript, Ruby, and .NET/C#, add
package-name: your-package-name
to theoutput
section. - For Go, add
repository: your-organization/your-repository
to thegithub
section.
Add the package name to your docs configuration
Add the package name for the corresponding SDK to your docs.yml
file:
- For Python, TypeScript, Ruby, and .NET/C#,
your-package-name
must match theyour-package-name
that you configured in yourgenerators.yml
file. - For Go, use the exact URL where the SDK repository is located, including the
https://github.com/
.
To display different package names for SDK users versus documentation users, use overrides files.
Specify SDK versions (optional)
You can specify which SDK version to use when generating code snippets.
Access via API
Pro and Enterprise feature
This feature is available only for the Pro and Enterprise plans. To get started, reach out to support@buildwithfern.com.
If you’d like to bring SDK snippets into your own documentation, you can use the Snippets API.
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.