调用openai

调用openai代码成功,但是没有调用额度

import openai
import requests

# 设置 OpenAI API 密钥
openai.api_key = "sk-w6FiFg0JiBmn5eQCzD9XRy0Sqi9vfoZLxdyPdX3XaRT3BlbkFJLNOrDZtmNxFowW1ZrifnotzGmHxz3AR-_CabNFlmQA"

# 配置代理
proxies = {
    "http": "http://xxx.xxx.xxx.xxx:xxxx",
    "https": "http://xxx.xxx.xxx.xxx:xxxx"
}

# 定义请求 headers
headers = {
    "Authorization": f"Bearer {openai.api_key}",
    "Content-Type": "application/json"
}

# 测试调用 OpenAI Chat API
response = requests.post(
    "https://api.openai.com/v1/chat/completions",
    headers=headers,
    json={
        "model": "gpt-3.5-turbo",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Hello, world!"}
        ],
        "max_tokens": 50
    },
    proxies=proxies
)

print(response.json())

 

返回

{'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

 

posted @ 2024-09-25 11:06  testway  阅读(16)  评论(0编辑  收藏  举报