fastapi-best-practices

fastapi-best-practices is a skill for Claude Code from dkmqflx/fastapi-best-practices-plugin. It costs 97 tokens per session (1,503 once invoked), scanned A, original, MIT.

A set of coding guidelines for FastAPI, a Python framework for building web APIs. It covers common choices for routes, request data, validation, dependencies, errors, and application structure.

In plain words
What is it for?
Writing, reviewing, or refactoring FastAPI endpoints, routers, Pydantic models, dependency injection, middleware, streaming, background tasks, settings, and CORS.
Why use it?
It helps prevent common mistakes when an API accepts data, returns responses, handles failures, or runs asynchronous work.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the fastapi-best-practices plugin — 3 skills 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/dkmqflx/fastapi-best-practices-plugin/fastapi-best-practices
Any agent
npx skills add dkmqflx/fastapi-best-practices-plugin --skill fastapi-best-practices
Clone the repo
git clone --depth 1 https://github.com/dkmqflx/fastapi-best-practices-plugin

Made for: Claude Code.

Or install fastapi-best-practices, the plugin that ships this one along with the rest of its 3 skills.

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/dkmqflx/fastapi-best-practices-plugin/fastapi-best-practices.svg)](https://agentmods.dev/skills/dkmqflx/fastapi-best-practices-plugin/fastapi-best-practices)
Your own site
<a href="https://agentmods.dev/skills/dkmqflx/fastapi-best-practices-plugin/fastapi-best-practices"><img src="https://agentmods.dev/badge/skills/dkmqflx/fastapi-best-practices-plugin/fastapi-best-practices.svg" alt="Measured on agentmods" height="20"></a>
Per session 97 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,503 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.00097 $0.01503
Opus 5 $0.00048 $0.00751
Sonnet 5 $0.00019 $0.00301
Haiku 4.5 $0.00010 $0.00150

Measured 5d ago against content hash 5059fd77644a, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, 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 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.

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.

plugins/fastapi-best-practices/skills/fastapi-best-practices/SKILL.md · 132 lines

How it starts

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

FastAPI Best Practices

Reference guide for writing FastAPI code that follows the official documentation (https://fastapi.tiangolo.com/). 33 rules across 11 categories, prioritized by impact — correctness first, structure/validation next, performance and polish last. Each rule pairs an incorrect example with the official correct pattern and links the relevant docs page.

Security/authentication and testing are covered by two companion skills — fastapi-security and fastapi-testing — since they tend to live in their own files (auth modules, test suites) rather than alongside routing/model code.

When to Apply

Reference these guidelines when:

  • Writing new FastAPI endpoints, routers, parameters, or Pydantic models
  • Designing dependency injection or error handling
  • Adding streaming, background tasks, settings/config, or middleware
  • Reviewing or refactoring a FastAPI backend

Rule Categories by Priority

Priority Category Impact Prefix
1 Request/Response Models CRITICAL model-
2 Request Parameters & Validation HIGH params-
3 App Structure & Routing HIGH structure-
4 Dependency Injection HIGH di-
5 Error Handling HIGH error-
6 Async & Concurrency MEDIUM async-
7 Responses & Streaming MEDIUM response-
8 Background Tasks & Config MEDIUM background-, config-
9 Lifespan & Resources MEDIUM lifespan-
10 Middleware & Cross-cutting MEDIUM mw-
11 OpenAPI Documentation LOW docs-

Quick Reference

1. Request/Response Models (CRITICAL)

  • model-response-model — declare a response model on every endpoint
  • model-separate-input-output — separate input vs output models so secrets never leak
  • model-return-type-annotation — prefer the return-type annotation; use response_model= only when types differ
  • model-pydantic-validation — validate with Pydantic Field/Literal, not manual if checks
  • model-exclude-unsetresponse_model_exclude_unset for partial/sparse data

Read the full file on GitHub · 132 lines

Files

What ships with it

33 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. 5d ago First seen · 132 lines · 97 tokens per session scan A 5059fd77644a

Subscribe to this mod's changes

fastapi-best-practices is a skill published in the GitHub repository dkmqflx/fastapi-best-practices-plugin (1 stars, last pushed 2mo ago), licensed MIT. It adds 97 tokens to every session and 1,503 once invoked, about $0.0005 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.

Related

Other skills, from other repositories

Cursor rules for FastAPI services with router/service/repository boundaries, typ

Cursor rules for FastAPI services with router/service/repository boundaries, typed provider adapters, bulkhead isolation, idempotency, and domain exceptions.

AmariahAK/atlarix-skills · 14 tokens

FastAPI best practices and patterns for building modern Python web APIs

Skill "FastAPI best practices and patterns for building modern Python web APIs" from AmariahAK/atlarix-skills, covering when to use this skill, source, fastapi best practices, project structure and api design.

AmariahAK/atlarix-skills · 12 tokens

FastAPI Patterns

Use this skill when building Python APIs with FastAPI and you want consistent boundary validation, async correctness, and maintainable dependency injection patterns.

AmariahAK/atlarix-skills · 3 tokens

datamodel-code-generator

Use this skill when the user wants Python data models, Pydantic models, dataclasses, TypedDicts, msgspec structs, or type-safe Python classes generated from OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON/YAML/CSV sample data, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro, or existing Python model objects.…

koxudaxi/datamodel-code-generator · 147 tokens

api-contrib

Contributing to the Kokoro-FastAPI Python API: module layout, endpoint gating pattern, test expectations. Use when adding or changing endpoints, services, or inference code.

remsky/Kokoro-FastAPI · 39 tokens

fastapi

FastAPI best practices and conventions. Use when working with FastAPI APIs and Pydantic models for them. Keeps FastAPI code clean and up to date with the latest features and patterns, updated with new versions. Write new code or refactor and update old code.

ReflexioAI/claude-smart · 57 tokens