-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add support for querying billing details #591
base: master
Are you sure you want to change the base?
Conversation
83c32d7
to
3f01fbd
Compare
@mikeb26 Hey, thank you for the PR! Could you please provide an example program that uses this code? (Or integration test maybe?) It would greatly help reviewing this change |
@sashabaranov you bet. i'm using this in a CLI based chat tool i wrote. reference here: https://github.com/mikeb26/gptcli/blob/main/cmd/gptcli/main.go#L270 example output:
The PR also adds a unit test. |
8f923f5
to
ffd8a2d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #591 +/- ##
==========================================
+ Coverage 98.46% 98.74% +0.28%
==========================================
Files 24 27 +3
Lines 1364 1438 +74
==========================================
+ Hits 1343 1420 +77
+ Misses 15 10 -5
- Partials 6 8 +2 ☔ View full report in Codecov by Sentry. |
This commit adds support for querying daily costs usage information (as shown on https://platform.openai.com/usage). The implementation uses the public endpoing available at https://api.openai.com/dashboard/billing/usage However, note that this API is not documented in https://platform.openai.com/docs/api-reference and may thus be controversial to include. The API requires a browser session key and will explicitly reject requests made using an API key. (cherry picked from commit 2f53565) (cherry picked from commit 33269e5) (cherry picked from commit 26947c0) (cherry picked from commit 7cf5c6b) (cherry picked from commit 7669bf1) (cherry picked from commit 7943ad7)
It looks like the github action build environment for this repo uses a go 1.19.x environment which does not have time.DateOnly. Replace with local constant until this is upgraded. (cherry picked from commit 22886dd) (cherry picked from commit 5225542) (cherry picked from commit fbaa1f1) (cherry picked from commit 46091ed) (cherry picked from commit f477bcf) (cherry picked from commit dc6b161)
It looks like the github action build environment for this repo uses a go 1.19.x environment which does not have time.Compare(). Replace with time.Before() and time.After() instead. (cherry picked from commit a579ea8) (cherry picked from commit ffd8a2d) (cherry picked from commit 24eaaf5) (cherry picked from commit 6020e24) (cherry picked from commit 3abc47f) (cherry picked from commit a1f95a8)
3abc47f
to
121bab2
Compare
Describe the change
This PR adds support for querying daily costs usage information (the same as shown on https://platform.openai.com/usage).
Describe your solution
The implementation uses the public endpoint available at https://api.openai.com/dashboard/billing/usage However, note that this API is not documented in https://platform.openai.com/docs/api-reference and thus this PR may be controversial to merge. The API requires a browser session key and will explicitly reject requests made using an API key.
Tests
I've added positive and negative unit tests in billing_test.go and mock the dashboard OpenAPI endpoint following the test pattern that is already established in chat_test.go.
Additional context
I'm using this feature in a CLI based gpt tool that I wrote which enables the user to query billing information from within the tool itself rather than switch to a web browser (https://github.com/mikeb26/gptcli/blob/main/cmd/gptcli/main.go#L272).