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
- フォーク
- 365
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 263
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/ai のほかの issue
-
openai-base: a tool call cut off by finish_reason "length" is reported as "tool_calls" and re-sent対応中かも @tombeckenham が今日担当しました。 オープンwaiting-on: maintainer
メンテナーはふだん 1 日以内に返信
-
ai-ollama: streamed chat() reports finishReason "stop" when done_reason is "length"対応中かも @AlemTuzlak が今日担当しました。 オープンwaiting-on: maintainer
メンテナーはふだん 1 日以内に返信
-
withPersistence does not save activity rows when a run is stopped or fails対応中かも @tombeckenham が 6 日前に担当しました。 オープンwaiting-on: maintainer
メンテナーはふだん 1 日以内に返信
-
Discriminate status-dependent record and option types (RunRecord, SessionIndexEntry, InputState, durable-only options)対応中かも @jherr が 6 日前に担当しました。 オープンenhancement waiting-on: maintainer
メンテナーはふだん 1 日以内に返信
-
ai-harness: an input with no principal runs with the owner session's principal対応中かも @tombeckenham が 7 日前に担当しました。 オープンwaiting-on: maintainer
メンテナーはふだん 1 日以内に返信
似ている issue
-
数据界面的横向滚动条缺失オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
zilliztech/attu#1037 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
openclaw/openclaw#181212 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apify/apify-mcp-server#1684 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Automattic/data-liberation-agent#953 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
siteboon/claudecodeui#1642 ·
メンテナーはふだん 5 日以内に返信