feat: capture provider-reported cost from OpenAI-compatible streaming responses
Problem
Several OpenAI-compatible gateways report the monetary cost of a request in the chat-completions stream, but rig drops it. Notably OpenCode Go emits a dedicated inference-cost SSE chunk after the usage chunk:
{choices: [], x-opencode-type: inference-cost, cost: 0.00006972, normalizedUsage: {...}}(the cost field is a string; some gateways send a number). Since StreamingCompletionChunk ignores unknown fields, the value is lost and callers cannot report real spend — they must either re-derive cost from token counts (approximate, requires per-model price tables that drift) or not report it.
Proposal
- Parse the top-level
costfield (string or number) inStreamingCompletionChunk. - Thread it through
CompatibleChunk→ the streaming loop →build_final_response, mirroring howusagealready flows. - Surface it on
StreamingCompletionResponse.costand propagate it intocompletion::Usage::costintoken_usage(), so agent runs and telemetry see it without extra plumbing.
OpenRouter already models provider-reported cost (usage.cost); this extends the same capability to OpenAI-compatible streams where the field is a sibling of usage rather than nested inside it.
No breaking changes: the new field defaults to None and existing deserialization is unaffected.
Source: 0xPlaygrounds/rig