fastapi

fastapi is a cursor rule for Cursor from steph-dove/klaussy-agents. It costs 0 tokens per session (1,175 once invoked), scanned A, original, MIT.

A set of coding rules for FastAPI, a Python framework for building web APIs. The rules cover API versioning, data models, streamed events, and background tasks.

In plain words
What is it for?
It guides URL-based API versions, Pydantic models for API data, dataclasses for internal objects, server-sent events, and background jobs.
Why use it?
It reduces inconsistent design decisions when an agent adds or changes FastAPI endpoints and supporting code.

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/steph-dove/klaussy-agents/fastapi
Clone the repo
git clone --depth 1 https://github.com/steph-dove/klaussy-agents

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 fastapi

README.md
[![agentmods](https://agentmods.dev/badge/rules/steph-dove/klaussy-agents/fastapi.svg)](https://agentmods.dev/rules/steph-dove/klaussy-agents/fastapi)
Your own site
<a href="https://agentmods.dev/rules/steph-dove/klaussy-agents/fastapi"><img src="https://agentmods.dev/badge/rules/steph-dove/klaussy-agents/fastapi.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,175 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 $0.00000 $0.01175
Opus 5 $0.00000 $0.00588
Sonnet 5 $0.00000 $0.00235
Haiku 4.5 $0.00000 $0.00118

Measured 5d ago against content hash 46a2320a42c4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

fastapi 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.

examples/fastapi/.cursor/rules/fastapi.mdc · 122 lines

How it starts

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

Conventions

  • URL-based API versioning: Use URL path versioning (e.g., /v1/, /api/v2/). Example context from fastapi/applications.py (lines 214-220):
                    ```python
                    from fastapi import FastAPI
    
                    app = FastAPI(openapi_url="/api/v1/openapi.json")
                    ```
                    """
                ),
    
  • Data class style: Pydantic for API + dataclasses for internal: Use Pydantic for API schemas (40) and dataclasses for internal DTOs (10). Good separation. Example context from fastapi/sse.py (lines 47-57):
        if v is not None and "\0" in v:
            raise ValueError("SSE 'id' must not contain null characters")
        return _check_single_line(v, "id")
    
    
    class ServerSentEvent(BaseModel):
        """Represents a single Server-Sent Event.
    
        When `yield`ed from a *path operation function* that uses
        `response_class=EventSourceResponse`, each `ServerSentEvent` is encoded
        into the [SSE wire format](https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream)
    
  • Background jobs with FastAPI BackgroundTasks: Use FastAPI BackgroundTasks for background task processing. Example context from fastapi/background.py (lines 1-10):
    from collections.abc import Callable
    from typing import Annotated, Any
    
    from annotated_doc import Doc
    from starlette.background import BackgroundTasks as StarletteBackgroundTasks
    from typing_extensions import ParamSpec
    
    P = ParamSpec("P")
    
    
  • Data classes: Pydantic models: Use Pydantic models for structured data. 62/80 structured classes use this pattern. Example context from fastapi/sse.py (lines 47-57):
        if v is not None and "\0" in v:
            raise ValueError("SSE 'id' must not contain null characters")
        return _check_single_line(v, "id")
    
    
    class ServerSentEvent(BaseModel):
        """Represents a single Server-Sent Event.
    
        When `yield`ed from a *path operation function* that uses
        `response_class=EventSourceResponse`, each `ServerSentEvent` is encoded
        into the [SSE wire format](https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream)
    
  • lowercase constant naming: Name constants using lowercase style. Example context from fastapi/params.py (lines 18-22):
    
    class ParamTypes(Enum):
        query = "query"
        header = "header"
        path = "path"
    
  • Enum usage: Enum: Use Python enums for categorical values. Found 4 enum class(es). Example context from fastapi/params.py (lines 14-24):
        Undefined,
    )
    from .datastructures import _Unset
    
    
    class ParamTypes(Enum):
        query = "query"
        header = "header"
        path = "path"
        cookie = "cookie"
    
  • Custom decorator pattern: @deprecated: Use custom decorator @deprecated (4 usages). Also uses: @asynccontextmanager. Example context from fastapi/responses.py (lines 34-44):
        orjson = cast(_OrjsonModule, importlib.import_module("orjson"))
    except ModuleNotFoundError:  # pragma: nocover
        orjson = None  # type: ignore[assignment]
    
    
    @deprecated(
        "UJSONResponse is deprecated, FastAPI now serializes data directly to JSON "
        "bytes via Pydantic when a return type or response model is set, which is "
        "faster and doesn't need a custom response class. Read more in the FastAPI "
        "docs: https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model "
        "and https://fastapi.tiangolo.com/tutorial/response-model/",
    
  • Limited exception chaining: Preserve exception context: use raise X from Y or raise X from None. Example context from fastapi/encoders.py (lines 350-356):
                data = vars(obj)
            except Exception as e:
                errors.append(e)
                raise ValueError(errors) from e
        return jsonable_encoder(
            data,
            include=include,
    
  • Mixed validation approaches: Validate inputs and parameters: Use multiple validation approaches: Pydantic validation, Manual validation (ValueError/TypeError), Decorator-based validation.. Example context from fastapi/encoders.py (lines 21-27):
    from annotated_doc import Doc
    from fastapi.exceptions import PydanticV1NotSupportedError
    from fastapi.types import IncEx
    from pydantic import BaseModel
    from pydantic.networks import AnyUrl, NameEmail
    from pydantic.types import SecretBytes, SecretStr
    from pydantic_core import PydanticUndefinedType
    

Read the full file on GitHub · 122 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 · 122 lines · 0 tokens per session scan A 46a2320a42c4

Subscribe to this mod's changes

fastapi is a cursor rule published in the GitHub repository steph-dove/klaussy-agents (16 stars, last pushed 8d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,175 tokens. 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-30.