fastapi-ai-chat-module-skill

fastapi-ai-chat-module-skill is a skill for Claude Code, Codex from jiushiwon/wg-skills. It costs 179 tokens per session (7,083 once invoked), scanned A, original, Apache-2.0.

A Python module for adding AI chat to an existing FastAPI application. FastAPI is a Python framework for building web services, and this module covers conversations, saved context, streaming replies, usage tracking, limits, and several model providers.

In plain words
What is it for?
Use it to add AI conversations, session management, message handling, remembered context, Server-Sent Events streaming, token limits, and support for OpenAI, Claude, or local models.
Why use it?
It gives an existing FastAPI project a defined way to store conversations and messages, restore context, stream responses, and track token use. This avoids designing those chat functions from scratch.

Skill for Claude CodeCodex

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

Good fit Use it to add AI conversations, session management, message handling, remembered context, Server-Sent Events streaming, token limits, and support for OpenAI, Claude, or local models.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jiushiwon/wg-skills/fastapi-ai-chat-module-skill
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 jiushiwon/wg-skills --skill fastapi-ai-chat-module-skill
Clone the repo
git clone --depth 1 https://github.com/jiushiwon/wg-skills

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-ai-chat-module-skill

README.md
[![agentmods](https://agentmods.dev/badge/skills/jiushiwon/wg-skills/fastapi-ai-chat-module-skill/github.svg)](https://agentmods.dev/skills/jiushiwon/wg-skills/fastapi-ai-chat-module-skill)
Your own site
<a href="https://agentmods.dev/skills/jiushiwon/wg-skills/fastapi-ai-chat-module-skill"><img src="https://agentmods.dev/badge/skills/jiushiwon/wg-skills/fastapi-ai-chat-module-skill/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-ai-chat-module-skill

Your own site · 80×15
<a href="https://agentmods.dev/skills/jiushiwon/wg-skills/fastapi-ai-chat-module-skill"><img src="https://agentmods.dev/badge/skills/jiushiwon/wg-skills/fastapi-ai-chat-module-skill.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 179 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 7,083 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. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to medium

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • medium Data Exfiltration · line 41
    Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
    Fix: Verify the destination URL is trusted and necessary. Remove or replace with documented APIs. Ensure no secrets, tokens, or PII are transmitted.
How audits are shown
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.00179 $0.07083
Opus 5.5 $0.00072 $0.02833
Sonnet 5.5 $0.00036 $0.01417
Haiku 4.5 $0.00018 $0.00708

Measured 1mo ago against content hash 319e01032433, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

fastapi-ai-chat-module-skill 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 1mo 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.

backend/python/fastapi-module/fastapi-ai-chat-module-skill/SKILL.md · 916 lines

How it starts

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

FastAPI AI Chat Module Skill

面向已有 FastAPI 项目的开发者,快速集成 AI 对话 Agent 能力。

版本对标:本模块对齐 Spring Boot 版 springboot-agent-module-skill 的能力矩阵(Function Calling、Tool、限流、审计等),确保两套体系的 AI 能力对齐。

骨架依赖

本模块依赖 fastapi-init-skill 骨架 + fastapi-auth-module-skill 鉴权模块。

使用前必须满足:

  1. ✅ 已安装 fastapi-init-skill(项目骨架)
  2. ✅ 已安装 fastapi-auth-module-skill(用户鉴权)

对接规范:

  1. ✅ 使用骨架的 ApiResponse 统一响应
  2. ✅ 使用骨架的 BusinessException 异常处理(负数错误码 -1001 ~ -2000)
  3. ✅ 使用骨架的 get_current_user() 获取当前用户
  4. ✅ 使用骨架的数据库配置(SQLAlchemy + Alembic)
  5. ✅ 使用骨架的 Redis 配置(如有,用于限流/缓存)
  6. ✅ 使用骨架的 restart.sh 部署脚本

核心能力清单

# 能力 说明
1 Function Calling 基于 OpenAI/Claude SDK,AI 可调用外部 Tool
2 Tool 系统 声明式 Tool 定义,自动参数校验,权限注入
3 多模型接入 统一 ChatModel 接口,支持 OpenAI/Claude/DeepSeek/Ollama
4 多轮对话 上下文记忆,会话级别历史,LRU 自动裁剪
5 对话管理 创建/查询/删除/清除会话(软删除 + 级联硬删除)
6 租户隔离 所有 Tool 按 tenant_id 过滤,多租户安全
7 流式输出 SSE 流式返回 token,含断连检测
8 Rate Limiting Redis 实现,每用户 10 次/分钟(防 LLM 财务风险)
9 审计日志 独立 logger,记录 tool_call/tool_failure/chat_failure/token_usage/rate_limit
10 上下文记忆 Deque 自动裁剪 + LRU 内存缓冲
11 Token 统计 消耗统计与限额控制
12 PII 加密 Fernet 对称加密,日志自动脱敏
13 trace_id 追踪 MDC 注入 trace_id,跨服务追踪支持
14 模型白名单 客户端无法指定白名单外模型(防财务风险)

用户问题(最多 3 个)

1. 用什么模型?(默认 gpt-4o-mini,可选 Claude/DeepSeek/Ollama)
2. 需要哪些内置 Tool?(默认:查用户信息、查角色、查菜单)
3. 是否开启历史消息?(默认开启,保留 20 轮)

依赖配置

# 核心依赖
pip install openai anthropic httpx sse-starlette

# 可选:Ollama 本地模型
pip install ollama

# 限流
pip install redis龟

# 加密
pip install cryptography

# 重试
pip install tenacity

# 工具
pip install pydantic pydantic-settings

配置

# config.py
from pydantic_settings import BaseSettings
from typing import Optional

class Settings(BaseSettings):
    # ====== AI 模型配置 ======
    ai_provider: str = "openai"  # openai / claude / deepseek / ollama

    # OpenAI
    openai_api_key: str = ""
    openai_base_url: str = "https://api.openai.com/v1"
    openai_model: str = "gpt-4o-mini"

    # Claude
    anthropic_api_key: str = ""
    anthropic_model: str = "claude-3-haiku-20240307"

    # DeepSeek
    deepseek_api_key: str = ""
    deepseek_base_url: str = "https://api.deepseek.com/v1"
    deepseek_model: str = "deepseek-chat"

    # Ollama
    ollama_base_url: str = "http://localhost:11434"
    ollama_model: str = "llama3"

    # ====== 会话配置 ======
    chat_max_history: int = 20  # 保留轮数
    chat_max_tokens: int = 4000

    # ====== 限流配置 ======
    rate_limit_enabled: bool = True
    rate_limit_requests: int = 10  # 每分钟
    rate_limit_window: int = 60   # 秒

    # ====== 安全配置 ======
    pii_encryption_key: str = ""  # Fernet key
    enable_audit: bool = True

    # ====== Tool 白名单 ======
    allowed_tools: list[str] = [
        "get_user_info", "get_user_roles", "get_user_menus",
        "search_users", "get_org_tree"
    ]

    class Config:
        env_file = ".env"

settings = Settings()

Read the full file on GitHub · 916 lines

Files

What ships with it

1 file 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. 1mo ago Changed · +716 lines · +73 tokens per session 319e01032433
  2. 3mo ago First seen · 200 lines · 106 tokens per session scan A cc28afba0e45

Subscribe to this mod's changes

fastapi-ai-chat-module-skill is a skill published in the GitHub repository jiushiwon/wg-skills (154 stars, last pushed 6d ago), licensed Apache-2.0. It adds 179 tokens to every session and 7,083 once invoked, about $0.0007 per session on Opus 5.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-30.

Related

fastapi-ai-chat-module-skill compared with skills from other repositories

fastapi-ai-chat-module-skill next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
fastapi-ai-chat-module-skilljiushiwon/wg-skillsSkill1546d agoApache-2.0A179Claude Code, Codex
open-sourcebrowser-use/browser-useSkill122ktodayMITA101Claude Code
gemini-api-agent-platformdavila7/claude-code-templatesSkill35ktodayMITA61Claude Code, Codex
prowler-mcpprowler-cloud/prowlerSkill15ktodayApache-2.0A67Claude Code
deepstream-sopNVIDIA/skillsSkill4.2ktodayApache-2.0A219Claude Code
tao-run-inference-serviceNVIDIA/skillsSkill4.2ktodayApache-2.0A92Claude Code
gemini-api-devgoogle-gemini/gemini-skillsSkill5.0k11d agoApache-2.0A96Claude Code