Skip to content

Instantly share code, notes, and snippets.

@airyland
Last active March 8, 2023 01:52
Show Gist options
  • Save airyland/1110aee75c17023e62c1c0cca126dfc5 to your computer and use it in GitHub Desktop.
Save airyland/1110aee75c17023e62c1c0cca126dfc5 to your computer and use it in GitHub Desktop.
ChatGPT Bill Caculator
// https://platform.openai.com/account/usage
// Run code in the console to avoid bankruptcy
var $labels = document.querySelectorAll('.usage-table .expn-title .expn-icon')
$labels[0].click()
var $items = document.querySelectorAll('.expn.expanded .expn-content .expn-icon')
for (let i = 0; i < $items.length; i++) {
$items[i].click()
}
var $sum = document.querySelectorAll('.sum')
let count = 0
for (let i = 0; i < $sum.length; i++) {
const _count = $sum[i].innerText.replace('tokens', '').replace(/,/g, '').trim()
count += _count * 1
}
console.log('Date:', document.querySelector('.usage-day-select').innerText)
console.log('Tokens:', count)
console.log('Bill:', '$' + new Intl.NumberFormat().format(count / 1000 * 0.002))
@yunyu950908
Copy link

不理解有什么区别

curl --location --request GET 'https://api.openai.com/dashboard/billing/credit_grants' \
--header 'Authorization: Bearer {{API_KEY}}' \
--header 'Host: api.openai.com' \

官网直接扒接口是一样的吧

{
  "object": "credit_summary",
  "total_granted": 18.0,
  "total_used": 13.34386,
  "total_available": 4.656140000000001,
  "grants": {
    "object": "list",
    "data": [
      {
        "object": "credit_grant",
        "id": "2e45daf7-d9e0-41ed-9bee-3a93eaf23ec2",
        "grant_amount": 18.0,
        "used_amount": 13.34386,
        "effective_at": 1671062400.0,
        "expires_at": 1680307200.0
      }
    ]
  }
}

@airyland
Copy link
Author

airyland commented Mar 6, 2023

@yunyu950908 这个数据是滞后的。turbo model 每天调用的费用并没有计算出来。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment