一、問題來源
ChatGPT不斷強大,用得人多。目前為止OpenAI還是會給新注冊的用戶送5美金,因此大部分應用還是直接用這類新注冊的賬號來調用API,擼點羊毛。
作為開發(fā)者,比較關注的一個問題,如何通過接口實時查詢OpenAI賬號的余額?
不過比較遺憾,目前OpenAI官方并沒有提供直接的API來查詢。
二、幾個查詢余額的方案
1、后臺直接查詢
最原始的可以通過OpenAI官方的后臺查看,官方鏈接:https://platform.openai.com/account/usage
這種方式適合普通用戶使用,不過前提是需要登錄(免不了需要梯子。。。),對開發(fā)者來說沒什么太大意義。
2、隱藏的接口【現(xiàn)在不好用了】
后面有些朋友發(fā)現(xiàn)了一個隱藏的接口:https://api.openai.com/dashboard/billing/credit_grants
直接GET請求,Header中帶上Token(API key)就可以了
之前接口可以直接返回如下結果:
{
"object": "credit_summary",
"total_granted": 18.0,
"total_used": 0.6284545,
"total_available": 17.3715455,
"grants": {
"object": "list",
"data": [{
"object": "credit_grant",
"id": "bdb804***********************ff0132",
"grant_amount": 18.0,
"used_amount": 0.6284545,
"effective_at": 1673740800.0,
"expires_at": 1682899200.0
}]
}
}
但是現(xiàn)在不行了,需要session key才行,所以這個方法也不合適了。
3、最新的方案
通過抓包分析,可以用另外的一些接口來實現(xiàn)
賬單訂閱信息:https://api.openai.com/v1/dashboard/billing/subscription
這個接口也是GET請求,Header中帶上Token(API key)就可以了
返回結果如下:
{
"object": "billing_subscription",
"has_payment_method": true,//OpenAI賬號是否已經(jīng)綁卡,綁卡后有120美金的額度
"canceled": false,
"canceled_at": null,
"delinquent": null,
"access_until": 1690848000,//key到期時間
"soft_limit": 1600000,
"hard_limit": 2000000,
"system_hard_limit": 2000000,
"soft_limit_usd": 96.0,
"hard_limit_usd": 120.0,
"system_hard_limit_usd": 120.0,
"plan": {
"title": "Pay-as-you-go",
"id": "payg"
},
"account_name": "xxdwe",
"po_number": null,
"billing_email": null,
"tax_ids": null,
"billing_address": {
},
"business_address": null
}
賬單明細:https://api.openai.com/v1/v1/dashboard/billing/usage?start_date=2023-05-01&end_date=2023-05-08
這個接口也是GET請求,Header中帶上Token(API key)就可以了,查詢指定日期范圍內的使用明細
返回結果如下:
{
"object": "list",
"daily_costs": [
{
"timestamp": 1681948800.0,
"line_items": [
{
"name": "Instruct models",
"cost": 0.0
},
{
"name": "Chat models",
"cost": 0.0
},
{
"name": "GPT-4",
"cost": 0.0
},
{
"name": "Fine-tuned models",
"cost": 0.0
},
{
"name": "Embedding models",
"cost": 0.0
},
{
"name": "Image models",
"cost": 0.0
},
{
"name": "Audio models",
"cost": 0.0
}
]
}
],
"total_usage": 5956.9476//合計費用,單位美分
}
結合這兩個接口就可以達到查詢余額的目標了!文章來源:http://www.zghlxwxcb.cn/news/detail-454857.html
三、在線網(wǎng)頁查詢
基于第三個方案,我做了一個在線的查詢站點,方便大家使用,也不需要加梯子使用了。
https://gptbill.lonlie.cn/文章來源地址http://www.zghlxwxcb.cn/news/detail-454857.html
到了這里,關于免登錄在線查詢OpenAI ChatGPT API key余額的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!