Prompt
How do I generate SDK examples from an API spec?
Latest observation
Oct 4, 2026
OpenAI APIWeb search: off
To generate SDK examples from an API spec, the usual workflow is:
1) Start with a machine-readable API spec
Use something like:
- OpenAPI for REST APIs
- gRPC/protobuf for gRPC APIs
- GraphQL schema for GraphQL APIs
For SDK examples, OpenAPI is the most common.
2) Decide what “examples” means
You may want one or more of these:
- Code snippets for docs
- Runnable SDK sample projects
- Language-specific example calls generated from operations
- Request/response examples from schema examples in the spec
3) Add example data to the spec
To generate good examples, include:
summary/descriptionexample/examplesfields in schemas- sample values for parameters and request bodies
- example responses for each endpoint
In OpenAPI, for instance:
paths:
/users:
post:
summary: Create a user
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserCreate'
example:
name: Ada Lovelace
email: ada@example.com
4) Use a generator or documentation tool
Depending on your output, common tools include:
For SDK code generation
- OpenAPI Generator
- Swagger Codegen (older)
- Kiota (Microsoft)
- Fern
- Speakeasy
- StepZen (more GraphQL-oriented)
These can generate SDKs, and some can also generate example snippets or docs.
For docs with examples
- Redoc / Redocly
- Swagger UI
- Stoplight
- Docusaurus + custom plugins
- Slate / Mintlify / ReadMe integrations
5) Generate language-specific snippets
If you want examples like:
client.users.create(name="Ada Lovelace")
you typically need a snippet generator that maps OpenAPI operations to SDK methods.
Some platforms support this directly:
- OpenAPI + SDK generator
- Docs tooling with snippet templates
- Custom templates if your SDK method names differ from the raw API paths
6) Validate against the generated SDK
Make sure the examples:
- use the correct method names
- include required auth setup
- reflect actual parameter names and types
- are runnable and tested
7) Automate in CI
A common setup:
- Spec changes trigger SDK generation
- Example snippets are regenerated
- Tests verify examples compile/run
- Docs are published automatically
Practical approach for OpenAPI
If you have an OpenAPI spec and want examples in multiple languages:
- Add examples to the spec.
- Generate SDKs with OpenAPI Generator or Fern/Speakeasy.
- Use a docs generator or template layer to render code snippets per language.
- Run example tests in CI.
If you want a quick-start toolchain
A simple modern stack is:
- OpenAPI spec
- OpenAPI Generator for SDKs
- Redocly / Mintlify / ReadMe for docs
- CI pipeline to regenerate snippets and validate them
If you want, I can show you:
- a concrete OpenAPI example,
- how to generate Python/JavaScript/Java SDK snippets, or
- a full CI pipeline for auto-generating examples from your spec.