Agent skill

API Patterns

by bybren-llc in bybren-llc/safe-agentic-workflow

API route implementation patterns with RLS, Zod validation, and error handling.

MITAuto-check passedBackend & APIs

Install API Patterns

skills CLI
$ npx skills add bybren-llc/safe-agentic-workflow --skill api-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install bybren-llc/safe-agentic-workflow api-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/bybren-llc/safe-agentic-workflow.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/api-patterns .claude/skills/api-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
api-patterns
GitHub stars
421
Token cost
~1.6k tokens
SKILL.md length
201 words
Files
2
Skills in repo
42
Repo updated
First seen
Licence
MIT

At a glance

API route implementation patterns with RLS, Zod validation, and error handling.

  • Creating API routes
  • SKILL.md covers Purpose, When This Skill Applies, Authoritative References (MUST… and Stop-the-Line Conditions, plus 5 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Implementing endpoints

What it does

API Patterns is an agent skill from bybren-llc/safe-agentic-workflow. API route implementation patterns with RLS, Zod validation, and error handling. Use when creating API routes, implementing endpoints, or adding server-side validation.

Its SKILL.md is about 1.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 1 other file (for example `README.md`).

It sits in Backend & APIs, covering Forms and validation and Backend development. It works with Zod. The repository describes itself as: SAW — SAFe Agentic Workflow AI Agent Harness for Multi-Agent Team Workflows Built on SAFe methodology (Scaled Agile Framework), adapted for AI agent teams (Now With AI-DLC!)… The licence is MIT.

When your agent uses it

  • Creating API routes
  • Implementing endpoints
  • Adding server-side validation

Example prompts

  • “/api-patterns”

Requirements

  • Pre-approved tools (allowed-tools): Read, Grep, Glob

What it can do on your machine

Read from SKILL.md and the folder at commit 26ca58b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Grep
    • Glob

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript and markdown).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

API Patterns loads about 1.6k tokens when it runs. Until then it costs about 45 tokens; SKILL.md has 201 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~45
When it runs · the whole SKILL.md, loaded when a task matches
~1.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from bybren-llc/safe-agentic-workflow at commit 26ca58b, republished under its MIT licence (© bybren-llc). 201 words, ~1,556 tokens.

Download SKILL.mdSave it as .claude/skills/api-patterns/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
api-patterns
description
API route implementation patterns with RLS, Zod validation, and error handling. Use when creating API routes, implementing endpoints, or adding server-side validation.
allowed-tools
Read, Grep, Glob
user-invocable
false

API Patterns Skill

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

Invoke this skill when:

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

Authoritative References (MUST READ)

PatternLocationPurpose
User Context APIpatterns_library/api/user-context-api.mdUser-scoped operations
Admin Context APIpatterns_library/api/admin-context-api.mdAdmin-scoped operations
Zod Validationpatterns_library/api/zod-validation-api.mdRequest/response validation
Webhook Handlerpatterns_library/api/webhook-handler.mdWebhook processing
Bonus Contentpatterns_library/api/bonus-content-delivery.mdProtected content delivery

Stop-the-Line Conditions

FORBIDDEN Patterns
typescript
// FORBIDDEN: Direct Prisma calls (bypass RLS)
const users = await prisma.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 Zod schema

// FORBIDDEN: Generic error responses
return new Response("Error", { status: 500 });
// Must use structured error response
CORRECT Patterns
typescript
// 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(prisma, userId, async (client) => {
    return client.user.findUnique({ where: { user_id: userId } });
  });

  return NextResponse.json(data);
}

// CORRECT: Zod 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 },
  );
}

API Route Checklist

Before ANY API route:

  • Authentication check with await auth() from Clerk
  • Proper 401 response for unauthenticated
  • Request validation with Zod schema
  • RLS context wrapper (withUserContext/withAdminContext/withSystemContext)
  • Structured error responses with appropriate status codes
  • TypeScript types for request/response

Standard Response Patterns

Success Response
typescript
return NextResponse.json({ data, success: true }, { status: 200 });
Error Response
typescript
return NextResponse.json(
  {
    error: "Human-readable error message",
    code: "ERROR_CODE",
    details: optional_details,
  },
  { status: 400 | 401 | 403 | 404 | 500 },
);
Status Codes
CodeWhen to Use
200Success
201Created (POST)
400Bad request / validation error
401Not authenticated
403Forbidden (authenticated but not authorized)
404Resource not found
500Server error

API Route Template

typescript
import { auth } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
import { z } from "zod";
import { withUserContext } from "@/lib/rls-helpers";
import { prisma } from "@/lib/prisma";

// Request validation schema
const RequestSchema = z.object({
  // Define expected fields
});

export async function POST(req: Request) {
  try {
    // 1. Authenticate
    const { userId } = await auth();
    if (!userId) {
      return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
    }

    // 2. Parse and validate request
    const body = await req.json();
    const result = RequestSchema.safeParse(body);
    if (!result.success) {
      return NextResponse.json(
        { error: "Validation failed", details: result.error.flatten() },
        { status: 400 },
      );
    }

    // 3. Execute with RLS context
    const data = await withUserContext(prisma, userId, async (client) => {
      return client.resource.create({ data: result.data });
    });

    // 4. Return success response
    return NextResponse.json({ data, success: true }, { status: 201 });
  } catch (error) {
    console.error("API error:", error);
    return NextResponse.json(
      { error: "Internal server error" },
      { status: 500 },
    );
  }
}

API Documentation Template

For documenting new endpoints:

markdown
## Endpoint: POST /api/resource

### Description

Creates a new resource for the authenticated user.

### Authentication

Required: Clerk session

### Request Body

| Field | Type   | Required | Description   |
| ----- | ------ | -------- | ------------- |
| name  | string | Yes      | Resource name |
| type  | string | No       | Resource type |

### Response

**Success (201)**:
\`\`\`json
{ "data": { "id": 1, "name": "..." }, "success": true }
\`\`\`

**Error (400)**:
\`\`\`json
{ "error": "Validation failed", "details": {...} }
\`\`\`

### RLS Context

Uses `withUserContext` - user can only access own resources.
  • rls-patterns: RLS context helper usage (REQUIRED for all DB operations)
  • security-audit: API security validation
  • testing-patterns: API endpoint testing

© bybren-llc, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in .claude/skills/api-patterns of bybren-llc/safe-agentic-workflow.

  • SKILL.md
  • README.md

Open the folder on GitHubat commit 26ca58b

Compare with similar skills

API Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

API Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
API Patterns this skillbybren-llc/safe-agentic-workflow421—~1.6kAutomated safety check: PassMIT
Opinionated Nextjs Patternspproenca/dot-skills214—~3kAutomated safety check: PassMIT
Backend Dev Guidelineslitefuse/litefuse1001 repos~5.8kAutomated safety check: PassCustom licence
Typescript SecurityHoangNguyen0403/agent-skills-standard570—~817Automated safety check: NotesMIT
Nestjs Drizzle Crud Generatorgiuseppe-trisciuoglio/developer-kit355—~1.3kAutomated safety check: NotesMIT
Form Validationvibeeval/vibecosystem531—~3kAutomated safety check: PassMIT

Similar skills

  • Opinionated Nextjs Patterns

    pproenca/dot-skills

    Opinionated, backend-agnostic Next.js 16 (App Router) architecture — authorization at the data layer, server-side loading with cache()+Promise.all, mutations through next-safe-action + typed route…

    214 GitHub stars~3k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed
  • Backend Dev Guidelines

    litefuse/litefuse

    Comprehensive backend development guide for Litefuse's Next.js 14/tRPC/Express/TypeScript monorepo.

    100 GitHub starsUsed in 1 repo~5.8k tokens
    Backend & APIsAuto-check passed
  • Typescript Security

    HoangNguyen0403/agent-skills-standard

    Secure server-side TypeScript input, auth tokens, and injection boundaries.

    570 GitHub stars~817 tokensUpdated yesterday
    DevelopmentAuto-check: notes
  • Nestjs Drizzle Crud Generator

    giuseppe-trisciuoglio/developer-kit

    Generates complete CRUD modules for NestJS applications with Drizzle ORM.

    355 GitHub stars~1.3k tokensUpdated 27 days ago
    DatabasesAuto-check: notes
  • Form Validation

    vibeeval/vibecosystem

    React Hook Form + Zod integration, multi-step forms, optimistic validation, server-side error mapping, and file upload patterns.

    531 GitHub stars~3k tokensUpdated 2 mo ago
    Frontend & DesignAuto-check passed
  • Livewire Development

    coollabsio/coolify

    A skill your agent uses for any task or question involving Livewire.

    63k GitHub stars~964 tokensUpdated today
    Backend & APIsAuto-check passed

More from bybren-llc/safe-agentic-workflow

All 42 skills in this repo
  • Multi-Agent Coordination Template

    bybren-llc/safe-agentic-workflow

    Agent assignment matrix, blocker escalation, and TDM coordination patterns. Use when assigning work to specialist agents, managing blockers across agents…

    421 GitHub stars~1.2k tokensUpdated 2 mo ago
    Auto-check passed
  • API Route Patterns

    bybren-llc/safe-agentic-workflow

    API route implementation patterns with RLS, validation, and error handling. Use when creating API routes, implementing CRUD endpoints, adding server-side…

    421 GitHub stars~1.6k tokensUpdated 2 mo ago
    Auto-check passed
  • Technical Documentation Templates

    bybren-llc/safe-agentic-workflow

    Documentation templates for ADRs, runbooks, architecture docs, and knowledge transfer documents. Use when creating Architecture Decision Records, writing…

    421 GitHub stars~1.2k tokensUpdated 2 mo ago
    Auto-check passed
  • Deployment SOP Checklist

    bybren-llc/safe-agentic-workflow

    Deployment workflows, pre-deploy validation, smoke testing, and rollback procedures. Use when deploying to staging or production, running smoke tests…

    421 GitHub stars~950 tokensUpdated 2 mo ago
    Auto-check passed
  • Frontend Patterns Template

    bybren-llc/safe-agentic-workflow

    Frontend patterns for modern web frameworks, component libraries, auth flows, and analytics. Use when building UI components, creating pages, implementing…

    421 GitHub stars~2k tokensUpdated 2 mo ago
    Auto-check passed
  • Advanced Git Operations

    bybren-llc/safe-agentic-workflow

    Advanced git operations including rebase, bisect, cherry-pick, and conflict resolution. Use when rebasing feature branches, debugging with bisect…

    421 GitHub stars~1.6k tokensUpdated 2 mo ago
    Auto-check passed

Works with

Questions about API Patterns

What does API Patterns do?

API route implementation patterns with RLS, Zod validation, and error handling. API Patterns is an agent skill from bybren-llc/safe-agentic-workflow. API route implementation patterns with RLS, Zod validation, and error handling.

When should I use API Patterns?

API Patterns fits situations like: creating API routes; implementing endpoints; adding server-side validation.

How do I install API Patterns in Claude Code?

Run `npx skills add bybren-llc/safe-agentic-workflow --skill api-patterns -a claude-code`. Or copy the skill folder (.claude/skills/api-patterns in bybren-llc/safe-agentic-workflow) into .claude/skills/api-patterns in your project. Claude Code loads it when a task matches its description.

How do I install API Patterns in Codex?

Run `npx skills add bybren-llc/safe-agentic-workflow --skill api-patterns -a codex`. Or copy the skill folder (.claude/skills/api-patterns in bybren-llc/safe-agentic-workflow) into .agents/skills/api-patterns in your project. Codex loads it when a task matches its description.

Can I use API Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add bybren-llc/safe-agentic-workflow --skill api-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/api-patterns, .gemini/skills/api-patterns, .github/skills/api-patterns and .opencode/skills/api-patterns in your project.

What does API Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: API Patterns is instructions for the agent only. Its frontmatter pre-approves these tools: Read, Grep, Glob.

Does API Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is API Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does API Patterns use?

API Patterns is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does API Patterns use?

About 1.6k tokens (SKILL.md is roughly 6.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to API Patterns?

Skills that share tags, products or a category with API Patterns: Opinionated Nextjs Patterns (pproenca/dot-skills, 214 stars), Backend Dev Guidelines (litefuse/litefuse, 100 stars), Typescript Security (HoangNguyen0403/agent-skills-standard, 570 stars) and Nestjs Drizzle Crud Generator (giuseppe-trisciuoglio/developer-kit, 355 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains API Patterns?

bybren-llc (a GitHub organization) maintains it in bybren-llc/safe-agentic-workflow, which has 421 GitHub stars. The repository holds 42 skills in this directory. The repository was last updated on July 20, 2026.

Source: bybren-llc/safe-agentic-workflow on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.