api-contract-first

api-contract-first is a skill for Claude Code from dhslegen/digital-delivery-team. It costs 62 tokens per session (1,208 once invoked), scanned A, original, MIT.

A set of rules for designing and changing OpenAPI 3.0 interface contracts. These contracts describe how a frontend and backend communicate, including URLs, fields, errors, and status codes.

In plain words
What is it for?
It helps design, review, and evolve web API contracts while frontend and backend work in parallel. It covers resource URLs, required fields, error responses, pagination, dates, idempotency headers, and HTTP status codes.
Why use it?
It gives both sides one shared reference before coding begins, reducing mismatched requests and responses. It also records why interface changes were made and how they affect compatibility.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: mentions subagents.

Part of the digital-delivery-team plugin — 13 skills, 21 commands, 9 agents, 8 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/dhslegen/digital-delivery-team/api-contract-first
Any agent
npx skills add dhslegen/digital-delivery-team --skill api-contract-first
Clone the repo
git clone --depth 1 https://github.com/dhslegen/digital-delivery-team

Made for: Claude Code.

Or install digital-delivery-team, the plugin that ships this one along with the rest of its 13 skills, 21 commands, 9 agents, 8 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for api-contract-first

README.md
[![agentmods](https://agentmods.dev/badge/skills/dhslegen/digital-delivery-team/api-contract-first.svg)](https://agentmods.dev/skills/dhslegen/digital-delivery-team/api-contract-first)
Your own site
<a href="https://agentmods.dev/skills/dhslegen/digital-delivery-team/api-contract-first"><img src="https://agentmods.dev/badge/skills/dhslegen/digital-delivery-team/api-contract-first.svg" alt="Measured on agentmods" height="20"></a>
Per session 62 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,208 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00062 $0.01208
Opus 5 $0.00031 $0.00604
Sonnet 5 $0.00012 $0.00242
Haiku 4.5 $0.00006 $0.00121

Measured 6d ago against content hash a2745c7c0b01, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

api-contract-first scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/api-contract-first/SKILL.md · 101 lines

How it starts

The opening of the file, as written. The whole thing — 101 lines — stays where its author put it; the contents beside it link to each section on GitHub.

API Contract First

Triggers

  • architect-agent 启动 / /design 命令(写契约)
  • /build-api / /build-web main thread 加载 backend-development / frontend-development skill 时只读链入(契约消费方,M6.4 起 main thread 直接执行而非 subagent)

Core Principles

  1. 契约先于代码:没有 lint 通过的 OpenAPI,不允许动 web/ 或 server/
  2. 契约是唯一真相源:UI 文案、错误提示、日志格式以外的所有接口约定必须出自契约
  3. 契约变更 = 事件:每次契约变更在 docs/arch.md 的 ADR 章节追加一条,说明原因、影响面、兼容策略

Design Rules

URL 结构(DDT 标准)

# 资源名:名词、复数、小写、kebab-case
GET    /api/v1/users
POST   /api/v1/users
GET    /api/v1/users/:id
PUT    /api/v1/users/:id
PATCH  /api/v1/users/:id
DELETE /api/v1/users/:id

# 子资源(所有权关系)
GET    /api/v1/users/:id/orders

# 动作(谨慎使用,限非 CRUD)
POST   /api/v1/orders/:id/cancel

字段约束

  • 所有字段含 type / required / description / example
  • 所有错误响应用枚举(error.code)+ 人类可读 message,避免只有数字码
  • 分页统一:page + pageSize + total,或游标 cursor + nextCursor 二选一,全局一致
  • 幂等操作必须声明 Idempotency-Key header
  • 所有时间字段 ISO-8601 UTC

HTTP 状态码(强制)

200 OK                    — GET/PUT/PATCH 有响应体
201 Created               — POST 成功(含 Location header)
204 No Content            — DELETE/PUT 无响应体
400 Bad Request           — 格式错误、缺少必填字段
401 Unauthorized          — 未认证
403 Forbidden             — 已认证但无权限
404 Not Found             — 资源不存在
409 Conflict              — 重复创建、状态冲突
422 Unprocessable Entity  — 语义非法(格式合法但业务无效)
429 Too Many Requests     — 限流(含 Retry-After header)
500 Internal Server Error — 不暴露内部细节

分页(二选一,全局保持一致)

  • Offset(小数据集 < 10K / 管理后台):?page=2&pageSize=20
  • Cursor(大数据集 / 无限滚动):?cursor=<opaque>&limit=20,响应含 nextCursor

版本化策略(ADR)

1. URL Path 版本(推荐):/api/v1/ → /api/v2/
2. 不破坏性变更不需要新版本:
   - 新增可选字段、新增端点、新增可选查询参数
3. 破坏性变更必须新版本:
   - 删改字段名/类型、改 URL 结构、改认证方式
4. 废弃策略:宣告(6 个月) → Sunset header → 410 Gone

Do

  • npx @redocly/cli lint 跑 schema lint,lint 必须通过后才能进入实现阶段
  • openapi-typescript 或等价工具生成前端 types
  • openapi-generator 或等价工具生成后端路由骨架
  • 每个 endpoint 含完整的 request / response / error 示例(见 templates/api-contract.template.yaml

Read the full file on GitHub · 101 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 101 lines · 62 tokens per session scan A a2745c7c0b01

Subscribe to this mod's changes

api-contract-first is a skill published in the GitHub repository dhslegen/digital-delivery-team (1 stars, last pushed 3mo ago), licensed MIT. It adds 62 tokens to every session and 1,208 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.