Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
signebedi opened this issue Apr 6, 2023 · 2 comments
Open

Comments

@signebedi
Copy link
Owner

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

@signebedi
Copy link
Owner Author

signebedi commented Apr 6, 2023

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
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant