第一个接口调用
本节用一个最小示例验证密钥与网络是否可用。
请求示例
curl https://api.anideaai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_NAME",
"messages": [{"role": "user", "content": "你好"}]
}'
响应示例
{
"id": "chatcmpl_xxxxx",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 20,
"total_tokens": 32
}
}
常见判断
- 返回包含
choices:调用成功 - 返回 401:密钥无效或未传递认证信息
- 返回 429:请求过快或额度不足
- 返回 500:服务异常,建议稍后重试
如需更详细解释,请查看 错误码说明。