Get the remaining credits via the API

Take a look through the GitHub repo https://github.com/mc1903/PS-OpenAI and you will find the url in each of the functions under /Src/Public/

They use the [uri]$url = "https://api.openai.com/*" variable.

Just be aware that some of the totals return a value 100x the actual usage.

For instance my billing for yesterday was 0.05 (5 cents), but the https://api.openai.com/dashboard/billing/usage endpoint returns my total_usage as 4.562

{
	"object": "list",
	"daily_costs": [{
		"timestamp": 1674691200.0,
		"line_items": [{
				"name": "Base",
				"cost": 4.562
			},
			{
				"name": "FT Training",
				"cost": 0.0
			},
			{
				"name": "FT Inference",
				"cost": 0.0
			},
			{
				"name": "Embeddings",
				"cost": 0.0
			},
			{
				"name": "DALL-E API",
				"cost": 0.0
			}
		]
	}],
	"total_usage": 4.562
}

Where as the webpage shows it as:

image

Enjoy.
M

3 Likes