api-patterns

api-patterns is a cursor rule for Cursor from brendadeeznuts1111/betting-brain-v3. It costs 2,671 tokens per session, scanned A, original, MIT.

Rules for designing API endpoints, the parts of a program that receive requests and return responses.

In plain words
What is it for?
Use them to find and implement endpoint handlers, JSON responses, error handling, request ID generation, and logging.
Why use it?
They give developers consistent patterns for responses, errors, request IDs, and logging across the API.

Cursor rule for Cursor

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 rules/brendadeeznuts1111/betting-brain-v3/api-patterns
Clone the repo
git clone --depth 1 https://github.com/brendadeeznuts1111/betting-brain-v3

Made for: Cursor.

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-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/api-patterns.svg)](https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/api-patterns)
Your own site
<a href="https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/api-patterns"><img src="https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/api-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 2,671 This file is loaded in full into every session.
When invoked 2,671 The same file — it is already loaded in full.
Security scan A 1 finding. 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.02671 $0.02671
Opus 5 $0.01336 $0.01336
Sonnet 5 $0.00534 $0.00534
Haiku 4.5 $0.00267 $0.00267

Measured 5d ago against content hash a4517dbadede, 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 1 finding 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 5d 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.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

# Test with curl
.cursor/rules/api-patterns.mdc · 476 lines

How it starts

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

🔍 Code Searchability Patterns

Find api-patterns Issues with ast-grep

# Find async function $NAME(request: Request, env: Env, requestId: string)
# Find return createJSONResponse($$$)
# Find return createErrorResponse($$$)
# Find generateRequestId()
# Find createLogger($$$)
ast-grep --pattern 'async function $NAME(request: Request, env: Env, requestId: string)' src/
ast-grep --pattern 'return createJSONResponse($$$)' src/
ast-grep --pattern 'return createErrorResponse($$$)' src/
ast-grep --pattern 'generateRequestId()' src/
ast-grep --pattern 'createLogger($$$)' src/
sg -p 'async' src/
sg -p 'return' src/
sg -p 'return' src/
sg -p 'generateRequestId()' src/
sg -p 'createLogger($$$)' src/

api-patterns Discovery Commands

sg search "async function" src/api/
sg search "createJSONResponse" src/
sg search "generateRequestId" src/
sg search "createLogger" src/

Search Examples

# Find all API endpoint handlers
sg search 'async' src/
# Find JSON response patterns
sg search 'return' src/
# Find request ID generation
sg search 'return' src/
# Find logging patterns
sg search 'generateRequestId()' src/

Error Handling Patterns

Using Error Classes

Location: src/utils/error-handler.ts

import { Errors, createErrorResponse } from '../utils/error-handler';

// In endpoint handler
try {
  // Validation error
  if (!isValid) {
    throw Errors.validationError(['Field is required']);
  }
  
  // Not found
  if (!record) {
    throw Errors.notFound('Event');
  }
  
  // Database error
  if (queryFailed) {
    throw Errors.databaseError('Query failed: ' + error.message);
  }
  
  // Success response
  return new Response(JSON.stringify(data), {
    headers: { 'Content-Type': 'application/json' }
  });
  
} catch (error) {
  return createErrorResponse(error, requestId, url.pathname);
}

Error Types

// Client errors (4xx)
Errors.badRequest(message, details?)       // 400
Errors.unauthorized(message?)              // 401
Errors.forbidden(message?)                 // 403
Errors.notFound(resource?)                 // 404
Errors.validationError(errors[])           // 400
Errors.rateLimit(message?)                 // 429

// Server errors (5xx)
Errors.databaseError(message)              // 500
Errors.serviceUnavailable(message?)        // 503
Errors.timeout(message?)                   // 504

Read the full file on GitHub · 476 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. 5d ago First seen · 476 lines · 2,671 tokens per session scan A a4517dbadede

Subscribe to this mod's changes

api-patterns is a cursor rule published in the GitHub repository brendadeeznuts1111/betting-brain-v3 (8 stars, last pushed 11mo ago), licensed MIT. It adds 2,671 tokens to every session, about $0.0134 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.