以下のようにする
import requests
OPENAI_API_KEY = "sk-*****"
headers = {
'Authorization': f'Bearer {OPENAI_API_KEY}',
}
response = requests.get('https://api.openai.com/dashboard/billing/credit_grants', headers=headers)
response_json = response.json()
取得できるのは以下のイメージ
{'object': 'credit_summary', 'total_granted': 18.0, 'total_used': 0.18462800000000001, 'total_available': 17.815372, 'grants': {'object': 'list', 'data': [{'object': 'credit_grant', 'id': '*****', 'grant_amount': 18.0, 'used_amount': 0.18462800000000001, 'effective_at': 1675641600.0, 'expires_at': 1685577600.0}]}}
この場合、無料分の18ドルがtotal_grantedにあり、そのうち、使用分0.18ドルがtotal_usedに記載されている