请求头信息:
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Accept: application/json
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称(gpt4) |
messages | array | 是 | 对话消息列表 |
temperature | number | 否 | 生成温度(0-2,默认0.7) |
max_tokens | number | 否 | 最大输出token数 |
curl -X POST "https://cross.cybermagi.space/api/v1/chat" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt4", "messages": [{"role": "user", "content": "帮我写一段电商产品描述"}]}'
# Python example
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://cross.cybermagi.space"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"target": "gpt4"
}
response = requests.post(
f"{BASE_URL}/api/v1/chat",
json=data,
headers=headers
)
result = response.json()
print(result)
{
"success": true,
"data": {
"model": "gpt4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "这是GPT-4模型返回的AI响应内容..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 45,
"completion_tokens": 128,
"total_tokens": 173
}
},
"request_id": "req_chat_gpt4_en_5"
}
点击返回主页,获取API密钥并在线测试