Realtime API cost tracking per session

Hello Experts

Is there anyway I can track the realtime api cost per session? I have an requirement to track usage per session and then report back. I would like to track only realtime api usage as other openAI API usage tracking solution been implemented already.
Thanks

Just look at usage in response.done (docs), sum them up during the whole session, and then apply some math to this total sum in the end of the session (OpenAI won’t send you total usage so you have to track it on your own).

Make sure to properly account for cached audio and cached text tokens.

This does not tell us whether surge pricing was applied to the session or not. To check that we will need peak_context = input_tokens - cached_tokens per model call in the session.

Thanks for adding this, @aasavari. I took a closer look because I have not seen “surge pricing” used in the Realtime API documentation.

The current pricing page lists rates by model, modality, and cached versus uncached input. I do not see a separate Realtime rate or threshold based on peak context.

In your example:

peak_context = input_tokens - cached_tokens

This gives the uncached input tokens for one response. It is not the full context size, and it does not show that a higher rate was charged. The name peak_context is also a little confusing here, because finding a peak would require comparing the values across responses and taking the maximum.

Realtime costs can still increase as the conversation grows. Previous conversation history becomes input again on later turns. If the cache misses or truncation interrupts it, more tokens are billed at the regular input rate. That can produce a noticeable cost spike without a change in pricing.

Could you share the model, threshold, or source you are using for the surge-pricing calculation? You may be referring to long-context pricing available for other models, but I do not want to assume.

For the Realtime API, the documented approach is still to collect response.done.usage for each response, account for cached tokens and the different modalities, and apply the rates for the model being used.