fastapi

Guides writing FastAPI APIs with Pydantic models, dependencies, and streaming responses.

4|Updated Mar 28, 2026
One-click install
npx skills add https://github.com/minexo79/coser-card-maker --skill fastapi-minexo79
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi
Source: https://github.com/minexo79/coser-card-maker/tree/main/.kilo/skills/fastapi
Command: npx skills add https://github.com/minexo79/coser-card-maker --skill fastapi-minexo79

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? FastAPI codebases often drift into outdated or discouraged patterns such as ellipsis defaults, RootModel wrappers, mixed HTTP operations, and blocking code inside async handlers. This Skill provides current best practices and conventions so generated FastAPI code stays clean, typed, and performant. ## Core Features & Use Cases - Modern API Patterns: Enforces Annotated-based parameters and dependencies, router-level prefixes and tags, one HTTP operation per function, and return-type-driven response serialization. - Streaming Support: Covers Server-Sent Events with EventSourceResponse and ServerSentEvent, JSON Lines streaming, and byte streaming via StreamingResponse subclasses. - Frontend Serving & Tooling: Uses app.frontend() and router.frontend() to serve built SPA assets, and recommends uv, Ruff, ty, Asyncer, SQLModel, and HTTPX for the surrounding toolchain. - Use Case: When building a new FastAPI endpoint that streams progress events to a React frontend, the Skill directs you to yield ServerSentEvent objects from an endpoint declared with response_class=EventSourceResponse. ## Quick Start Ask the AI to create a FastAPI endpoint with Pydantic validation and dependency injection following current best practices.

Frequently Asked Questions about fastapi

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stream Server-Sent Events in FastAPI?

Declare the endpoint with response_class=EventSourceResponse and yield items from an async generator. Plain objects are JSON-serialized automatically, or yield ServerSentEvent instances for control over event, id, retry, and comment fields.

How do I serve a React or Vite frontend from FastAPI?

Use app.frontend("/", directory="dist") to serve built static assets, or router.frontend() when the frontend belongs to an APIRouter. These are low-priority routes, so API routes match first and client-side routing fallbacks work for single-page apps.

Should I use async def or def for FastAPI path operations?

Use async def only when the called logic is fully async-compatible and non-blocking. Otherwise use regular def, which runs in a threadpool and avoids blocking the event loop. Blocking code inside async functions severely damages performance.

Why should I avoid Pydantic RootModel in FastAPI?

FastAPI creates a Pydantic TypeAdapter for plain type annotations like Annotated[list[int], Field(min_length=1)], so wrapper RootModel classes are unnecessary. Regular annotations with Body() give the same validation with simpler code.

When should I use response_model instead of a return type?

Use response_model when the returned internal object differs from the public schema you want to expose. It validates, filters, and serializes the output, which is useful for hiding sensitive fields like secret keys from API responses.