Area: Provider adapters
What are you trying to accomplish?
Accurate per-request cost accounting for the kiro provider. Every Kiro request row in usage.jsonl currently records estimated: true token counts and cacheProvenance: "unknown", so there is no real usage/cost signal for Kiro traffic at all — not even the one the upstream already sends.
What prevents this today?
The Kiro event stream already emits a meteringEvent frame carrying the actual credits charged for the request, but KNOWN_EVENT_TYPES in src/adapters/kiro-events.ts does not include it, so parseKiroEvent() returns null and the frame is dropped silently — ocx debug provider on does not log it either.
Live capture (fresh free-tier Builder ID account, opencodex 2.65.0, raw decodeEventStream probe against runtime.us-east-1.kiro.dev):
glm-5:
#1 :event-type=initial-response {"conversationId": "..."} <- dropped
#2 :event-type=assistantResponseEvent {"content": "...", "modelId"}
#3 :event-type=metadataEvent {"stopReason": "END_TURN"} <- no tokenUsage
#4 :event-type=contextUsageEvent {"contextUsagePercentage": 1.94}
#5 :event-type=meteringEvent {"unit": "credit", "unitPlural": "credits",
"usage": 0.04582331509121062} <- dropped
claude-sonnet-4.5 (same account/endpoint):
#1 initial-response, #2 assistantResponseEvent, #3 metadataEvent {stopReason},
#4 contextUsageEvent {contextUsagePercentage: 2.03},
#5 meteringEvent {"unit":"credit","usage":0.009624912835820896}
q.us-east-1.amazonaws.com/generateAssistantResponse emits the same meteringEvent shape.
Two facts worth stating plainly:
metadataEvent carried no tokenUsage in any observed frame, on either model, on either endpoint — the token-count absence is real upstream behavior, not an adapter miss.
- The
meteringEvent credit value is present every request and is currently invisible to opencodex.
What should OpenCodex do?
- Recognize
meteringEvent (and defensively usageEvent/metricsEvent/tokenMetrics wrappers) and record the reported credit amount on the request log/usage row — e.g. a creditUsage field alongside OcxUsage, so usage.jsonl carries real spend instead of only heuristic tokens.
- Log dropped/unknown
:event-type names via debugProviderDiagnostic when provider debug is on — today they leave no trace even in debug mode, which hides exactly this class of upstream data.
- Optionally:
initial-response also carries conversationId and is dropped; when messageMetadataEvent is absent (it was on both captures above), the conversation id is lost.
Example
Current row:
"usage": {"inputTokens": 8, "outputTokens": 1, "contextTotalTokens": 3701, "estimated": true},
"cacheProvenance": "unknown"
Desired (exact field naming up to you):
"usage": { ..., "estimated": true },
"creditUsage": {"unit": "credit", "amount": 0.04582331509121062}
Alternatives or workarounds
The heuristic estimator (devlog 142/160) is the right answer for input_tokens/output_tokens display and Codex auto-compact — keep it. This proposal only adds the billing signal next to it. Another implementation of the same subscription surface, 0a00/Kiro-Go-Plus (proxy/eventstream_payload.go, proxy/kiro.go), already classifies meteringEvent/usageEvent/metricsEvent frames and recursively hunts nested usage envelopes, including Anthropic-style cacheReadInputTokens/cacheCreation splits when present — useful reference for the priority order.
Additional context
Area: Provider adapters
What are you trying to accomplish?
Accurate per-request cost accounting for the
kiroprovider. Every Kiro request row inusage.jsonlcurrently recordsestimated: truetoken counts andcacheProvenance: "unknown", so there is no real usage/cost signal for Kiro traffic at all — not even the one the upstream already sends.What prevents this today?
The Kiro event stream already emits a
meteringEventframe carrying the actual credits charged for the request, butKNOWN_EVENT_TYPESinsrc/adapters/kiro-events.tsdoes not include it, soparseKiroEvent()returnsnulland the frame is dropped silently —ocx debug provider ondoes not log it either.Live capture (fresh free-tier Builder ID account, opencodex 2.65.0, raw
decodeEventStreamprobe againstruntime.us-east-1.kiro.dev):glm-5:claude-sonnet-4.5(same account/endpoint):q.us-east-1.amazonaws.com/generateAssistantResponseemits the samemeteringEventshape.Two facts worth stating plainly:
metadataEventcarried notokenUsagein any observed frame, on either model, on either endpoint — the token-count absence is real upstream behavior, not an adapter miss.meteringEventcredit value is present every request and is currently invisible to opencodex.What should OpenCodex do?
meteringEvent(and defensivelyusageEvent/metricsEvent/tokenMetricswrappers) and record the reported credit amount on the request log/usage row — e.g. acreditUsagefield alongsideOcxUsage, sousage.jsonlcarries real spend instead of only heuristic tokens.:event-typenames viadebugProviderDiagnosticwhen provider debug is on — today they leave no trace even in debug mode, which hides exactly this class of upstream data.initial-responsealso carriesconversationIdand is dropped; whenmessageMetadataEventis absent (it was on both captures above), the conversation id is lost.Example
Current row:
Desired (exact field naming up to you):
Alternatives or workarounds
The heuristic estimator (devlog 142/160) is the right answer for
input_tokens/output_tokensdisplay and Codex auto-compact — keep it. This proposal only adds the billing signal next to it. Another implementation of the same subscription surface,0a00/Kiro-Go-Plus(proxy/eventstream_payload.go,proxy/kiro.go), already classifiesmeteringEvent/usageEvent/metricsEventframes and recursively hunts nested usage envelopes, including Anthropic-stylecacheReadInputTokens/cacheCreationsplits when present — useful reference for the priority order.Additional context
us-east-1KIRO_CLIandAI_EDITORrequest shapes receivedmeteringEvent