I wnat check Credit remaining by api

i wnat check Credit remaining by api
just last Credit remaining
link or example request

i wnat check Credit remaining by api
just last Credit remaining
link or example request

5 Likes

You cannot get your current OpenAI account balance via API for the AI models.
It’s just how the system is and maybe this will be coming in the future but as of now the only way is to log into the account and get the numbers from there.

1 Like

Thank You
It’s very Useful , I hope access soon for developers

2 Likes

there is no api, of course if you just open the console on openai page it is using an api… but better to tell the user to go to OpenAI page IMO

It would be very nice to have this! :slight_smile:

I found a possible workaround. There’s a function in the loaded JS on the billing page:
var f = ((null === t || void 0 === t ? void 0 : t.total_available) || 0) - ((null === t || void 0 === t ? void 0 : t.pending_usage) || 0);

Balance = total_available - pending_usage

Where total_available is from GET https:// api.openai. com /dashboard/billing/credit_grants
and pending_usage is from GET https:// api.openai. com /dashboard/billing/pending_usage

Note that pending_usage is in cents, so divide it by 100

I’d love to have a proper api for this for community driven apps giving visibility for donations towards openai costs.

The workaround doesn’t actually work. It gives a 403 forbidden error with the details:

{
    "error": {
        "message": "Your request to GET /dashboard/billing/credit_grants must be made with a session key (that is, it can only be made from the browser). You made it with the following key type: secret.",
        "type": "server_error",
        "param": null,
        "code": null
    }
}

It’s only possible with a session key rather than an api key :(. It’s a bit harder to get this since it comes from a login flow with the oauth provider.

Please implement an api endpoint for this. I really want to create a way for people to see how much credit my tool has so they can decide to contribute towards credits.

If you want people to create tools for the good of humanity that is, otherwise, I’ll get back to my monetization ideas

Yeah, please implement this quickly. It should not be too hard. In the beginning a simple REST URL could do the trick, so it is available more early.

Thanks!

1 Like

+1
Checking the remaining credit through the API could lead to many enhancements in our code, especially for projects running long tasks.

1 Like

It would be really nice to have an API to check the balance. Pretty please?