Code examples
Choose the languages for generated request examples, or add your own SDK and CLI code samples with the x-codeSamples extension or Speakeasy.
Every endpoint page shows request code examples next to the playground. By default, Mintlify generates them from your OpenAPI specification in the languages you choose. If your users call your API through an SDK or CLI, add your own examples with the x-codeSamples extension, or pull them from Speakeasy.
Choose example languages
Set api.examples.languages in your docs.json to choose which languages appear in generated examples. Languages display in the order you list them.
Set defaults to required to leave optional parameters out of generated examples. The default, all, includes them.
To show only the examples you write, set api.examples.autogenerate to false. Endpoint pages then show only x-codeSamples from your specification, or <RequestExample> components on MDX pages.
Write your own examples
Add the x-codeSamples property to any operation. It has the following schema.
The language of the code sample.
The label for the sample. This is useful when providing multiple examples for a single endpoint.
The source code of the sample.
The following example shows code samples for a plant tracking app that has both a Bash CLI tool and a JavaScript SDK.
Generate examples with Speakeasy
If you generate your SDKs with Speakeasy, you can pull its autogenerated snippets into your API reference instead of maintaining them by hand. The snippets appear in the interactive playground alongside your endpoints.
