openai / openai-realtime-api-beta

Node.js + JavaScript reference client for the Realtime API (beta)
MIT License
531 stars 106 forks source link

Populating `tokens` in `conversation.updated` #32

Open svapnil opened 1 week ago

svapnil commented 1 week ago

Hey folks,

For measuring usage of the OpenAI Realtime API it's important to measure tokens used. Unfortunately, the conversation.updated event doesn't contain token counts, for reference, you can receive it in the response.done event in the API: https://platform.openai.com/docs/api-reference/realtime-server-events/response-done

Is there a recommendation around this? AFAIK conversation.updated is built from these events. Wondering if people have alternative ways of getting this information from this library.

khorwood-openai commented 1 week ago

You can use;

client.realtime.on('server.response.done', (event) => {
  // track usage
});

Did you need something more deeply integrated?