API Introduction
Welcome to the API Reference documentation. This guide covers all available endpoints and their usage.
Base URL
All API requests should be made to:
https://api.example.com/v1
Authentication
All requests must include an API key in the Authorization header:
curl https://api.example.com/v1/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"
Request Format
Requests should be sent as JSON with appropriate headers:
{
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
Response Format
All successful responses return JSON with this structure:
{
"id": "req_abc123",
"object": "generation",
"data": { ... },
"createdAt": "2025-01-15T12:00:00Z"
}
Error Responses
Errors follow this format:
{
"error": {
"type": "invalid_request_error",
"message": "Invalid API key provided",
"code": "invalid_api_key"
}
}
Common Error Codes
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid API key |
| 403 | Forbidden - Insufficient permissions |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error |
| 503 | Service Unavailable |
Rate Limiting
Rate limits are enforced per API key. When you exceed limits, you'll receive a 429 status code.
Headers in the response:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640000000
Pagination
List endpoints support pagination:
{
"data": [...],
"pagination": {
"page": 1,
"perPage": 20,
"total": 100,
"totalPages": 5
}
}
Use page and perPage query parameters:
GET /v1/resources?page=2&perPage=50
Idempotency
POST requests support idempotency via the Idempotency-Key header:
curl https://api.example.com/v1/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: unique-key-123" \
-H "Content-Type: application/json"
API Versions
The current API version is v1. Version is specified in the base URL.