Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#1,845 コメント 0 件 リアクション 0 件 担当者 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
フォーク
365
平均マージ
1日 9時間
マージ済み PR(30日)
263

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/ai のほかの issue

TanStack/ai の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。