x-codeSamples extension to add code samples to your OpenAPI document and display them in your OpenAPI pages.
SDK examples appear alongside the default cURL examples in your API playground, making it easier for developers to integrate with your API using their preferred language or framework.
This property can be added to any request method and 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.
Multiple SDK languages
You can provide examples in multiple programming languages to support different developer audiences. Common languages include:Best practices
Use realistic examples
Use realistic examples
Provide examples that reflect actual use cases rather than placeholder code. Include error handling and common patterns your users will need.
Keep examples concise
Keep examples concise
Focus on the essential code needed to make the API call. Avoid unnecessary boilerplate that distracts from the core functionality.
Match your SDK
Match your SDK
If you provide official SDKs, ensure the examples match your SDK’s actual API and conventions. Keep examples updated when your SDK changes.
Include authentication
Include authentication
Show how to properly authenticate requests in each language, as authentication patterns vary significantly across SDKs.
Add helpful labels
Add helpful labels
Use descriptive labels when providing multiple examples for the same endpoint to help users find the right example quickly.
Related resources
Learn more about OpenAPI setup
Configure OpenAPI specifications and generate API documentation