FastAPI基础设施

FastAPI基础设施 is a skill for Claude Code, Codex from nongjun/awesome-harness-engineering. It costs 49 tokens per session (510 once invoked), scanned A, a copy of fastapi-common, MIT.

A shared set of FastAPI backend components for cross-origin access, error handling, request logging, and consistent API responses. FastAPI is a Python framework for building web APIs.

In plain words
What is it for?
Use it when creating FastAPI modules, configuring CORS, handling exceptions, logging slow requests, returning standard responses, or paginating database queries.
Why use it?
It prevents each backend module from inventing its own middleware, error format, logging behavior, or pagination structure.

Skill for Claude CodeCodex

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/nongjun/awesome-harness-engineering/fastapi
Any agent
npx skills add nongjun/awesome-harness-engineering --skill fastapi
Clone the repo
git clone --depth 1 https://github.com/nongjun/awesome-harness-engineering

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基础设施

README.md
[![agentmods](https://agentmods.dev/badge/skills/nongjun/awesome-harness-engineering/fastapi.svg)](https://agentmods.dev/skills/nongjun/awesome-harness-engineering/fastapi)
Your own site
<a href="https://agentmods.dev/skills/nongjun/awesome-harness-engineering/fastapi"><img src="https://agentmods.dev/badge/skills/nongjun/awesome-harness-engineering/fastapi.svg" alt="Measured on agentmods" height="20"></a>
Per session 49 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 510 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 97% copy Near-identical to another mod 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.00049 $0.00510
Opus 5 $0.00024 $0.00255
Sonnet 5 $0.00010 $0.00102
Haiku 4.5 $0.00005 $0.00051

Measured 3d ago against content hash 89db376b29df, 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 3d 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.

Origin

This is a copy

97% identical to fastapi-common — 2 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

项目模板/瑞小美AiOS/skills/FastAPI基础设施/SKILL.md · 53 lines

What it actually says

FastAPI 公共基础设施

模块一览

模块 导入路径 功能
CORS shared_backend.middleware.cors 跨域配置(开发/生产自动切换)
异常处理 shared_backend.middleware.exception_handler 统一错误格式
请求日志 shared_backend.middleware.request_logging 耗时记录、慢请求告警
响应格式 shared_backend.middleware.response 标准化 API 返回

统一响应格式

  • 成功:{ code: 0, message: "success", data: ... }
  • 错误:{ code: 错误码, message: "描述", data: null }
  • 分页:{ code: 0, data: { list: [...], total, page, page_size } }

所有异常统一返回 HTTP 200,通过 code 字段区分错误类型。

关键函数

函数 用途
setup_cors(app, app_env) 配置 CORS(开发允许所有,生产限域名)
setup_exception_handlers(app) 注册全局异常处理
RequestLoggingMiddleware 请求日志中间件(慢请求阈值 3s)
success_response() 包装成功响应
error_response() 包装错误响应
paginated_response() 包装分页响应
paginate_query() SQLAlchemy 查询分页
APIException 自定义业务异常
NotFoundException 404 异常

SOP:新建后端模块

  1. 创建 FastAPI 应用
  2. 调用 setup_cors()、setup_exception_handlers()
  3. 添加 RequestLoggingMiddleware
  4. 路由中使用 success_response() / paginated_response() 返回数据
  5. 业务异常抛出 APIException

参考文件

  • 公共模块/shared_backend/middleware/cors.py
  • 公共模块/shared_backend/middleware/exception_handler.py
  • 公共模块/shared_backend/middleware/request_logging.py
  • 公共模块/shared_backend/middleware/response.py
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. 3d ago First seen · 53 lines · 49 tokens per session scan A 89db376b29df

Subscribe to this mod's changes

FastAPI基础设施 is a skill published in the GitHub repository nongjun/awesome-harness-engineering (2 stars, last pushed 5mo ago), licensed MIT. It adds 49 tokens to every session and 510 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. It is 97% identical to fastapi-common, differing in 2 lines, and is treated as a copy.

Related

Other skills, from other repositories

bump-dependency

Bumps a Python package dependency across Home Assistant Core integrations, regenerates core requirement files, runs verification tests and prek lint, and prepares a pull request with proper release/compare links.

home-assistant/core · 42 tokens

mem0-vercel-ai-sdk

Mem0 provider for Vercel AI SDK (@mem0/vercel-ai-provider). TRIGGER when: user mentions "vercel ai sdk", "@mem0/vercel-ai-provider", "createMem0", "retrieveMemories", "addMemories", "getMemories", "searchMemories", "mem0 vercel", "AI SDK provider", "AI SDK memory", or is using generateText/streamText with mem0. Also…

mem0ai/mem0 · 146 tokens

schema-exploration

Lists tables, describes columns and data types, identifies foreign key relationships, and maps entity relationships in a database. Use when the user asks about database schema, table structure, column types, what tables exist, ERD, foreign keys, or how entities relate.

langchain-ai/deepagents · 57 tokens

deepagents-thread-inspector

Inspect and explain conversations in the local Deep Agents Code SQLite session store. Use as a fallback when LangSmith trace tooling is unavailable, for offline or untraced sessions, or when asked to identify or summarize a local dcode thread, inspect checkpoint metadata, list recent local threads, or parse…

langchain-ai/deepagents · 82 tokens

agent-framework-azure-ai-py

Build persistent agents on Azure AI Foundry using the Microsoft Agent Framework Python SDK.

sickn33/agentic-awesome-skills · 24 tokens

pause

Pause Mem0 memory capture on this machine. Use when the user wants to stop memories being recorded, for example for private work or experiments.

mem0ai/mem0 · 30 tokens