api-patterns

A set of patterns for building server-side API routes, including access control, input checking, webhooks, and error handling. RLS (row-level security) limits which database records each request can access.

In plain words
What is it for?
Use it when creating CRUD endpoints, validating requests and responses, processing webhooks, delivering protected content, or handling API errors. It is not intended for frontend-only changes or database migrations without API work.
Why use it?
It helps avoid unsafe routes that skip access checks or accept invalid data. It also provides established approaches for common API work instead of requiring each route to be designed from scratch.

Skill for Claude CodeCodex

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/bybren-llc/safe-agentic-workflow/api-patterns
Any agent
npx skills add bybren-llc/safe-agentic-workflow --skill api-patterns
Clone the repo
git clone --depth 1 https://github.com/bybren-llc/safe-agentic-workflow

Made for: Claude Code, Codex.

Per session 57 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,427 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 $0.00057 $0.01427
Opus 5 $0.00028 $0.00714
Sonnet 5 $0.00011 $0.00285
Haiku 4.5 $0.00006 $0.00143

Measured 3d ago against content hash 74ddedb0e337, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-patterns 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 3d 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.

.agents/skills/api-patterns/SKILL.md · 216 lines

How it starts

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

API Patterns Skill

TEMPLATE: This skill uses {{PLACEHOLDER}} tokens. Replace with your project values before use.

Purpose

Route to existing API patterns and provide checklists for safe, validated API route implementation. All API routes MUST use RLS context helpers -- see rls-patterns skill.

When This Skill Applies

  • Creating new API routes
  • Implementing CRUD endpoints
  • Adding request/response validation
  • Handling webhooks
  • Implementing error handling patterns

Authoritative References (MUST READ)

Pattern Location Purpose
User Context API patterns_library/api/user-context-api.md User-scoped operations
Admin Context API patterns_library/api/admin-context-api.md Admin-scoped operations
Zod Validation patterns_library/api/zod-validation-api.md Request/response validation
Webhook Handler patterns_library/api/webhook-handler.md Webhook processing
Bonus Content patterns_library/api/bonus-content-delivery.md Protected content delivery

Stop-the-Line Conditions

FORBIDDEN Patterns

// FORBIDDEN: Direct ORM/DB calls (bypass RLS)
const users = await db.user.findMany();
// Must use: withUserContext, withAdminContext, or withSystemContext

// FORBIDDEN: Missing authentication check
export async function GET(req: Request) {
  return getUserData(); // No auth check!
}

// FORBIDDEN: Unvalidated user input
const { userId } = await req.json();
// Must validate with schema validation (Zod, Pydantic, etc.)

// FORBIDDEN: Generic error responses
return new Response("Error", { status: 500 });
// Must use structured error response

CORRECT Patterns

// CORRECT: RLS context + auth check
export async function GET(req: Request) {
  const { userId } = await auth();
  if (!userId) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  const data = await withUserContext(db, userId, async (client) => {
    return client.user.findUnique({ where: { user_id: userId } });
  });

  return NextResponse.json(data);
}

// CORRECT: Schema validation
const schema = z.object({
  email: z.string().email(),
  name: z.string().min(1),
});

const result = schema.safeParse(body);
if (!result.success) {
  return NextResponse.json(
    { error: "Validation failed", details: result.error.flatten() },
    { status: 400 },
  );
}

Read the full file on GitHub · 216 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 3d ago First seen · 216 lines · 57 tokens per session scan A 74ddedb0e337

Subscribe to this mod's changes

api-patterns is a skill published in the GitHub repository bybren-llc/safe-agentic-workflow (404 stars, last pushed 1mo ago), licensed MIT. It adds 57 tokens to every session and 1,427 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-30.

Related

Other skills, from other repositories

bug-triage

Read all open bugs in production/qa/bugs/, re-evaluate priority vs. severity, assign to sprints, surface systemic trends, and produce a triage report. Run at sprint start or when the bug count grows enough to need re-prioritization.

Donchitos/Claude-Code-Game-Studios · 59 tokens

bug-report

Creates a structured bug report from a description, or analyzes code to identify potential bugs. Ensures every bug report has full reproduction steps, severity assessment, and context.

Donchitos/Claude-Code-Game-Studios · 36 tokens

audit-onboarding-proposal

Independently audit a brownfield onboarding transcript, operational map, or exact proposed documentation patch before application. Use when a fresh reviewer must verify an $onboard-repository first pass, distinguish environment-caused Unknowns from reasoning defects, score its safety and evidence gates, or run a…

hoangnb24/repository-harness · 104 tokens

improve-harness

Run one explicitly authorized, evidence-backed improvement to a repository's agent guidance, tools, runbooks, or validation. Use only when the user invokes $improve-harness or explicitly asks to improve the Harness after observed reusable agent friction. Do not use for ordinary product changes, speculative cleanup…

hoangnb24/repository-harness · 76 tokens

checkup-simplify

Use this skill when the user asks for conservative cleanup of already changed source files, similar to Claude Code /simplify, but the active agent may be Cursor, Codex, Gemini, or OpenCode.

promptdriven/pdd · 0 tokens

red-green-refactor

Guides the red-green-refactor TDD workflow: write a failing test first, implement the minimum code to make it pass, then refactor while keeping tests green. Use when a user asks to practice TDD, write tests first, follow red-green-refactor, do test-driven development, write failing tests before code, or phrases like…

rohitg00/skillkit · 90 tokens