API 管理
管理开放 API 密钥,支持外部系统调用文章生成接口
0 个密钥
Base URL
https://article.kou6.com
认证方式
所有 API 请求需要在请求头中携带 API Key
X-API-Key: cpak_xxxxxxxxxxxxxxxx
也支持通过 URL 参数传递:?api_key=cpak_xxx
接口列表
GET
/api/v1/business-types
获取可用的业务类型列表
响应示例
{
"success": true,
"data": [
{"id": "zjz", "name": "证件照测评", "description": "..."}
]
}
POST
/api/v1/generate
一键生成文章(核心接口),支持自动从关键词生成标题再生成文章
关于 auto_prepare 模式
什么时候需要设置 auto_prepare: true?
- 当系统中没有预先准备的 AI 标题时(首次使用或标题已用完)
- 需要自动从关键词库生成新标题再生成文章
工作流程:
auto_prepare: false(默认)- 直接使用现有的 AI 标题生成文章,如果没有标题则报错auto_prepare: true- 先从关键词生成 AI 标题,再用标题生成文章(全自动流程)
请求参数
business_type |
必填 | 业务类型 ID,如 "zjz" |
count |
可选 | 每个平台生成的文章数量,null=使用全部标题 |
concurrent |
可选 | 是否并发生成文章,默认 true |
auto_prepare |
可选 | 是否启用自动准备模式。设为 true 时自动从关键词生成标题,默认 false |
keyword_source |
可选 | 关键词来源:"core"(核心)/"expanded"(拓展)/"competition"(竞争),默认 "expanded"。仅 auto_prepare=true 时有效 |
category |
可选 | 分类ID,用于标题生成。仅 auto_prepare=true 时有效 |
platforms |
可选 | 指定平台列表,如 ["toutiao", "163"]。null=使用启用的平台,指定时无视启用状态 |
titles_per_keyword |
可选 | 每个关键词生成几个标题,默认 1。仅 auto_prepare=true 时有效 |
keywords_limit |
可选 | 限制用于生成标题的关键词数量,null=不限制。仅 auto_prepare=true 时有效 |
use_all_keywords |
可选 | 是否使用全部关键词(包括禁用的),默认 false。仅 auto_prepare=true 时有效 |
示例1:基础模式(使用现有标题)
适用场景:系统中已有 AI 标题,直接生成文章
curl -X POST "https://article.kou6.com/api/v1/generate" \
-H "X-API-Key: cpak_xxx" \
-H "Content-Type: application/json" \
-d '{
"business_type": "zjz",
"count": 5,
"concurrent": true
}'
成功响应 (HTTP 200)
{
"success": true,
"data": {
"total": 15,
"success_count": 15,
"fail_count": 0,
"results": [
{
"platform": "toutiao",
"title": "证件照测评:哪款App拍出来最好看",
"status": "success"
}
]
}
}
失败响应 - 没有可用标题 (HTTP 400)
{
"success": false,
"error": {
"code": "no_titles",
"message": "没有可用的 AI 标题",
"type": "business"
}
}
示例2:自动准备模式(从关键词全自动生成)
适用场景:没有现成标题,需要从关键词开始完整生成流程
curl -X POST "https://article.kou6.com/api/v1/generate" \
-H "X-API-Key: cpak_xxx" \
-H "Content-Type: application/json" \
-d '{
"business_type": "zjz",
"auto_prepare": true,
"keyword_source": "expanded",
"category": "qsy",
"titles_per_keyword": 2,
"keywords_limit": 50,
"use_all_keywords": true,
"platforms": ["toutiao", "163", "sohu"],
"concurrent": true
}'
成功响应 (HTTP 200)
{
"success": true,
"data": {
"total": 150,
"success_count": 148,
"fail_count": 2,
"prepare": {
"keyword_source": "expanded",
"keywords_count": 50,
"titles_generated": 100,
"use_all_keywords": true
},
"results": [
{
"platform": "toutiao",
"title": "证件照测评:哪款App拍出来最好看",
"status": "success"
},
{
"platform": "163",
"title": "证件照测评:哪款App拍出来最好看",
"status": "success"
}
]
}
}
失败响应 - 没有可用关键词 (HTTP 400)
{
"success": false,
"error": {
"code": "no_keywords",
"message": "没有可用的关键词",
"type": "business"
}
}
GET
/api/v1/articles
获取文章列表
请求参数
business_type |
必填 | 业务类型 ID |
platform |
可选 | 平台 ID |
status |
可选 | 状态:pending / published |
page |
可选 | 页码,默认 1 |
page_size |
可选 | 每页数量,默认 20 |
GET
/api/v1/stats
获取关键词和文章统计信息
请求参数
business_type |
必填 | 业务类型 ID |
响应示例
{
"success": true,
"data": {
"keywords": {
"core_count": 50,
"expanded_count": 93,
"ai_title_count": 150,
"platform_title_counts": {
"toutiao": 50,
"163": 50,
"sohu": 50
}
},
"articles": {
"pending_count": 15,
"published_count": 100,
"total_count": 115
}
}
}
平台ID列表
baijia | 百家号 |
toutiao | 今日头条 |
163 | 网易号 |
feng | 凤凰号 |
sohu | 搜狐号 |
zhihu | 知乎 |
sina | 新浪 |
qq | 腾讯 |
错误码
错误响应统一格式:{"success": false, "error": {"code": "xxx", "message": "xxx", "type": "auth|param|business"}}
认证错误 (HTTP 401)
| 错误码 | 说明 | 解决方案 |
|---|---|---|
missing_api_key | 缺少 API Key | 在请求头添加 X-API-Key |
invalid_api_key | API Key 无效或已禁用 | 检查 API Key 是否正确,或在管理页面确认未被禁用 |
参数错误 (HTTP 400, type: "param")
| 错误码 | 说明 | 解决方案 |
|---|---|---|
missing_business_type | 缺少 business_type 参数 | 请求体必须包含 business_type 字段 |
invalid_business_type | business_type 不存在 | 调用 /api/v1/business-types 获取有效值 |
invalid_platforms | 指定的平台不存在 | 检查 platforms 数组中的平台 ID 是否有效 |
invalid_keyword_source | keyword_source 值无效 | 只能是 "core"/"expanded"/"competition" |
业务错误 (HTTP 400, type: "business")
| 错误码 | 说明 | 解决方案 |
|---|---|---|
no_platforms | 没有启用的平台 | 在管理页面启用至少一个平台,或在请求中指定 platforms 参数 |
no_titles | 没有可用的 AI 标题 | 先生成标题,或设置 auto_prepare: true 自动生成 |
no_keywords | 没有可用的关键词 | 先添加关键词,或设置 use_all_keywords: true 使用禁用的关键词 |
title_generation_failed | 标题生成失败 | 检查 AI 服务是否正常,稍后重试 |
服务器错误 (HTTP 500)
| 错误码 | 说明 | 解决方案 |
|---|---|---|
internal_error | 内部错误 | 请联系管理员或稍后重试 |
共 0 条日志