帮我写一个chatgpt key余额查询python脚本
当你想要查询ChatGPT的余额时,你可以使用以下的Python脚本:
import openai
openai.api_key = "<你的API密钥>"
def get_chatgpt_balance():
balance = openai.Account.retrieve().balance
return balance
if __name__ == "__main__":
balance = get_chatgpt_balance()
print(f"ChatGPT余额: ${balance/100:.2f}")
请确保你已经安装了OpenAI的Python SDK(openai),可以使用pip install openai来进行安装。
在脚本中,你需要将<你的API密钥>替换成你的OpenAI API密钥,你可以在OpenAI的网站上找到它。
运行脚本后,它会打印出你ChatGPT的余额,以美元为单位。注意,余额的单位是以“cents”为基础,所以在打印时我们将其除以100转换为美元。
原文地址: https://www.cveoy.top/t/topic/hPPd 著作权归作者所有。请勿转载和采集!