ai-vercel-gateway: usage.cost leaves out gateway surcharges, and the BYOK credential type is not exposed
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Start with packages/ai-vercel-gateway/src/utils/gateway-cost.ts and the gateway response metadata described in the issue. Trace how withGatewayCost sets usage.cost and how providerUsageDetails is assembled, then check the related tests. Done when usage exposes the gateway-debited amount, surcharge information, and credential type as described.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens
Follow-up to #1845 (fixed in #1873, thank you). withGatewayCost copies provider_metadata.gateway.cost to usage.cost and documents it as the amount debited:
When the gateway adds a surcharge (Custom Reporting user / tags writes, Zero Data Retention), cost is the inference charge only. The amount debited is gatewayCost, which is cost + surchargeCost. Vercel's generation lookup docs define gateway_cost as "Total amount debited from your AI Gateway balance for this generation", and total_cost as including "any surcharges (for example, Zero Data Retention or Custom Reporting writes)".
The response also says which credential served the request (routing.modelAttempts[].providerAttempts[].credentialType: byok or system). That is not carried over either, so a consumer cannot tell whether cost: 0 means a BYOK request, which the provider bills at marketCost. We use costDetails.upstreamCost ?? cost for that today.
Repro
@tanstack/ai 1.0.0, @tanstack/ai-vercel-gateway 1.0.0, server-side chat() on Node 24
provider_metadata.gateway from POST https://ai-gateway.vercel.sh/v1/responses with max_output_tokens: 16:
| Model (credential) | providerOptions.gateway |
cost |
marketCost |
surchargeCost |
gatewayCost |
|---|---|---|---|---|---|
openai/gpt-4.1-nano (system) |
none | 0.0000019 | 0.0000019 | 0 | 0.0000019 |
openai/gpt-4.1-nano (system) |
user + tags |
0.0000019 | 0.0000019 | 0.00015 | 0.0001519 |
anthropic/claude-sonnet-5.5 (byok) |
none | 0 | 0.00008 | 0 | 0 |
anthropic/claude-sonnet-5.5 (byok) |
user + tags |
0 | 0.00008 | 0.00015 | 0.00015 |
The same user + tags requests through the adapter:
let usage
await chat({
adapter: createVercelGatewayText(model, key),
messages: [{ role: 'user', content: 'Reply with OK.' }],
threadId: 'repro',
stream: false,
modelOptions: { max_output_tokens: 16, gateway: { user: 'u1', tags: ['t1'] } },
middleware: [{ name: 'usage', onFinish: (_ctx, info) => { usage = info.usage } }],
})
| Model | usage.cost |
usage.costDetails |
usage.providerUsageDetails |
GET /v1/generation for that id |
|---|---|---|---|---|
openai/gpt-4.1-nano |
0.0000019 | { upstreamCost: 0.0000019 } |
generationId, finalProvider: 'azure' |
gateway_cost 0.0001519, surcharge_cost 0.00015, is_byok false |
anthropic/claude-sonnet-5.5 |
0 | { upstreamCost: 0.00008 } |
generationId, finalProvider: 'anthropic' |
gateway_cost 0.00015, surcharge_cost 0.00015, is_byok true |
Expected
usage.cost is what the gateway debits (gatewayCost), or the surcharge is available next to it (for example surchargeCost and gatewayCost in providerUsageDetails). The credential type is carried in providerUsageDetails as well.
Why
Per-run cost in our analytics should match the gateway bill. For BYOK runs we report the provider's list price instead, which only works when we can tell BYOK from system credits.
- Ngôn ngữ chính
- TypeScript
- Star
- 3.2k
- Fork
- 372
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 229
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/ai
-
openai-base: a Responses max_output_tokens cutoff ends as RUN_ERROR without usage instead of finishReason 'length'Có thể đã có người làm @pcbeingused333 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
TanStack/ai#1916 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[ai-harness] Rejected receipt resolves before durable rejection; recovery can rerun the inputĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
TanStack/ai#1926 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
TanStack/ai#1924 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-gemini: native image generation throws "returned no id" when modelOptions.store is falseCó thể đã có người làm @pcbeingused333 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 57/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:plugins area:security area:skills bug has repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
anthropics/claude-code#105911 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[ko] Translate /team into KoreanĐang mởdocumentation good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
dev-five-git/devup-ui#879 ·
Maintainer thường phản hồi trong vòng 11 ngày
-
openspec-apply-change skill: when blocked, may select a ready artifact unrelated to missingArtifactsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Fission-AI/OpenSpec#2165 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐞 bug 🧐 unconfirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Tencent/tdesign-vue-next#7032 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày