Apache Casbin Gateway
3. 供应商

3.3 没有API Key:用订阅顶上

ChatGPT或Claude订阅本来就没有API Key可粘,也不需要。把订阅接到供应商上有两条路,区别只在于登录握在谁手里。

Gateway保管

新建供应商时选ChatGPT订阅或Claude订阅,点登录:厂商自己的页面会在浏览器里打开,拿回来的令牌存在这边,和Key一样加密,过期前自动续,一个字都不会交给Agent。

之后这个订阅就跟一个Key没区别:任何Agent都能花它,它说的是哪套API无所谓,模型路由、权限、记录也都和有Key的供应商一模一样。

  • 基础URL指向的是这个订阅自己的服务端,不是厂商的API:ChatGPT是https://chatgpt.com/backend-api/codex,Claude是https://api.anthropic.com。
  • 模型留空:这个账号能用哪些模型,由它背后的套餐说了算。
  • 请求会按"这个登录本来是发给谁用的"那个样子发出去——那个服务端只认这个样子。

想换账号,再登录一次就行。快照里从来不带登录,所以导入进来的这类供应商要重新登录一次。

Agent自己保管

把认证方式设成调用方自己的登录。这时每个请求都带着Agent自己发来的凭据转发出去,它保住自己的登录态,这边什么都不存。

这样的供应商只有握着那个登录的Agent能用——Claude的归Claude Code,ChatGPT的归Codex。对Codex来说,写入配置往~/.codex/config.toml里写的不是Key,而是requires_openai_auth = true,它由此把自己已有的ChatGPT登录发过来。

这类供应商的环境变量片段只设基础URL,别的都不设:

export ANTHROPIC_BASE_URL="http://localhost:17000/v1/agents/claude-code"

在这里再放一个token,会顶掉Agent已有的登录——而保住那个登录正是这种模式存在的理由。

不管走哪条路,Codex的花费都会出现在用量页上,因为那一页读的是Agent自己的会话记录,而不是转发记录。

两条路都给你的

除了"你自己那把Key"以外的全部:

  • 完整的LLM记录(4.2)。
  • 对工具、模型、供应商的权限控制(4.1)。
  • 在会话记录已有数据之上,再加一份来自转发流量的用量(4.3)。

下一节:3.4 真伪检测。

在GitHub上编辑
Apache Incubator

Apache Casbin (Incubating) is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2026 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.

Apache, Apache Casbin, the names of Apache projects, and the feather logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. All other marks mentioned may be trademarks or registered trademarks of their respective owners.

本页内容