Repository navigation
Description
Client or integration
Claude Code
Provider or upstream service
kiro
OpenCodex version
2.98.0 and 2.99.0 (same cost code on dev at 4a22eda)
Endpoint or capability
/v1/messages routed to Kiro: usage and cost accounting (Logs ~$ column, ocx usage, /api/usage)
Current behaviour
Every Kiro row is logged with usageStatus: "estimated", and its cost is the estimated input and output tokens at the model's Anthropic list price (for claude-opus-5.5, $4 input / $20 output per 1M tokens), on every turn.
The rows are estimated because Kiro sent no tokenUsage frame on any turn of this account: src/adapters/kiro-events.ts marks a figure upstreamReported only from that frame, and src/adapters/kiro/stream.ts falls back to estimated input without it. Of 72,334 Kiro rows in ~/.opencodex/usage.jsonl, 72,322 are estimated, 12 are unreported and none is upstream-reported.
Kiro does not bill tokens: it bills credits, and returns the billed amount in its meteringEvent. The adapter already parses it into usage.providerCredits (src/adapters/kiro/stream.ts, summed in src/server/request-log.ts), but estimateRequestCost / estimateAttemptCost (src/usage/cost.ts) never read it.
Two effects make the estimate far too high:
- Long conversations resend their whole context every turn. The token estimate grows linearly with context, while the billed credits grow much more slowly, which is consistent with Kiro caching the repeated context (the CodeWhisperer wire has no
cache_control, and Kiro reports no cache tokens). - A credit is cheaper than the list price of the tokens it covers.
Rows that Kiro refused or that were cancelled before generation have no output and no credits, and are priced at their estimated input like any other estimated row, although nothing was billed. This account has 2,986 such rows (HTTP 429: 1,587, 400: 715, 502: 200, 499: 199, 500: 187, 403: 43, 401: 38, 503: 13, 504: 4), for 865.8 M estimated input tokens.
Caching on Kiro's side is a hypothesis: the wire carries no cache field. The evidence is the billed credits per 1k estimated input below, which fall as the context grows. The fix does not depend on it, because it costs what Kiro reports in meteringEvent.
Expected behaviour
When the operator sets a USD price per credit for the provider, the cost of a Kiro request is providerCredits x price, which follows what Kiro billed, caching included. A row with no credits and no output costs nothing. Without a configured price, today's token estimate stays unchanged.
The price is configurable and has no default, because it depends on the plan: on https://kiro.dev/pricing/, Pro is $20 for 1,000 credits ($0.02), Pro+ $40 for 2,000, Pro Max $100 for 5,000, Power $200 for 10,000 (all $0.02), and add-on credits are $0.04.
Minimal redacted request or reproduction
# Any Claude Code conversation routed to Kiro, then compare the displayed cost with the billed credits:
ocx usage --range today --provider kiro --model claude-opus-5.5 --json # summary.estimatedCostUsd
# per row in ~/.opencodex/usage.jsonl: usage.inputTokens (estimated) vs usage.providerCredits (billed)Actual response or error
# One Kiro account, 2026-11-07, Pro-tier price of $0.02 per credit.
# ocx usage today (2.98.0) providerCredits x $0.02
claude-opus-5.5 52.99 $ 35.03 $ (1,163 requests)
claude-sonnet-5.5 9.35 $ 0.82 $ (46 requests)
# 30 days, all Kiro rows (~39,500 requests):
token estimate, 5.5 models only ~56,500 $
providerCredits x $0.02 1,240 $
# Billed credits against estimated input size, 23,000 claude-opus-5.5 rows (median):
estimated input rows median credits credits per 1k input
50k - 100k 834 0.48 ~0.0064
100k - 200k 4416 0.66 ~0.0044
200k - 400k 7340 1.17 ~0.0039
400k+ 10150 1.95 ~0.0025 - 0.0035Upstream documentation
- https://kiro.dev/pricing/: plan prices, included credits, and $0.04 per add-on credit.
- https://kiro.dev/docs/models/ (updated 2026-10-24): consumption is in credits, relative to Auto, and depends on generated tokens and thinking depth. It documents no prompt caching and no per-token credit formula, so the caching above is inferred from billed credits.
Suggested mapping or implementation notes
Proposed in #8452, opt-in and without effect when the key is not set:
src/types/provider.ts: optionalproviders.<name>.creditPriceUsd(USD per provider credit).src/config/schema/config-schema.ts: accepts a finite number >= 0, rejects anything else onproviders.<name>.creditPriceUsd.src/usage/user-cost-overlays.ts:refreshUserCostOverlaysloads the prices with themodelCostsoverlays and includes them in the version signature, so/api/usagecaches refresh when a price changes; exported asactiveCreditPrices().src/usage/cost.ts: inestimateRequestCostandestimateAttemptCost, when the provider has a credit price,cost.totalisproviderCredits x price; a row with no credits andoutputTokens === 0costs 0; a row with output but no credits keeps the token estimate. Token counts are unchanged.
Tests (tests/usage/usage-provider-credit-price.test.ts): token estimate without a price, credits x price with a price (request and combo attempt), refused row at 0 with a price and at the token estimate without one, other providers unaffected, version bump on a price change, schema accepts 0 and 0.04 and rejects -0.01, Infinity and "0.04". With tests/usage/usage-cost.test.ts and usage-haiku-5-5-pricing.test.ts: 253 pass. bun test tests/usage tests/config shows the same intermittent timeouts (usage-timeline, settings-stream-mode) with and without the patch.
Verified on the running proxy after a restart: a new claude-sonnet-5.5 request billed 0.01703 credits and raised ocx usage by exactly $0.000341, and the daily totals above match providerCredits x $0.02 to the cent for Opus, Sonnet and Haiku 5.5.
Additional context and attachments
Related to #8306 (Kiro request shape for Claude models). The protocol trace marks request.cache_control as degraded on almost every Claude Desktop request routed to Kiro; caching still happens on Kiro's side, which is why billed credits are the reliable figure.
Checks
- I searched existing provider and compatibility issues.
- The request and response were redacted.
- The expected behaviour is based on an upstream specification or a concrete client requirement.
Activity
svc-aibot-363 commentedon Nov 7, 2026
Ready-to-apply patch
The change proposed above, as a patch against
devat6df9e1176767d5da2b674b7d9ee8a8df4bbf2b65. It applies cleanly withgit applyand is independent of the #8306 patch. No PR is opened: a maintainer can apply, review and land it.What it changes
src/types/provider.tsproviders.<name>.creditPriceUsd, USD per provider creditsrc/config/schema/config-schema.tsproviders.<name>.creditPriceUsdsrc/usage/user-cost-overlays.tsrefreshUserCostOverlaysloads the prices and adds them to the overlay signature, souserCostOverlayVersion()and the/api/usagecaches follow a price change;activeCreditPrices()exposes themsrc/usage/cost.tsestimateRequestCostandestimateAttemptCosttakecreditPrices(defaultactiveCreditPrices()); with a price,cost.total = providerCredits x price; no credits andoutputTokens === 0costs 0; output without credits keeps the token estimate; token counts are unchangedConfiguration, for a Kiro Pro plan:
{ "providers": { "kiro": { "creditPriceUsd": 0.02 } } }Tests
New
tests/usage/usage-provider-credit-price.test.ts(10 cases): token estimate without a price; credits x price for a request and for a combo attempt; output without credits keeps the token estimate; a refused row costs 0 with a price and keeps the token estimate without one; another provider is unaffected; a price change bumps the overlay version; the schema accepts 0 and 0.04 and rejects -0.01, Infinity and "0.04" on the right path.On
dev+ patch, Bun 1.4.4:The full
bun run testsuite was not run.Live check after a proxy restart with
creditPriceUsd: 0.02:ocx usage --range today --provider kiro --model <m>equals the sum ofproviderCredits x 0.02to the cent forclaude-opus-5.5(35.0348 $, 1,163 requests),claude-sonnet-5.5(0.8175 $, 46) andclaude-haiku-5.5(0.0112 $, 29). One newclaude-sonnet-5.5request billed 0.01703 credits and raised the total by 0.000341 $.Patch (5 files, +150 / -4)
Ingwannu commentedon Nov 8, 2026
Verified on
dev(f8dfc2f):src/adapters/kiro/stream.ts:749and:476,src/server/request-log.ts:1961,src/usage/log.ts:611. The earlier parse gap ([Kiro] Event stream already carries per-request credit metering — adapter drops meteringEvent #5948) was fixed by fix(providers): parse Kiro meteringEvent credits and preserve in usage ledger #5951 and fix: integrate bug train 9B provider, Claude, and Windows repairs #5985.estimateAttemptCost(src/usage/cost.ts:613-648) andestimateRequestCost(:698-735) price only input and output tokens through the price table.cost.tsnever readsproviderCredits.tokenUsageframe.src/adapters/kiro-events.ts:140marks a measured figureupstreamReported.src/usage/log.ts:582marks Kiro rows estimated when that flag is absent, andsrc/adapters/kiro/stream.ts:458-463falls back to estimated input when no authoritative usage arrives. Your rows match a turn with notokenUsageframe. That should be stated in the report.Not verified here: that server-side caching explains the gap between estimated tokens and billed credits (the Kiro wire carries no cache field, so that is a hypothesis), and that refused or cancelled rows are priced at full input.
A per-credit price is a new configuration field and changes the cost model, so it is a feature decision for the owner rather than a bug fix. Please do not treat the attached patch as reviewed; it is a comment, not a PR.
svc-aibot-363 commentedon Nov 9, 2026
Thanks for checking. The PR is #8452; the per-credit price is opt-in and leaves every cost unchanged when it is not set, so the feature decision stays with the owner on the PR.
On your points, from this account's local
usage.jsonl(72,334 Kiro rows):tokenUsageframe: 72,322 rows areestimatedand 12unreported; none carries an upstream-reported figure. On this account Kiro never sent atokenUsageframe, so every Kiro cost shown is the token estimate. I will add that to the issue.meteringEvent.estimateRequestCostprices them like any other estimated row; the test "without a price, a refused row keeps the token estimate" in the PR runs that unchanged path.Merge dev into fix/kiro-cost at e083c08
docs(providers): document providers.<name>.creditPriceUsd
docs(providers): restore the config reference's paragraph break
feat(usage): cost credit-billed provider rows from providerCredits an…
docs(providers): document providers.<name>.creditPriceUsd
docs(providers): restore the config reference's paragraph break
feat(usage): cost credit-billed provider rows from providerCredits an…
docs(providers): document providers.<name>.creditPriceUsd
docs(providers): restore the config reference's paragraph break
feat(usage): cost credit-billed provider rows from providerCredits an…