gptty icon indicating copy to clipboard operation
gptty copied to clipboard

[debug] Include analytics and usage statistics for the given API key

Open signebedi opened this issue 2 years ago • 2 comments

Provide users with insights into their API usage, response patterns, and other metrics to help them optimize their interactions with ChatGPT.

signebedi avatar Apr 06 '23 19:04 signebedi

We can define a callable using the logic below to display current API usage stats for the present day within the chat runtime.

import datetime
r = openai.api_requestor.APIRequestor()
resp = r.request("GET", f'/usage?date={datetime.datetime.now().strftime("%Y-%m-%d")}')
resp_object = resp[0]
resp_object.data # this object has all the info

requests_today = resp['data'][0]['n_requests'] # num requests
query_tokens_today = resp['data'][0]['n_context_tokens_total'] # query tokens
response_tokens_today = resp['data'][0]['n_generated_tokens_total'] # response tokens

signebedi avatar Apr 06 '23 19:04 signebedi

https://github.com/openai/openai-cookbook/blob/main/examples/How_to_handle_rate_limits.ipynb

signebedi avatar Apr 06 '23 19:04 signebedi