API Documentation Best Practices for Developers
Write API documentation that developers actually want to read. Covers structure, examples, authentication docs, error handling, and tools.
The quality of your API documentation directly affects adoption. Developers evaluating your API will spend 5 minutes reading your docs before deciding whether to integrate. Here's how to make those 5 minutes count.
Start with a quick win
The first thing in your API docs should be a working example. Not authentication setup, not architecture overview — a curl command that returns real data.
curl https://api.example.com/v1/status{
"status": "operational",
"version": "1.4.2",
"timestamp": "2026-03-10T12:00:00Z"
}This proves the API works and gives developers confidence to keep reading.
Document every endpoint consistently
Use a consistent template for every endpoint:
## Create User
Creates a new user account.
**Endpoint:** `POST /v1/users`
**Authentication:** Bearer token required
### Request Body
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| email | string | Yes | User email address |
| name | string | Yes | Display name |
| role | string | No | Default: "member" |
### Example Request
\`\`\`bash
curl -X POST https://api.example.com/v1/users \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"email": "jane@example.com", "name": "Jane Doe"}'
\`\`\`
### Response (201 Created)
\`\`\`json
{
"id": "usr_abc123",
"email": "jane@example.com",
"name": "Jane Doe",
"role": "member",
"created_at": "2026-03-10T12:00:00Z"
}
\`\`\`
### Errors
| Status | Code | Description |
|--------|------|-------------|
| 400 | invalid_email | Email format is invalid |
| 409 | email_exists | A user with this email already exists |
| 401 | unauthorized | Missing or invalid token |Authentication section
Document authentication upfront with concrete examples:
- How to get credentials — Link to the dashboard or signup flow
- How to authenticate — Show the exact header format
- Token lifecycle — Expiration, refresh, and rotation
- Scopes — What permissions each scope grants
## Authentication
All API requests require a Bearer token in the Authorization header:
\`\`\`bash
Authorization: Bearer YOUR_API_KEY
\`\`\`
Get your API key from the [dashboard](https://app.example.com/settings/api).
Keys are project-scoped and do not expire.Error handling
Document your error format once, then reference it:
{
"error": {
"code": "rate_limited",
"message": "Too many requests. Retry after 30 seconds.",
"retry_after": 30
}
}List all possible error codes in a single reference table. Developers will bookmark this page.
Rate limiting
Be transparent about limits:
## Rate Limits
| Plan | Requests/minute | Requests/day |
|------|----------------|--------------|
| Free | 60 | 1,000 |
| Pro | 600 | 50,000 |
Rate limit headers are included in every response:
- `X-RateLimit-Limit` — Your plan's limit
- `X-RateLimit-Remaining` — Requests remaining
- `X-RateLimit-Reset` — Unix timestamp when the limit resetsPagination
If any endpoint returns lists, document pagination early:
## Pagination
List endpoints return paginated results. Use `cursor` for efficient pagination:
\`\`\`bash
GET /v1/users?limit=20&cursor=usr_abc123
\`\`\`
Response includes a `next_cursor` field. When it's `null`, you've reached the end.SDKs and code examples
Show examples in the languages your users actually use. At minimum, cover:
- curl — Universal baseline
- JavaScript/TypeScript — Most common for web APIs
- Python — Most common for data/ML APIs
import { Client } from "example-sdk";
const client = new Client("YOUR_API_KEY");
const user = await client.users.create({
email: "jane@example.com",
name: "Jane Doe",
});Versioning
Document your versioning strategy:
## Versioning
The API version is included in the URL path: `/v1/`, `/v2/`.
- Breaking changes trigger a major version bump
- New fields added to existing responses are non-breaking
- Deprecated endpoints are supported for 12 monthsChangelog
Maintain an API changelog so developers know what changed:
## Changelog
### 2026-03-10
- Added `role` field to User object
- Deprecated `GET /v1/users/search` (use query params on `GET /v1/users`)
### 2026-02-15
- Increased rate limits for Pro plan
- Added cursor-based paginationDocumentation tools
| Tool | Best for | |------|----------| | Swagger/OpenAPI | REST APIs with auto-generated docs | | Redoc | Beautiful OpenAPI rendering | | Mintlify | Modern docs with great DX | | ReadMe.com | Interactive API explorer | | Docusaurus | Custom documentation sites |
README for API projects
Your API project's README should include a quick start example, authentication overview, and link to full documentation. Our API docs README template covers this, and you can generate one from your codebase automatically.
For general README quality tips, score your README with our free checker or read the complete README writing guide.