openai-php / client

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

Retrieve RateLimits #176

Closed krio-rogue closed 1 year ago

krio-rogue commented 1 year ago

Hi. When requesting https://api.openai.com/v1/chat/completions in streaming mode, the HTTP response contains a set of headers with service information like X-Ratelimit-Remaining-Tokens:.

Is it possible to add a method to retrieve all headers from stream? Or make the $response property in the OpenAI\Responses\StreamResponse class public?

Jafo232 commented 1 year ago

I agree. We need this for things like calculating how many tokens were used.

Jafo232 commented 1 year ago

I submitted this PR that would accomplish this: https://github.com/openai-php/client/pull/187

gehrisandro commented 1 year ago

You can now use the latest release which gives you access to the header / meta information on every response: https://github.com/openai-php/client#meta-information