ChatGPT API 开发指南
快速接入
# Python 示例代码
import openai
client = openai.OpenAI(
api_key="your-api-key-here"
)
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)定价说明 (Pricing)
| 模型 (Model) | 输入价格 (Input) | 输出价格 (Output) |
|---|---|---|
| GPT-4 Turbo | $10.00 / 1M tokens | $30.00 / 1M tokens |
| GPT-4o | $5.00 / 1M tokens | $15.00 / 1M tokens |
| GPT-3.5 Turbo | $0.50 / 1M tokens | $1.50 / 1M tokens |
* 价格可能会随时间调整,请以 OpenAI 官网为准。1000 tokens 大约等于 750 个英文单词或 400-500 个汉字。
申请步骤
- 登录 OpenAI Platform。
- 点击右上角头像,选择 "Dashboard"。
- 在左侧菜单点击 "API keys"。
- 点击 "Create new secret key",复制并保存你的 Key(只会显示一次)。
- 在 "Billing" 设置中绑定信用卡并充值余额(API 使用是按量付费,不包含在 Plus 订阅中)。