cURL 示例
cURL 是一个命令行工具,用于发送 HTTP 请求。以下是使用 cURL 调用 AI2API 的常见示例。
基础对话请求
curl -X POST https://api.ai2api.top/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{"role": "user", "content": "你好"}
]
}'流式响应
curl -X POST https://api.ai2api.top/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "讲个故事"}],
"stream": true
}'多轮对话
curl -X POST https://api.ai2api.top/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "你是一个专业的编程助手"},
{"role": "user", "content": "如何用 Python 读取 CSV 文件?"}
],
"temperature": 0.7,
"max_tokens": 500
}'获取模型列表
curl https://api.ai2api.top/v1/models \
-H "X-API-Key: YOUR_API_KEY"查看账户余额
curl https://api.ai2api.top/api/v1/balance \
-H "Authorization: Bearer YOUR_JWT_TOKEN"