Api documentation

From 5throck/ai-workspace-standards · View interactive version

Api documentation is an AI agent skill from the GitHub repository 5throck/ai-workspace-standards. Creates comprehensive API documentation including endpoints, parameters, authentication, request/response schemas, and code examples. Use when: documenting REST APIs, GraphQL interfaces, SDKs, or developer-facing technical specifications.

How to use this skill

Skill file

Context

This skill provides systematic API documentation capabilities, creating comprehensive developer resources that enable API integration and adoption. It ensures documentation is accurate, complete, and developer-friendly.

When to Use

API Documentation:

SDK Documentation:

API Updates:

Developer Resources:


Execution Steps

Step 1: API Analysis and Structure

Purpose: Understand API structure and documentation requirements.

API Analysis Process:

  1. API Type Identification:
  1. Endpoint/Operation Inventory:
  1. Data Model Analysis:
  1. Developer Use Cases:

Documentation Structure:

1. Overview (getting started, authentication)
2. Quick Start (simple example)
3. API Reference (detailed endpoints)
4. Guides (tutorials, best practices)
5. SDK Reference (if applicable)
6. Error Handling (troubleshooting)
7. Changelog (version history)

Step 2: Getting Started Documentation

Purpose: Help developers begin using the API quickly.

Getting Started Components:

  1. Overview Section:
  1. Authentication Guide:
  1. Quick Start Example:
  1. Setup Instructions:

Quick Start Template:

## Quick Start

### 1. Get API Key
Register at [url] to get your API key

### 2. Make Your First Request
\`\`\`bash
curl -X GET "https://api.example.com/v1/users" \\
  -H "Authorization: Bearer YOUR_API_KEY"
\`\`\`

### 3. Expected Response
\`\`\`json
{
  "users": [...],
  "total": 10
}
\`\`\`

Step 3: API Reference Documentation

Purpose: Create detailed documentation for each endpoint/operation.

Endpoint Documentation Structure:

  1. Endpoint Overview:
  1. Request Parameters:
  1. Response Documentation:
  1. Error Responses:

Endpoint Template:

## Get Users

Retrieves a list of users with optional filtering.

### Request
\`GET /v1/users\`

### Query Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| limit | integer | No | Number of results (1-100, default: 20) |
| offset | integer | No | Pagination offset (default: 0) |

### Response
\`\`\`json
{
  "users": [
    {
      "id": "user_123",
      "name": "John Doe",
      "email": "john@example.com"
    }
  ],
  "total": 1,
  "limit": 20,
  "offset": 0
}
\`\`\`

### Errors
| Status | Description |
|--------|-------------|
| 400 | Invalid query parameter |
| 401 | Unauthorized (invalid API key) |
| 429 | Rate limit exceeded |

Step 4: Request/Response Schema Documentation

Purpose: Document data structures and validation rules.

Schema Documentation:

  1. Request Schemas:
  1. Response Schemas:
  1. Data Types:

Schema Documentation Format:

### User Object

| Field | Type | Nullable | Description |
|-------|------|----------|-------------|
| id | string | No | Unique user identifier |
| name | string | No | User's full name |
| email | string | No | User's email address |
| created_at | string (ISO 8601) | No | Account creation timestamp |
| updated_at | string (ISO 8601) | Yes | Last update timestamp |

**Example**
\`\`\`json
{
  "id": "user_123",
  "name": "John Doe",
  "email": "john@example.com",
  "created_at": "2026-05-26T12:00:00Z"
}
\`\`\`

Step 5: Code Examples and SDKs

Purpose: Provide working code examples in multiple languages.

Code Example Guidelines:

  1. Language Coverage:
  1. Example Quality:
  1. SDK Documentation (if applicable):

Code Example Template:

import os
import requests

API_KEY = os.environ["API_KEY"]  # never hardcode credentials
BASE_URL = "https://api.example.com/v1"

def get_users(limit=20, offset=0):
    """
    Retrieve a list of users.
    
    Args:
        limit: Number of results (1-100)
        offset: Pagination offset
    
    Returns:
        List of users
    
    Raises:
        ValueError: If parameters are invalid
        requests.HTTPError: If API request fails
    """
    url = f"{BASE_URL}/users"
    headers = {"Authorization": f"Bearer {API_KEY}"}
    params = {"limit": limit, "offset": offset}
    
    try:
        response = requests.get(url, headers=headers, params=params)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as e:
        print(f"API Error: {e}")
        raise

Step 6: Error Handling and Troubleshooting

Purpose: Help developers handle errors effectively.

Error Documentation:

  1. HTTP Status Codes:
  1. Error Response Format:
  1. Common Issues:
  1. Troubleshooting Guides:

Error Documentation Template:

## Error Handling

### HTTP Status Codes

| Status | Meaning | Resolution |
|--------|---------|------------|
| 400 | Bad Request | Fix request parameters |
| 401 | Unauthorized | Check API key |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Verify endpoint URL |
| 429 | Rate Limit | Wait and retry |

### Error Response Format
\`\`\`json
{
  "error": {
    "code": "INVALID_PARAMETER",
    "message": "Invalid value for 'limit' parameter",
    "details": {
      "parameter": "limit",
      "value": 999,
      "constraint": "1-100"
    }
  }
}
\`\`\`

### Common Issues

**Issue**: "401 Unauthorized"
**Solution**: Verify API key is correct and not expired

**Issue**: "429 Rate Limit Exceeded"
**Solution**: Implement exponential backoff, wait before retry

Step 7: Versioning and Changelog

Purpose: Document API evolution and breaking changes.

Versioning Strategy:

  1. Semantic Versioning:
  1. URL Versioning:
  1. Header Versioning:

Changelog Format:

## Changelog

### [Version] - [Date]

#### Added
- New endpoint description
- New parameter description

#### Changed
- Modified endpoint behavior
- Updated response format

#### Deprecated
- Endpoint deprecation notice

#### Removed
- Removed endpoint (include migration guide)

Output Format

For REST API Documentation:

For GraphQL API Documentation:

For SDK Documentation:


Best Practices

Documentation Quality:

✅ Do:

❌ Don't:

Developer Experience:

✅ Do:

❌ Don't:


Common Mistakes to Avoid

Documentation Anti-Patterns:

  1. Outdated Docs: Documentation not synced with API changes
  2. Missing Examples: Text-only without working code
  3. Poor Search: Hard to find specific endpoints or info
  4. Inconsistent Structure: Different formats across sections
  5. Missing Context: Not explaining "why" or "when to use"

Content Anti-Patterns:

  1. Assumptions: Assuming prior knowledge
  2. Ambiguity: Unclear parameter descriptions
  3. Incomplete Info: Missing required parameters
  4. No Error Handling: Examples without error cases
  5. Dead Links: References to non-existent resources

Related Skills


API Documentation Tools

Static Site Generators:

API Documentation Tools:

Interactive API Explorers:

Code Examples Tools:


Documentation Quality Checklist

Content Quality:

Usability Quality:

Maintainability Quality:


OpenAPI/Swagger Specification

OpenAPI 3.0 Structure:

openapi: 3.0.0
info:
  title: API Name
  version: 1.0.0
  description: API description
servers:
  - url: https://api.example.com/v1
    description: Production server

paths:
  /users:
    get:
      summary: Get users
      description: Retrieve list of users
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
          description: Number of results
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  users:
                    type: array
                    items:
                      $ref: '#/components/schemas/User'

GraphQL Documentation

GraphQL Documentation Components:

  1. Schema Documentation:
  1. Operation Documentation:
  1. Example Queries:

GraphQL Documentation Format:

"""
User type definition
"""
type User {
  """
  Unique user identifier
  """
  id: ID!
  
  """
  User's full name
  """
  name: String!
  
  """
  User's email address
  """
  email: String!
  
  """
  Timestamp when user was created
  """
  createdAt: String!
}

"""
Query users
"""
type Query {
  """
  Get list of users
  """
  users(
    """
    Number of users to return
    """
    limit: Int = 20
    
    """
    Pagination offset
    """
    offset: Int = 0
  ): [User!]!
}
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.