* fix(realtime): count realtime turns toward TPM limits and refuse turns over the limit
Each response.done charges its tokens to the session's key, team, user, end user, tag and per-key model TPM windows before the client sees it. Each response.create is checked first, read only. A turn over a limit, or one whose limits cannot be checked, gets an error event, is not forwarded, and the session stays open. A response the provider starts on its own over the limit is cancelled. The close still charges no tokens, so session TPM equals the sum of its turns
* fix(realtime): apply each turn's TPM charge before the next turn is checked
With Redis, the turn charge rode the socket's post-call batch, which flushes up to a second later, so a response.create sent right after response.done was admitted over the limit
* fix(realtime): never cancel a turn on a call the proxy only listens to
* fix(realtime): count a response the provider reports done twice only once
OpenAI sends a second response.done with the same id and usage when the caller starts speaking right after a reply finishes, so charging every event counted that reply twice toward the TPM limit
* fix(realtime): stop over-limit turns on every provider and count transcription tokens
Check the limits on every response.created, so a rejected create earns no free turn. A provider that cannot cancel a response now has its session ended before the output reaches the client
Count token-billed transcription turns, retry a failed turn charge before the next check, check deployment capacity per turn, and find per-model limits by the router's model group so aliases are covered. Bedrock guardrail replies are checked and its final usage is charged at close
* fix(realtime): stop output after a session ends over its token limit
Frames the provider already sent no longer reach the client once the proxy ends a session over its TPM limit, and their usage still counts. Bedrock text turns over the limit now end the session the same way audio turns do
* fix(realtime): cancel a refused response by its id
A response outside the default conversation is only cancelled when the cancel names it. Move the Redis-backed turn test to the integration suite and give the session test helpers precise frame types
* fix(realtime): count realtime sessions toward deployment capacity
* fix(realtime): stop idle sessions holding TPM and charge each turn to capacity
An open realtime session no longer reserves part of the limit, and each finished turn now counts toward deployment capacity as it arrives. A refused turn the provider cannot cancel still reports its tokens before the session closes
* fix(realtime): send one refusal per turn and stop reporting limit-ended sessions as failures
* fix(realtime): close at the refusal, gate Gemini text turns, and charge agent windows per turn
* fix(realtime): check and charge project TPM per turn and keep capacity on the turn's model group
A realtime turn is now checked against the project's ITPM and OTPM windows
before it starts and charged with its actual usage, cached input excluded.
A refusal no longer outlives a later check that passes. Deployment capacity
charges a session's close to the model group its turns used, and usage a
provider reports only at close is charged before the session-end log
* fix(realtime): write per-turn project charges to Redis at once and let started turns run when limits cannot be read
Project ITPM and OTPM charges for a realtime turn skip the request's Redis batch, so a back-to-back
response.create on another worker sees them. A turn OpenAI or Azure started on its own is no longer
cancelled when the limiter cannot be read, matching Gemini and Bedrock. The fake Redis test now checks
that its accept thread stops instead of timing a test
* fix(realtime): log a turn before counting it, refuse started turns when fail-closed limits cannot be read, and hold back a refused turn's output
* fix(realtime): keep a refused turn's finished output and conversation items from the client
* fix(bedrock): wait for a refused turn's usage when the client side ends during the over-limit close
---------
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>