# AI 网关配置文件(data/ 目录) # # ⚠ 本文件由管理页面「网关配置」生成(管理员账号),页面保存时会**整份重写**: # 想要的历史决策/踩坑说明在 README.md(按轮次记录),这里只保留必要的现场注释。 # 手改本文件仍然有效(server.hot_reload=true 时按 mtime 自动重载), # 但页面下次保存会以页面上的值为准 —— 改配置优先用页面。 # # 端口默认 8808;密钥统一走 auth.token_env 指向的环境变量(本机见 .env),不在 yaml 存明文。 # 本文件是项目的唯一配置文件(run.py 默认读取;GATEWAY_CONFIG 可覆盖)。 # ── 供应商 + 模型清单 ─────────────────────────────────── # auth.token_env 指向存放密钥的环境变量;auth.token 只有在不用环境变量时才填(明文)。 # media 段留空 = 该供应商不支持图像/视频(Agnes 是自有非标准端点,故单独覆盖)。 # models.type: text | image | video;vision: 该模型是否支持图像输入(带图对话会被优先排到链首)。 providers: agnes: name: Agnes AI base_url: https://api.agnes-ai.cn/v1 auth: token_env: AGNES_API_KEY token: '' extra_headers: {} rate_limit_rps: null requires_session_header: false endpoints: chat/completions: path: /chat/completions auth: bearer headers: {} messages: path: /messages auth: x-api-key headers: anthropic-version: '2023-06-01' responses: path: /responses auth: bearer headers: {} media: image_endpoint: /images/generations image_default_size: 1K video_create_endpoint: /videos video_poll_base: https://api.agnes-ai.cn video_poll_path: /agnesapi video_model_name: agnes-video-2.5-flash models: - id: agnes-3.0-flash display_name: Agnes 3.0 Flash type: text vision: true protocols: - chat/completions - id: agnes-2.5-flash display_name: Agnes 2.5 Flash type: text vision: true protocols: - chat/completions - id: agnes-image-2.5-flash display_name: Agnes Image 2.5 Flash type: image vision: false protocols: - chat/completions - id: agnes-video-2.5-flash display_name: Agnes Video 2.5 Flash type: video vision: false protocols: - chat/completions volc_engine: name: 火山方舟 Coding Plan base_url: https://ark.cn-beijing.volces.com/api/coding/v3 auth: token_env: VOLC_API_KEY token: '' extra_headers: {} rate_limit_rps: null requires_session_header: false endpoints: chat/completions: path: /chat/completions auth: bearer headers: {} messages: path: /messages auth: x-api-key headers: anthropic-version: '2023-06-01' responses: path: /responses auth: bearer headers: {} media: image_endpoint: null image_default_size: null video_create_endpoint: null video_poll_base: null video_poll_path: null video_model_name: null models: - id: ark-code-latest display_name: 火山方舟 ark-code-latest type: text vision: false protocols: - chat/completions opencode: name: OpenCode Go base_url: https://opencode.ai/zen/go/v1 auth: token_env: OPENCODE_API_KEY token: '' extra_headers: User-Agent: api-gateway/2.4.0 (jakon opencode-go) rate_limit_rps: null requires_session_header: true endpoints: chat/completions: path: /chat/completions auth: bearer messages: path: /messages auth: x-api-key headers: anthropic-version: '2023-06-01' responses: path: /responses auth: bearer media: image_endpoint: null image_default_size: null video_create_endpoint: null video_poll_base: null video_poll_path: null video_model_name: null models: - id: glm-5.3-flash display_name: GLM-5.3-Flash type: text protocols: - chat/completions vision: false - id: glm-5.3 display_name: GLM-5.3 type: text protocols: - chat/completions vision: false - id: glm-5.2 display_name: GLM-5.2 type: text protocols: - chat/completions vision: false - id: glm-5.1 display_name: GLM-5.1 type: text protocols: - chat/completions vision: false - id: kimi-k2.7-code display_name: Kimi K2.7 Code type: text protocols: - chat/completions params: temperature: 1 vision: false - id: kimi-k2.6 display_name: Kimi K2.6 type: text protocols: - chat/completions vision: false - id: longcat-2.0 display_name: LongCat 2.0 type: text protocols: - chat/completions vision: false - id: mimo-v2.5 display_name: MiMo V2.5 type: text protocols: - chat/completions vision: false - id: mimo-v2.5-pro display_name: MiMo V2.5 Pro type: text protocols: - chat/completions vision: false - id: hy4-preview display_name: Hy4 Preview type: text protocols: - chat/completions vision: false - id: hy3 display_name: Hy3 type: text protocols: - chat/completions vision: false - id: kimi-k3 display_name: Kimi K3 type: text protocols: - chat/completions - messages vision: false - id: minimax-m3 display_name: MiniMax M3 type: text protocols: - chat/completions - messages vision: false - id: minimax-m2.5 display_name: MiniMax M2.5 type: text protocols: - chat/completions - messages vision: false - id: qwen3.8-max display_name: Qwen3.8 Max type: text protocols: - chat/completions - messages vision: false - id: qwen3.8-flash display_name: Qwen3.8 Flash type: text protocols: - chat/completions - messages vision: false - id: qwen3.7-max display_name: Qwen3.7 Max type: text protocols: - chat/completions - messages vision: false - id: qwen3.7-plus display_name: Qwen3.7 Plus type: text protocols: - chat/completions - messages vision: false - id: qwen3.6-plus display_name: Qwen3.6 Plus type: text protocols: - chat/completions - messages vision: false - id: deepseek-v4.1-flash display_name: DeepSeek V4.1 Flash type: text vision: true protocols: - chat/completions - messages - responses - id: deepseek-v4-pro display_name: DeepSeek V4 Pro type: text protocols: - chat/completions - messages - responses vision: false - id: deepseek-v4-flash display_name: DeepSeek V4 Flash type: text protocols: - chat/completions - messages - responses vision: false - id: deepseek-v4-flash-vision-exp display_name: DeepSeek V4 Flash Vision Exp type: text vision: true protocols: - chat/completions - messages - responses - id: minimax-m2.7 display_name: MiniMax M2.7 type: text protocols: - messages vision: false - id: union-alpha display_name: Union Alpha Free type: text protocols: - messages vision: false - id: grok-4.6 display_name: Grok 4.6 type: text protocols: - responses vision: false - id: gpt-5.6-luna display_name: GPT 5.6 Luna type: text protocols: - responses vision: false - id: muse-spark-1.3-contributor display_name: Muse Spark 1.3 Contributor type: text protocols: - responses vision: false - id: muse-spark-1.2-contributor display_name: Muse Spark 1.2 Contributor type: text protocols: - responses vision: false # ── 虚拟模型 id(别名,第三十一轮)────────────────────── # 给客户端一个"名字固定"的入口:客户端永远只写 model: wjd,实际转发到哪个真实模型 # 由这里决定(页面上改:供应商与模型页 → 虚拟模型 wjd → 单选 + 保存)。 # 规则(保存时校验,手改 yaml 一样拦): # · 只走 chat/completions(OpenAI)格式;用 /v1/messages、/v1/responses 打 wjd 会在入口 400; # · target 必须是**存在的文本模型**且支持 chat/completions(面板里其余模型置灰); # · 别名 id 不能和真实模型 id 重名; # · 别名不复制目标的配置(协议线/视觉/强制参数/定价全部继承 target,一处修改全局生效); # · enabled: false = 该 id 不存在(等同没配),停用时不校验 target。 # 别名不进 /v1/models/speedtest(测速请测它指向的模型),但会出现在 /v1/models 里(带 alias_of)。 aliases: wjd: enabled: true target: agnes-3.0-flash note: 老板的固定入口(默认指向旗舰,随时可在页面上改) # ── 服务与运维开关 ────────────────────────────────────── # host/port/graceful_shutdown/docs_enabled/hot_reload 这几项**改完要重启进程**才生效, # 其余每请求读取,页面保存即生效。 # 安全相关:health_auth(/health/* 是否鉴权)、webhook_allow_private(视频回调是否允许内网地址)、 # docs_enabled(FastAPI 文档,默认关)、auth_fail_limit_per_min(同源 IP 每分钟鉴权失败上限)。 # cors_origins 写 ["*"] 表示任意站点都能跨域驱动本网关(会把上游额度暴露给陌生网页), # 生产建议收敛成可信前端域名白名单。 server: host: 127.0.0.1 port: 8808 timeout: 120 retry: 3 health_auth: false hot_reload: true hot_reload_interval: 15 metrics_enabled: true rate_limit_rps: null max_body_size: 2000000 cors_origins: - '*' graceful_shutdown: 30 batch_max_concurrency: 16 batch_max_items: 64 webhook_allow_private: false docs_enabled: false auth_fail_limit_per_min: 20 # ── 供应商熔断 ────────────────────────────────────────── # 某供应商在 window 秒内失败达到 failure_threshold 次就熔断 cooldown 秒, # 期间直接跳过它(不再白等),让 fallback 快速切到健康供应商。 circuit: enabled: true failure_threshold: 3 cooldown: 30 window: 10 # ── 可观测性 ──────────────────────────────────────────── # log_level 支持 DEBUG/INFO/WARNING/ERROR;log_json=true 输出结构化 JSON 行(接 ELK)。 # access_log_maxlen = 访问日志环形缓冲长度(日志页「已加载 N 条」的上限)。 observability: log_level: INFO log_json: false access_log_maxlen: 500 # ── 定价(人民币 / 百万 token,用于 /v1 响应里估算成本) ─ # 不配则该模型不返回 estimated_cost_cny(不影响调用)。 pricing: per_model: agnes-3.0-flash: input: 0.35 output: 1.0 agnes-2.5-flash: input: 0.0 output: 0.0 ark-code-latest: input: 0.5 output: 2.0 # ── 媒体下载代理白名单 ────────────────────────────────── # 生成的图片/视频挂在第三方 CDN 上且不带 CORS 头,浏览器 fetch 不到 blob、跨域 # 也不生效 —— 所以由网关代拉一次并加 Content-Disposition: attachment。 # 安全:这是全网关唯一一个服务端主动出网的接口,只有这里列出的域名(含子域)允许被代下载, # 且解析出的 IP 必须是公网地址;allowed_hosts 为空 = 该功能整体关闭。 # 换了供应商/CDN 域名时,往这里加一条即可(如 volc 的 tos-*.volces.com)。 download: allowed_hosts: - cos-platform-outputs.agnes-ai.cn - maas-watermark-prod-new.cn-wlcb.ufileos.com max_bytes: 67108864 # ── 网关入口鉴权 ──────────────────────────────────────── # 账号与 API Key 由页面管理,存在 data/users.json(见 app/users.py): # 管理员在「用户管理」建账号,各账号在「设置 → 我的 API Key」自助铸 Key。 # 本文件里没有任何用户/密钥,只有会话时长这一个开关。 auth: session_ttl_minutes: 1440