Skip to content

Verified by AI Team

This flow has been practiced in multiple projects, including Apidog integration and OpenAPI spec generation.

API Design Flow

API design follows an API-First approach where the specification precedes implementation, and AI agents generate API specs from high-level requirements combined with design principles.

API-First Principle

API-First Design Flow

Flow Steps

  1. High-Level Spec - Business requirements and user stories define what the API needs to accomplish
  2. API Design Principles - Organizational guidelines ensure consistency across APIs
  3. AI Agent Generation - Agent drafts OpenAPI spec based on inputs
  4. Human Review - Engineers review for correctness, security, and alignment
  5. Mock Server - Generate mock server for early consumer validation
  6. Consumer Validation - Consumers test against mock, provide feedback
  7. Implementation - Backend implements against approved spec
  8. Contract Testing - Automated tests verify implementation matches spec
  9. Documentation - Publish API documentation for consumers

API Specification Platform

API Specs Documentation Viewer

POC Status

This is a proof-of-concept implementation. Additional resources are required for further research and development before production adoption.

Agent Role in API Design

PhaseAgent Contribution
Spec DraftingGenerate OpenAPI from high-level spec + API principles
Consistency CheckValidate against organizational API guidelines
Mock GenerationCreate mock server from OpenAPI spec
Test GenerationGenerate contract tests from scenarios
Integration AnalysisIdentify platform constraints from documentation
Adapter GenerationGenerate adapter interface from integration.md

API Design Principles (ADP)

Organizations should maintain an API Design Principles (ADP) document that codifies API standards. This document serves as guiding principles for AI agents when reading high-level specs to generate API specifications, preventing context pollution issues such as API spec misalignment.

Reference: An organizational ADP proposal is available at API Design Principle.

ADP Document Structure

markdown
# API Design Principles (ADP)

## Naming Conventions
- Resource naming: plural nouns, kebab-case
- Query parameters: camelCase
- Headers: X-Custom-Header format

## Versioning Strategy
- URL path versioning: /api/v1/resources
- Breaking change definition
- Deprecation timeline (minimum 6 months)

## Authentication & Authorization
- Standard auth mechanisms (OAuth 2.0, API keys)
- Token formats and lifetimes
- Scope naming conventions

## Error Response Format
- Standard error schema
- Error code taxonomy
- Localization requirements

## Pagination & Filtering
- Cursor vs offset pagination
- Filter parameter patterns
- Sort parameter format

## Rate Limiting
- Rate limit headers
- Quota policies
- Retry-After behavior

How AI Agents Use ADP

The ADP document should be:

  • Referenced in CLAUDE.md - So AI agents always consider it
  • Version controlled - Changes tracked and reviewed
  • Enforced via linting - Automated validation against OpenAPI specs

Core Principles

  1. API-First, always - Spec before implementation; AI generates draft, human approves
  2. Consumer-driven - Design from consumer perspective, validate with consumers
  3. Backward compatibility - Breaking changes require deprecation flow
  4. Consistent conventions - Follow organizational ADP document
  5. Testable contracts - Every endpoint has contract tests derived from spec
  6. Platform transparency - Document external platform constraints in integration.md

Anti-patterns

Anti-patternProblemCorrect Approach
Implementation-firstAPI design constrained by existing codeSpec defines the contract, implementation follows
Undocumented breaking changesConsumers break silentlyFormal deprecation with version migration
Inconsistent conventionsHard to learn, error-prone integrationFollow organizational API style guide
Missing error specsConsumers can't handle failures properlyDefine all error responses in spec
No consumer validationAPI doesn't meet actual needsTest with mock server before implementation

Related: Workflow Framework Overview