Prompt
How do I add multiple language examples to API docs?
Latest observation
Oct 4, 2026
OpenAI APIWeb search: off
A good way to add multiple language examples to API docs is to provide the same request/response in a few common languages, usually under a shared endpoint section.
Typical structure
For each endpoint, include:
- Overview: what the endpoint does
- Request details: URL, method, headers, auth
- Example(s):
- cURL
- JavaScript / TypeScript
- Python
- Java / C# / Go if relevant
- Response examples
- Error examples
Example layout
## Create a user
**POST** `/users`
### cURL
```bash
curl -X POST https://api.example.com/users \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Ada","email":"ada@example.com"}'
JavaScript
const res = await fetch("https://api.example.com/users", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
},
body: JSON.stringify({ name: "Ada", email: "ada@example.com" })
});
Python
import requests
res = requests.post(
"https://api.example.com/users",
headers={
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
},
json={"name": "Ada", "email": "ada@example.com"}
)
### Best practices
- Keep examples **consistent** across languages.
- Use the **same sample data** so it’s easy to compare.
- Prefer **copy-pasteable code**.
- If you have many languages, make them **tabbed** or **collapsible** in your docs UI.
- Highlight one or two **primary languages** and keep others optional.
### If you use OpenAPI/Swagger
OpenAPI supports examples in schemas and request bodies, and many doc tools let you show multiple code samples via:
- custom `x-codeSamples`
- vendor extensions
- documentation platform features like tabs/switchers
Example (common pattern in some tools):
```yaml
x-codeSamples:
- lang: curl
source: |
curl -X POST https://api.example.com/users ...
- lang: JavaScript
source: |
fetch("https://api.example.com/users", { ... })
- lang: Python
source: |
requests.post("https://api.example.com/users", ...)
If you want, I can show you how to do this in OpenAPI, Markdown, Swagger UI, or a specific docs tool like Redoc, Stoplight, or Docusaurus.