*** title: Display SDK snippets description: >- Enable SDK code examples in TypeScript, Python, Go, and more from the request and response examples documented in your API definition. Once enabled, Fern Docs will automatically populate the snippets within your API Reference. ------------------------------------------------------------------------ For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see [https://buildwithfern.com/learn/llms.txt](https://buildwithfern.com/learn/llms.txt). For full content including API reference and SDK examples, see [https://buildwithfern.com/learn/llms-full.txt](https://buildwithfern.com/learn/llms-full.txt). If you use Fern to generate SDKs, you can display SDK code snippets in your API Reference. These snippets show examples using your actual SDK in TypeScript, Python, Go, and other supported languages. Once configured, SDK snippets replace [HTTP snippets](/learn/docs/api-references/http-snippets). By default, SDK snippets are dynamic code examples that allow users to modify parameters and see code examples update in real time across all supported languages. Alternatively, you can [disable dynamic snippets in your `docs.yml`](/learn/docs/configuration/site-level-settings#experimentaldynamic-snippets) and use static code examples. ![SDK code snippet selector](https://fern-image-hosting.s3.amazonaws.com/sdk-code-snippets.png) ## Configuration To configure SDK snippets, first name your SDKs in `generators.yml` and then reference that name in `docs.yml`. ### Add examples to your API definition Fern needs to read request examples from your API definition to generate code snippets. * For Fern Definition, follow the [examples documentation](/learn/api-definition/fern/examples). * For OpenAPI, follow [Swagger's examples documentation](https://swagger.io/docs/specification/adding-examples/). ### 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 the `output` section. * For **Java**, add `coordinate: com.your-org:your-package-name` to the `output` section. * For **PHP**, add `packageName: YourPackageName` to the `config` section. * For **Go**, add `repository: your-organization/your-repository` to the `github` section. Fern supports SDK snippets for TypeScript, Python, Ruby, Go, Java, PHP, and .NET/C#. [File an issue](https://github.com/fern-api/fern/issues) to request additional languages. ```yaml {9, 16, 22, 28, 34, 41, 46} groups: production: generators: - name: fernapi/fern-python-sdk version: 4.62.0 output: location: pypi token: ${PYPI_TOKEN} package-name: your-package-name # <--- add this field ... - name: fernapi/fern-typescript-sdk version: 3.53.7 output: location: npm token: ${NPM_TOKEN} package-name: your-package-name # <--- add this field - name: fernapi/fern-ruby-sdk version: 1.0.5 output: location: rubygems token: ${RUBYGEMS_TOKEN} package-name: your-package-name # <--- add this field - name: fernapi/fern-csharp-sdk version: 2.24.0 output: location: nuget api-key: ${NUGET_API_KEY} package-name: your-package-name # <--- add this field ... - name: fernapi/fern-java-sdk version: 3.42.4 output: location: maven coordinate: com.your-org:your-package-name # <--- add this field ... - name: fernapi/fern-php-sdk version: 2.1.6 github: repository: your-organization/your-repository config: packageName: YourPackageName # <--- add this field ... - name: fernapi/fern-go-sdk version: 1.28.4 github: repository: your-organization/your-repository # <--- add this field ... ``` ### 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 the `your-package-name` that you configured in your `generators.yml` file. * **For Java**, `com.your-org:your-package-name` must match the `coordinate` that you configured in your `generators.yml` file. * **For PHP**, `YourPackageName` must match the `packageName` that you configured in your `generators.yml` file. * **For Go**, use the exact URL where the SDK repository is located, including the `https://github.com/`. ```yaml {3-10} navigation: - api: API Reference snippets: python: your-package-name # <--- needs to match the naming in generators.yml typescript: your-package-name # <--- needs to match the naming in generators.yml ruby: your-package-name # <--- needs to match the naming in generators.yml csharp: your-package-name # <--- needs to match the naming in generators.yml java: com.your-org:your-package-name # <--- needs to match the coordinate in generators.yml php: YourPackageName # <--- needs to match the packageName in generators.yml go: https://github.com/your-organization/your-repository # <--- needs the https://github.com/ prefix ``` To display different package names for SDK users versus documentation users, [use overrides files](/learn/api-definitions/asyncapi/overrides#separate-overrides-for-sdks-and-docs). ### Trigger generation Trigger your docs generation by running `fern generate --docs` locally or in CI/CD (i.e., GitHub Actions). The SDK snippets will appear via a dropdown! ## Additional options ### Specify SDK versions You can specify which SDK version to use when generating code snippets. ```yaml {4-6} navigation: - api: API Reference snippets: python: package: your-package-name # <--- needs to match the naming in generators.yml version: your-version number # SDK version to use for snippets ``` ### Set default snippet language Use the `default-language` key at the top indentation level of `docs.yml`. This setting applies to both SDK snippets and HTTP snippets. ```yaml {1} default-language: typescript navigation: - api: API Reference snippets: python: your-package-name typescript: your-package-name ``` ## Endpoint request and response snippets Looking for information on generating API endpoint request and response snippets? See our documentation on [Endpoint Request Snippets](/learn/docs/content/components/request-snippet) and [Endpoint Response Snippets](/learn/docs/content/components/response-snippet).