Files
meida_backend/.env.example
T
xsl 2009aa938c fix(billing): make quota seed and column names match the product SSOT
The product plan is the only source for quota numbers, but the 0001 seed
used a second set (agent_chat 20/50, tryon hard 10) and omitted hairstyle,
hd_export and report regen. Migration 0003 replaces the seed and renames
points_reserved → quota_reserved and bonus_value → bonus_granted so the
docs and the schema stop contradicting each other.

Effective limit now clips at hard_cap. CI runs the integration slice
against the Postgres/Redis services it already starts.
2026-08-14 11:28:35 +08:00

84 lines
5.0 KiB
Bash
Executable File

# 复制为 .env 后填入真实值。.env 已在 .gitignore 中,不要提交。
# dev/staging/prod 由部署平台注入环境变量,不使用 .env(架构文档 §11.2)。
APP_ENV=local
APP_NAME=meida-backend
API_PREFIX=/api/v1
DEBUG=true
LOG_LEVEL=INFO
LOG_JSON=true
# 需要额外脱敏的字段名,逗号分隔;默认清单见 packages/shared/logging.py
LOG_EXTRA_REDACT_KEYS=
# ── 数据库 / Redis ─────────────────────────────────────────────────────────
# 端口刻意用 55432 / 56379,避免与本机已有的 PostgreSQL、Redis 抢端口
DATABASE_URL=postgresql+asyncpg://meida:meida@localhost:55432/meida
DB_POOL_SIZE=10
DB_MAX_OVERFLOW=20
DB_ECHO=false
REDIS_URL=redis://localhost:56379/0
CELERY_BROKER_URL=redis://localhost:56379/1
CELERY_RESULT_BACKEND=redis://localhost:56379/2
# ── 鉴权 ──────────────────────────────────────────────────────────────────
# 生成:openssl rand -hex 32 。staging/prod 若沿用占位值会启动失败
JWT_SECRET=change-me-local-only-do-not-use-outside-local
JWT_ALGORITHM=HS256
JWT_ACCESS_TTL_SECONDS=900
JWT_ISSUER=meida
# 免登录换 token 的调试入口,仅本地/联调可开
DEV_AUTH_ENABLED=true
# ── LLM 路由 ──────────────────────────────────────────────────────────────
LLM_PRIMARY_PROVIDER=deepseek
LLM_BACKUP_PROVIDER=zhipu
LLM_STRUCTURED_MAX_RETRIES=2
LLM_CIRCUIT_FAILURE_THRESHOLD=3
LLM_CIRCUIT_COOLDOWN_SECONDS=30
# 按场景覆盖模型与采样参数,如 {"agent_chat":{"temperature":0.5}}
LLM_SCENE_OVERRIDES_JSON={}
DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
DEEPSEEK_MODEL=deepseek-v4-flash
DEEPSEEK_TIMEOUT_SECONDS=30
ZHIPU_API_KEY=
ZHIPU_BASE_URL=https://open.bigmodel.cn/api/paas/v4
ZHIPU_MODEL=glm-4-flash
ZHIPU_TIMEOUT_SECONDS=30
# ── Prompt 缓存纪律 ───────────────────────────────────────────────────────
# strict:固定前缀里出现时间戳/随机值等易变 token 直接启动失败。
# 命中缓存的输入价格只有未命中的 1/30,前缀被污染会让输入成本翻数十倍。
LLM_CACHE_PREFIX_MODE=strict
PROMPTS_DIR=prompts
# ── 成本单价(单位:分 / 百万 token)──────────────────────────────────────
# 取自 DeepSeek 官方价目表。2026-08-17 00:00 起改为峰谷定价:
# 高峰(北京时间 09:00-12:00、14:00-18:00)单价是空闲时段的 2 倍。
# 因此这里要配两套,由 packages/llm/cost.py 按调用时刻选择。
# flash 空闲:缓存命中 ¥0.05 / 输入 ¥1.5 / 输出 ¥4.5 每百万 token
LLM_COST_RATES_JSON={"deepseek-v4-flash":{"input_cents_per_mtok":"150","cached_input_cents_per_mtok":"5","output_cents_per_mtok":"450"},"deepseek-v4-pro":{"input_cents_per_mtok":"450","cached_input_cents_per_mtok":"15","output_cents_per_mtok":"1350"},"glm-4-flash":{"input_cents_per_mtok":"10","cached_input_cents_per_mtok":"10","output_cents_per_mtok":"10"}}
# flash 高峰:缓存命中 ¥0.10 / 输入 ¥3 / 输出 ¥9 每百万 token
LLM_COST_RATES_PEAK_JSON={"deepseek-v4-flash":{"input_cents_per_mtok":"300","cached_input_cents_per_mtok":"10","output_cents_per_mtok":"900"},"deepseek-v4-pro":{"input_cents_per_mtok":"900","cached_input_cents_per_mtok":"30","output_cents_per_mtok":"2700"},"glm-4-flash":{"input_cents_per_mtok":"10","cached_input_cents_per_mtok":"10","output_cents_per_mtok":"10"}}
# 未登记的模型按这个价算。刻意取高档:宁可高估触发熔断,也不要低估成本形成盲区
LLM_DEFAULT_COST_RATE_JSON={"input_cents_per_mtok":"300","cached_input_cents_per_mtok":"10","output_cents_per_mtok":"900"}
LLM_PEAK_PRICING_ENABLED=true
# ── 全局日成本熔断(NFR-COST-02)─────────────────────────────────────────
# 按用户配额封不住总成本(总成本 = 用户数 × 人均,用户数无上限),
# 真正封顶的只有这个全局开关。
# 100000 分 = ¥1000/天,是按 8-17 之前旧单价推的占位,不是验收值。
# 峰谷生效后须用实测 token 分布重算(T-P1-25b),否则熔断会在错误位置触发。
LLM_DAILY_BUDGET_ENABLED=true
LLM_DAILY_BUDGET_CENTS=100000
LLM_BUDGET_TIMEZONE_OFFSET_HOURS=8
# ── 可观测性 ──────────────────────────────────────────────────────────────
OTEL_ENABLED=false
OTEL_SERVICE_NAME=meida-api
OTEL_EXPORTER_OTLP_ENDPOINT=
PROMETHEUS_ENABLED=true