The chat has stopped. The amount is still pending.
A support agent asks a chat app to summarize a report. Halfway through the first paragraph, she realizes she picked the wrong file. She clicks Stop. What should her team pay?
Support and Engineering have separate keys to our gateway, but we pay for both from one OpenRouter account. On Monday, Finance gets a $7.40 bill for Friday. Our records add up to $7.34. Can the interrupted summary explain the missing six cents?
Follow one request
Let's call the request R17. The application key tells us it belongs to Support. We save the rate we agreed to charge the team on Friday. As soon as OpenRouter sends the response headers, we also save its X-Generation-Id. We have all this before the first word appears.
{ "request_id": "R17", "cost_center": "Support", "rate_plan": "team-v1", "provider_account": "company-openrouter", "generation_id": "gen-example", "usage": null } Why keep two IDs? If the gateway tries a second model, Support still asked for one summary. OpenRouter may have two generations to bill us for. OpenRouter streaming reference
What does Stop do?
The browser reads from the gateway. The gateway reads from OpenRouter. When the browser disconnects, the gateway can ask OpenRouter to stop. The provider may already have generated text the agent never saw.
The browser has stopped receiving text. The gateway is still waiting for the cost.
Normally the final stream event tells us how many tokens we used and what they cost. For R17, that event never arrived. That's why the record says null. Writing zero would make the summary look free. OpenRouter usage accounting
Look up the receipt
A worker uses the saved generation ID to look up R17. Suppose OpenRouter reports four cents. At Friday's internal rate, the reported tokens cost Support three cents. The platform budget covers the remaining penny.
Those four cents are what OpenRouter charged our account. If we use our own cloud key, the cloud may also charge for output it generated after Stop. We'd need its bill to establish that cost. How OpenRouter accounts for cancelled chats
What if we process the receipt twice?
The worker writes the charges, then crashes before it marks the job done. On restart it picks up the same receipt. Does Support pay again?
For R17, we write two entries in one database transaction. The database enforces a different key for each entry.
- Provider expense — OpenRouter account and generation ID.
- Team charge — Gateway request ID.
When the worker retries, both entries already exist. If the gateway actually ran a second generation, that attempt has its own expense. We charge the team once we know which attempts its policy covers. We also save the policy that applied when the request began. A receipt that arrives today can explain yesterday's expense even if we promised to waive it.
If the receipt never arrives
Suppose the worker retries the lookup and still comes up empty. We could estimate the cost from the prompt and the part of the answer our gateway received. That estimate would miss any text the provider generated after the connection closed.
We agreed to charge Support for measured usage. When Finance closes Friday's books, R17 still has an unknown cost, so we leave it off Support's bill. The six-cent gap tells us how much we still need to explain across both teams. It can't tell us what this one summary cost.
Back to Friday’s bill
With R17's receipt in hand, Finance can account for $7.38 of Friday's $7.40.
| Friday's books | Amount |
|---|---|
| Provider expenses already recorded | $7.34 |
| OpenRouter's charge for R17 | $0.04 |
| Amount still unallocated | $0.02 |
| OpenRouter daily total | $7.40 |
Support owes three cents. R17 explains four of the six missing cents on the provider bill. The other two still need a receipt before we can assign them to anyone.
