Prompt Library 💻 Coding & Dev Create API Specification
GPT-4o 💻 Coding & Dev Advanced

Create API Specification

Write a complete REST API specification with endpoints, request/response schemas, authentication, and error handling.
👁 3 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Create an API Specification

You are a senior backend engineer and API design expert. Write a comprehensive REST API specification document.

## API Details
- **API Name:** [API_NAME]
- **Purpose:** [PURPOSE] (what this API does and who consumes it)
- **Version:** v[VERSION_NUMBER]
- **Base URL:** [BASE_URL] (e.g., https://api.yourapp.com/v1)
- **Authentication Method:** [AUTH_METHOD] (e.g., API Key, OAuth 2.0, JWT Bearer Token, Basic Auth)
- **Primary Resources:** [RESOURCES] (list the main data objects, e.g., users, products, orders, posts)
- **Documentation Format:** [FORMAT] (OpenAPI 3.0 YAML, Markdown, Postman collection)

## API Specification

### Authentication
- Auth method: [AUTH_METHOD]
- How to obtain credentials
- How to include credentials in requests (header name, format)
- Token expiry and refresh flow (if applicable)
- Example authenticated request

### Endpoints — For Each Resource in [RESOURCES]:

#### [RESOURCE NAME]

**GET /[resources]** — List all
- Description
- Query parameters: pagination (page, limit), filtering, sorting
- Request headers
- Response 200: schema with example
- Response 400, 401, 404, 500: error schemas

**GET /[resources]/{id}** — Get single
- Path parameters
- Response 200 with full object schema
- Response 404 example

**POST /[resources]** — Create
- Request body schema (required vs. optional fields)
- Validation rules
- Response 201 with created object

**PUT /[resources]/{id}** — Full update
- Request body schema
- Response 200

**PATCH /[resources]/{id}** — Partial update
- Which fields are patchable
- Response 200

**DELETE /[resources]/{id}** — Delete
- Soft delete vs. hard delete
- Response 204

### Error Response Standard
Define the universal error response envelope:
```json
{
  "error": {
    "code": "string",
    "message": "string",
    "details": []
  }
}
```

### Rate Limiting
- Limits: X requests per minute per API key
- Headers returned: X-RateLimit-Limit, X-RateLimit-Remaining, Retry-After
- Response when exceeded: 429 Too Many Requests

### Pagination Standard
- Strategy: cursor-based or offset/limit
- Response envelope with next/prev links and total count

### Versioning Strategy
- How breaking changes are handled
- Deprecation timeline and communication

Generate the full spec for all [RESOURCES]. Include realistic example JSON for every request and response body.

📝 Fill in the blanks

Replace these placeholders with your own content:

[API_NAME]
[PURPOSE]
[VERSION_NUMBER]
[BASE_URL]
[AUTH_METHOD]
[RESOURCES]
[FORMAT]
[RESOURCE NAME]
[resources]

How to use this prompt

1
Copy the prompt

Click "Copy Prompt" above to copy the full prompt text to your clipboard.

2
Replace the placeholders

Swap out anything in [BRACKETS] with your specific details.

3
Paste into GPT-4o

Open your preferred AI assistant and paste the prompt to get started.