Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

ai-vercel-gateway: surface provider_metadata.gateway cost on usage (usage.cost)

已关闭
#1,845 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@tombeckenham 已经在做这个了。

开始于 2026年10月21日。

评估

这个 Issue 还没有评估数据。

描述

waiting-on: maintainer
What happens

Vercel AI Gateway's Responses API returns cost and routing data in provider_metadata.gateway (cost, marketCost, gatewayCost, generationId, routing.finalProvider, …). With @tanstack/ai-vercel-gateway, none of it reaches the run: FinishInfo.usage / RUN_FINISHED.usage carry token counts only, so usage.cost stays undefined, although TokenUsage has cost/costDetails and the OpenRouter adapter fills them.

Repro

@tanstack/ai 0.70.0, @tanstack/ai-vercel-gateway 0.4.1 (same in 0.4.2), @tanstack/openai-base 0.15.0

let usage
await chat({
  adapter: createVercelGatewayText('anthropic/claude-haiku-4.5', key),
  messages: [{ role: 'user', content: 'Say OK.' }],
  stream: false,
  middleware: [{ name: 'usage', onFinish: (_ctx, info) => { usage = info.usage } }],
})
console.log(usage?.cost) // undefined

A direct POST https://ai-gateway.vercel.sh/v1/responses with the same model returns:

"provider_metadata": {
  "gateway": {
    "cost": "0",
    "marketCost": "0.000035",
    "gatewayCost": "0",
    "generationId": "gen_…",
    "routing": { "finalProvider": "anthropic", "…": "…" }
  }
}

buildResponsesUsage in openai-base reads only response.usage.

Expected

Map provider_metadata.gateway onto usage, e.g. usage.cost = Number(gateway.cost) with the market price in costDetails, so cost can be tracked per run as with OpenRouter. Exposing generationId / finalProvider (for example in RUN_FINISHED metadata) would help too.

Why

We send per-run AI metrics to our analytics. With the AI SDK we read providerMetadata.gateway; after moving to TanStack AI there is no way to get it without wrapping fetch and parsing the stream ourselves.

主要语言
TypeScript
星标
3.2k
派生
372
平均合并
1 天 16 小时
30 天内合并 PR
244

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/ai 的其他 Issue

查看 TanStack/ai 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。