fastapi-best-practices

fastapi-best-practices is a skill for Claude Code, Codex from ApexIQ/skillsmith. It costs 32 tokens per session (515 once invoked), scanned A, original, MIT.

A set of standards for building Python web services with FastAPI, a framework for creating web APIs.

In plain words
What is it for?
Use it when creating or changing FastAPI services, including their routes, request and response data, database access, authentication, and error handling.
Why use it?
It gives developers consistent guidance for API structure, validation, errors, security, and tests.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when creating or changing FastAPI services, including their routes, request and response data, database access, authentication, and error handling.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/apexiq/skillsmith/fastapi_best_practices
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.

Any agent
npx skills add ApexIQ/skillsmith --skill fastapi_best_practices
Clone the repo
git clone --depth 1 https://github.com/ApexIQ/skillsmith

Made for: Claude Code, Codex.

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 fastapi-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/skills/apexiq/skillsmith/fastapi_best_practices/github.svg)](https://agentmods.dev/skills/apexiq/skillsmith/fastapi_best_practices)
Your own site
<a href="https://agentmods.dev/skills/apexiq/skillsmith/fastapi_best_practices"><img src="https://agentmods.dev/badge/skills/apexiq/skillsmith/fastapi_best_practices/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for fastapi-best-practices

Your own site · 80×15
<a href="https://agentmods.dev/skills/apexiq/skillsmith/fastapi_best_practices"><img src="https://agentmods.dev/badge/skills/apexiq/skillsmith/fastapi_best_practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 32 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 515 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.00032 $0.00515
Opus 5 $0.00016 $0.00258
Sonnet 5 $0.00006 $0.00103
Haiku 4.5 $0.00003 $0.00052

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

Security

Grade A, and why

fastapi-best-practices 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 9d 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.

.agent/skills/fastapi_best_practices/SKILL.md · 63 lines

What it actually says

⚡ FastAPI Best Practices

1. Project Structure

  • Modular Features: Organize code by feature/domain, not by type.
    • Each feature folder: router.py, service.py, models.py, tests/.
  • No Global State: Use Dependency Injection (Depends), not global variables.

2. API Design (RESTful URLs)

Pattern Example Why
✅ Resource-based GET /users/{id} Predictable, cacheable.
❌ Verb-based GET /get_user_by_id Unclear, non-standard.
  • Pydantic Models: Always use for Request/Response schemas.
    • CreateUserRequest (Input), UserResponse (Output).
    • Never return ORM/DB objects directly from endpoints.

3. Dependency Injection

from fastapi import Depends

def get_current_user(token: str = Depends(oauth2_scheme)): ...
def get_db(session: Session = Depends(get_session)): ...

@router.get("/items/{item_id}")
def get_item(item_id: int, user = Depends(get_current_user), db = Depends(get_db)):
    ...

4. Error Handling

  • Use HTTPException with specific status codes (400, 401, 403, 404, 500).
  • Log errors before raising the exception for traceability.

5. Security (Critical)

  • Ownership Verification: ALWAYS check if resource belongs to user.
    if item.owner_id != user.id:
        raise HTTPException(status_code=404, detail="Not found") # Use 404, not 403
    
  • Rate Limiting: Apply on public/sensitive endpoints.

Examples

  • New endpoint: Define Pydantic schema -> Add route -> Add ownership check -> Write test.

Guidelines

  • Keep endpoints thin. Business logic goes in service layer.
  • Every new endpoint MUST have a corresponding test.
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. 9d ago First seen · 63 lines · 32 tokens per session scan A f554df3a53e4

Subscribe to this mod's changes

fastapi-best-practices is a skill published in the GitHub repository ApexIQ/skillsmith (5 stars, last pushed 5mo ago), licensed MIT. It adds 32 tokens to every session and 515 once invoked, about $0.0002 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.