# API Error Format Design

> Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components. Use when working with format design, schema authoring or when the user mentions format design, schema authoring.

- Skill: `opknock/api-error-format-design` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-error-format-design`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-error-format-design/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-error-format-design

---


Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components.

## Agentic Workflow: Read -> Reason -> Act (api-error-format-design)

You are **Api Error Format Design** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — backend context for `api-error-format-design`
- Domain: Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components.
- **format-design**: Model problem-details schemas and map domain codes to HTTP statuses — `node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:4`
- **schema-authoring**: Author reusable error schemas in OpenAPI components — `node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:`
- Check `knowledge` and `prerequisites: node.js, python, openapi`

### 2. Reason — think for `api-error-format-design`
- For `format-design`: Model problem-details schemas and map domain codes to HTTP statuses — decide which checks to run
- For `schema-authoring`: Author reusable error schemas in OpenAPI components — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-error-format-design` tools
- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Swagger-cli` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-error-format-design:320d6648`

# API Error (Format Design)

Designs the error contract before implementation: formats, status mapping, and reusable schemas.

## When to Use
- Greenfield API error design
- Standardizing across services
- Defining what clients can rely on

## Real Commands

```bash
# Draft the format
node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:400,code:'VALIDATION_1001',instance:'/api/users'};console.log(JSON.stringify(p,null,2))"

# Define status mapping
node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[429,'RATE']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"

# Reusable schema
node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}}}};console.log(JSON.stringify(s,null,2))"
```

## Design Principles
- Machine-readable `code`, human-readable `title`
- Status codes map to error families
- `instance` points to the failing request

## Testing
Validate the spec with swagger-cli after adding error components.

## Best Practices
- Keep error responses in the spec from day one
- Add examples per status code

## Capabilities

### format-design
Model problem-details schemas and map domain codes to HTTP statuses

**Parameters:**
- `status` (string): HTTP status
- `code` (string): Domain error code

**Commands:**
- `node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:400,code:'VALIDATION_1001',instance:'/api/users'};console.log(JSON.stringify(p,null,2))"`
- `python -c "import json;p={'title':'Not Found','status':404,'code':'NOT_FOUND'};print(json.dumps(p))"`
- `node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[409,'CONFLICT'],[429,'RATE'],[500,'INTERNAL'],[502,'UPSTREAM']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"`
- `node -e "console.log(['client','server','integration'].map(f=>f+'_errors').join(' '))"`
- `python -c "print({400:'VALIDATION_1XXX',500:'INTERNAL_5XXX'})"`

**Examples:**
- node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[429,'RATE']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"
- node -e "const p={title:'Conflict',status:409,code:'CONFLICT_2001'};console.log(JSON.stringify(p))"
- python -c "import json;print(json.dumps({'status':503,'code':'UPSTREAM_9001'}))"

### schema-authoring
Author reusable error schemas in OpenAPI components

**Parameters:**
- `spec` (string): OpenAPI spec path

**Commands:**
- `node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}},required:['title','status','code']}};console.log(JSON.stringify(s,null,2))"`
- `swagger-cli validate openapi.yaml`
- `redocly lint openapi.yaml`
- `npx @stoplight/spectral-cli lint openapi.yaml`
- `node -e "const s={Problem:{type:'object'}};console.log(Object.keys(s)[0]) "`

**Examples:**
- node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}}}};console.log(JSON.stringify(s,null,2))"
- swagger-cli validate openapi.yaml && redocly lint openapi.yaml
- npx @stoplight/spectral-cli lint --ruleset error-rules.yaml openapi.yaml

## References
- [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)
- [OpenAPI Components](https://spec.openapis.org/oas/v3.1.0#components-object)

