openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.6k stars 468 forks source link

Code example request: How to get promptTokens & completionTokens on Streamed output requests #212

Closed mycloudvip closed 10 months ago

mycloudvip commented 10 months ago

Your page notes and instructions do not fully describe this approach.

Kindly consider adding a code example, since I need it to track API usage.

Thanks

gehrisandro commented 10 months ago

Hi @mycloudvip

OpenAI does not provide this information on the stream response. See here: https://platform.openai.com/docs/api-reference/chat/streaming