脚本如下:
import openai
import os
# 设置 OpenAI API key
openai.api_key = os.environ["OPENAI_API_KEY"]
def get_balance():
"""
获取当前 OpenAI 可用余额
"""
balance = openai.Organization().retrieve().get("balance")
return balance
if __name__ == '__main__':
# 调用查询余额函数并输出结果
balance = get_balance()
print(f"当前 OpenAI 可用余额: ${balance}")