📖 API 文档
🔑 认证方式
所有 API 请求需要在 Header 中携带 API Key:
Authorization: Bearer YOUR_API_KEY
📝 POST /api/register
用户注册,获取 API Key
curl -X POST https://yongmoai.com/api/register \
-H "Content-Type: application/json" \
-d '{"username":"test","email":"test@test.com","password":"123456"}'
| 参数 | 类型 | 必填 | 说明 |
| username | string | ✅ | 用户名(唯一) |
| email | string | ✅ | 邮箱 |
| password | string | ✅ | 密码(至少6位) |
📝 POST /api/generate
生成文案(需要 API Key)
curl -X POST https://yongmoai.com/api/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"keywords":"秋天的第一杯奶茶"}'
| 参数 | 类型 | 必填 | 说明 |
| keywords | string | ✅ | 关键词,决定文案主题 |
📊 GET /api/user/info
查看用户信息和余额
curl -X GET https://yongmoai.com/api/user/info \
-H "Authorization: Bearer YOUR_API_KEY"
❤️ GET /api/health
服务健康检查(无需认证)
curl https://yongmoai.com/api/health
返回示例:
{
"status": "ok"
}
📤 返回格式
所有接口返回 JSON 格式:
// 成功
{
"success": true,
"data": { ... }
}
// 失败
{
"error": "错误信息"
}
⚠️ 错误码
| 状态码 | 说明 | 处理建议 |
| 400 | 参数错误 | 检查请求参数 |
| 401 | API Key 无效或缺失 | 检查 Authorization Header |
| 402 | 余额不足 | 充值后重试 |
| 500 | 服务器错误 | 稍后重试 |
🐍 Python 示例
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://yongmoai.com"
# 生成文案
resp = requests.post(
f"{BASE_URL}/api/generate",
headers={"Authorization": f"Bearer {API_KEY}"},
json={"keywords": "秋天的第一杯奶茶"}
)
data = resp.json()
print(data["content"])
print("剩余次数:", data["balance"])
🟨 JavaScript 示例
const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://yongmoai.com';
// 生成文案
const resp = await fetch(`${BASE_URL}/api/generate`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ keywords: '秋天的第一杯奶茶' })
});
const data = await resp.json();
console.log(data.content);
console.log('剩余次数:', data.balance);
❓ 常见问题
Q: 如何获取 API Key?
A: 去 主站个人中心 → 点击「我的 API Key」→ 复制。
Q: 调用一次消耗多少?
A: 每次调用消耗 1 次余额,按套餐计费(¥9.9 起 / 100 次)。
Q: 余额用完怎么办?
A: 去 主站充值中心 充值,或 API 平台充值。
Q: API 有调用频率限制吗?
A: 目前没有硬性限制,但建议合理使用。
Q: 支持哪些文案类型?
A: 朋友圈、小红书、抖音、公众号、营销文案等。