AI 模型 API
AI 模型 API 提供模型列表、配置、使用统计等功能。
获取模型列表
接口地址
GET /api/ai-models响应示例
json
{
"code": 200,
"msg": "获取成功",
"data": {
"models": [
{
"model_id": "deepseek-chat",
"name": "DeepSeek",
"description": "强大的中文理解和生成能力",
"type": "chat",
"context_length": 32000,
"pricing": {
"input_tokens": 0.001,
"output_tokens": 0.002
},
"features": ["streaming", "long_context"],
"status": "active"
},
{
"model_id": "kimi-chat",
"name": "Kimi",
"description": "优秀的长文本生成能力",
"type": "chat",
"context_length": 128000,
"pricing": {
"input_tokens": 0.0015,
"output_tokens": 0.003
},
"features": ["streaming", "ultra_long_context"],
"status": "active"
},
{
"model_id": "moonshot-chat",
"name": "Moonshot",
"description": "快速响应,适合短篇内容",
"type": "chat",
"context_length": 8000,
"pricing": {
"input_tokens": 0.0008,
"output_tokens": 0.0015
},
"features": ["streaming", "fast_response"],
"status": "active"
}
]
}
}获取模型详情
接口地址
GET /api/ai-models/:model_id响应示例
json
{
"code": 200,
"msg": "获取成功",
"data": {
"model_id": "deepseek-chat",
"name": "DeepSeek",
"description": "强大的中文理解和生成能力",
"type": "chat",
"context_length": 32000,
"max_tokens": 4000,
"pricing": {
"input_tokens": 0.001,
"output_tokens": 0.002
},
"features": ["streaming", "long_context"],
"parameters": {
"temperature": {
"min": 0.0,
"max": 1.0,
"default": 0.7
},
"top_p": {
"min": 0.1,
"max": 1.0,
"default": 0.9
},
"max_tokens": {
"min": 100,
"max": 4000,
"default": 2000
}
},
"status": "active"
}
}获取使用统计
接口地址
GET /api/ai-models/usage查询参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| start_date | string | 否 | 开始日期(YYYY-MM-DD) |
| end_date | string | 否 | 结束日期(YYYY-MM-DD) |
| model_id | string | 否 | 模型 ID |
响应示例
json
{
"code": 200,
"msg": "获取成功",
"data": {
"period": {
"start_date": "2026-02-01",
"end_date": "2026-02-09"
},
"summary": {
"total_tokens": 125000,
"total_cost": 150.50,
"total_requests": 50
},
"by_model": [
{
"model_id": "deepseek-chat",
"model_name": "DeepSeek",
"tokens_used": 80000,
"cost": 96.00,
"requests": 30
},
{
"model_id": "kimi-chat",
"model_name": "Kimi",
"tokens_used": 45000,
"cost": 54.50,
"requests": 20
}
],
"by_date": [
{
"date": "2026-02-09",
"tokens_used": 15000,
"cost": 18.00,
"requests": 5
}
]
}
}获取配额信息
接口地址
GET /api/ai-models/quota响应示例
json
{
"code": 200,
"msg": "获取成功",
"data": {
"total_quota": 500000,
"used_quota": 125000,
"remaining_quota": 375000,
"quota_type": "monthly",
"quota_period": {
"start": "2026-02-01T00:00:00Z",
"end": "2026-03-01T00:00:00Z"
},
"plan": {
"plan_id": "professional",
"plan_name": "专业版",
"monthly_quota": 500000
}
}
}错误码
| 错误码 | 说明 |
|---|---|
| 5001 | 模型不存在 |
| 5002 | 模型不可用 |
| 5003 | 配额不足 |
| 5004 | 参数超出范围 |
| 5005 | 功能不支持 |
最佳实践
模型选择
根据场景选择模型:
技术文章:
- 推荐:DeepSeek
- 原因:强大的中文理解能力
长篇内容:
- 推荐:Kimi
- 原因:支持超长上下文
短篇快速:
- 推荐:Moonshot
- 原因:快速响应
成本优化
降低 Token 消耗:
- 精简要求: 避免冗余描述
- 合理设置长度: 不要设置过长
- 多轮优化: 逐步完善,避免一次性生成
- 选择合适模型: 根据需求选择性价比高的模型
配额管理
合理使用配额:
- 监控使用: 定期查看使用统计
- 预测消耗: 根据历史数据预测
- 及时充值: 配额不足时及时充值
- 优化使用: 优化使用方式,降低消耗
