Request + response examples
Request + response examples
Fern generates realistic examples automatically using AI-generated examples, enabled by default. Use x-fern-examples to manually define specific values, associate request and response pairs that OpenAPI’s separate example fields can’t link, or define multiple named examples for an endpoint.
Manual examples take priority over AI-generated ones, and you can disable AI examples entirely.
Structure
x-fern-examples is an array. Each element can contain path-parameters, query-parameters, headers, request, and response values that are all associated. Optionally, add a name field to provide a descriptive label.
The request and response values use different shapes:
requestholds the request body properties directly.responserequires a nestedbodykey containing the response body properties.
Examples must include any headers declared with the x-fern-global-headers extension. Place them under headers alongside path-parameters and request.
An endpoint with path parameters:
An endpoint with a request body:
Code samples
Fern generators automatically add SDK code samples. To specify custom code samples for an example, use code-samples.
Each code sample uses one of two keys to identify the language:
sdk— for a language that maps to a Fern-supported SDK tab:curl,python,javascript,typescript,go,ruby,csharp,java,js,node,ts,nodets,golang,dotnet,jvm,c#.language— for any other language, or when you want to include aninstallcommand.
Using sdk
Using language
Convert to native OpenAPI examples
To make x-fern-examples work with non-Fern OpenAPI tools, run fern api enrich to convert them into native OpenAPI example fields.