ai-vercel-gateway: surface provider_metadata.gateway cost on usage (usage.cost)
维护者通常 1 天内回复
@tombeckenham 已经在做这个了。
开始于 2026年10月21日。
评估
这个 Issue 还没有评估数据。
描述
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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/ai 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
-
Durable resume through withPersistence never fills ctx.inputResponse for mcp_input interrupts可能已有人在做 @tombeckenham 于 3 天前认领。 未关闭waiting-on: maintainer
维护者通常 1 天内回复
-
ai, ai-persistence: a nested subagent that waits runs again from the start under withPersistence可能已有人在做 @tombeckenham 于 4 天前认领。 未关闭waiting-on: maintainer
维护者通常 1 天内回复
-
ai-ollama: streamed chat() reports finishReason "stop" when done_reason is "length"可能已有人在做 @AlemTuzlak 于 4 天前认领。 未关闭waiting-on: maintainer
维护者通常 1 天内回复
-
Discriminate status-dependent record and option types (RunRecord, SessionIndexEntry, InputState, durable-only options)可能已有人在做 @jherr 于 10 天前认领。 未关闭enhancement waiting-on: maintainer
维护者通常 1 天内回复
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
outline/outline#14348 · 1 条评论 ·
维护者通常 1 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
[Bug]: Agent import retains quotes in .env API keys followed by inline comments可能已有人在做 @yxr-2025 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
awslabs/visual-asset-management-system#804 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
dsh-market/dsh-market#1027 · 1 条评论 ·
维护者通常 1 天内回复