OhMyGPT

应用归属

在每个请求里标明你的应用,用量就能按应用拆分统计。

几个可选的请求头可以标明发出请求的应用。OhMyGPT 会把它们和请求一起保存,多个应用或工具共用一个账户时,你也能分清各自的用量。

请求头保存为取值
HTTP-Refererapp_url你的应用 URL,必须以 https:// 或 http:// 开头。
X-OhMyGPT-Titleapp_title你的应用名称。
X-OhMyGPT-Categoriesapp_categories自由文本,原样保存,例如 cli-agent。

已经在发送 OpenRouter 请求头的应用无需改动:X-OpenRouter-Title 和 X-Title 等同于 X-OhMyGPT-Title,X-OpenRouter-Categories 等同于 X-OhMyGPT-Categories。同时出现多个时,以 X-OhMyGPT-* 为准。浏览器自带的标准 Referer 头不会被读取。

超过 128 字节的值会被截断。无效的值会被丢弃,请求本身绝不会因为这些请求头而失败。

curl https://api.ohmygpt.com/v1/chat/completions \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "HTTP-Referer: https://example.com" \
  -H "X-OhMyGPT-Title: Example App" \
  -H "X-OhMyGPT-Categories: cli-agent" \
  -d '{"model": "ohmygpt/mock", "messages": [{"role": "user", "content": "ping"}]}'

使用 OpenAI SDK 时,在客户端上设置一次即可:

client = OpenAI(
    base_url="https://api.ohmygpt.com/v1",
    api_key=os.environ["OHMYGPT_API_KEY"],
    default_headers={"HTTP-Referer": "https://example.com", "X-OhMyGPT-Title": "Example App"},
)

自定义统计标签

另外三个请求头,加上最多 10 个自定义请求头,可以给请求打上费用统计用的标签:

请求头存为
X-Projectproject
X-Environmentenvironment
X-Cost-Centercost_center
X-Label-<名字>label.<名字>,转成小写,- 换成 _
curl https://api.ohmygpt.com/v1/chat/completions \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Project: docs-demo" \
  -H "X-Environment: staging" \
  -H "X-Cost-Center: research" \
  -H "X-Label-Team: core" \
  -d '{"model": "ohmygpt/mock", "messages": [{"role": "user", "content": "ping"}]}'

这个请求会带着 project: docs-demo、environment: staging、cost_center: research 和 label.team: core 这几个标签存下来。可以像应用标签一样按它们筛选,例如 GET /v1/usage?project=docs-demo 或 ?label.team=core,也可以用 group_by=label:project 分组汇总。

按应用查看用量

GET /v1/usage 在每条记录的 labels 里返回这些值,也可以按它们筛选。它读取的是整个账户的数据,请用管理员 Key 调用:

curl "https://api.ohmygpt.com/v1/usage?app_title=Example%20App&limit=1" \
  -H "Authorization: Bearer $OHMYGPT_API_KEY"
[
  {
    "request_id": "01a19b5d-8121-7575-9e9f-14208909f380",
    "time": "2026-11-02T08:26:00.185Z",
    "model": "ohmygpt/mock",
    "status": 200,
    "cost_credits": 0,
    "labels": {
      "app_url": "https://example.com",
      "app_title": "Example App",
      "app_categories": "cli-agent",
      "sdk_info": "curl/8.23.0"
    }
  }
]

sdk_info 取自 User-Agent 请求头。要按应用汇总费用,按标签分组汇总即可:GET /v1/usage/summary?group_by=label:app_title。

本页目录