🔌 开发者 API
AI家园开放部分 API 接口,供开发者集成文章发布、数据查询等功能。使用 X-API-Key 认证,简单易接入。
REST JSON API
认证 X-API-Key
限速 60次/分钟
🔑 认证方式
X-API-Key Header 认证
在请求头中添加 X-API-Key: 你的密钥 即可。密钥可在个人中心查看,或联系管理员获取。
// 认证示例
fetch('https://spark1.cn/api/articles', {
headers: {
'X-API-Key': 'your-api-key-here',
'Content-Type': 'application/json'
}
})
💡 注意:标记为「公开」的接口无需认证即可调用。需要写入操作的接口(如发布文章)必须携带有效的 API Key。
📖 公开接口(无需认证)
文章与内容
GET
/api/articles
获取已发布文章列表,支持分页、分类筛选和关键词搜索。
pagenumber页码(默认 1)
limitnumber每页条数(默认 20,最大 50)
categorystring分类 slug
searchstring搜索关键词
GET
/api/articles/:slug
获取单篇文章详情,包含完整内容和元数据。
GET
/api/search?q=关键词
全站搜索,返回文章、频道、工具等匹配结果。
GET
/api/qa/questions
获取星火问问的问题列表,支持分页和分类。
GET
/api/experience/posts
获取经验分享墙的帖子列表。
GET
/api/community/daily-news
获取 AI 管家每日早报(科技/AI 行业动态摘要)。
GET
/api/community/daily-question
获取每日一问(每天一个 AI 知识问答)。
GET
/api/marketplace
获取 AI 模板工坊的模板列表(已审核通过的),支持分类和搜索。
categorystring分类:writing/coding/analysis/creative/education/business/life/scenario/other
searchstring搜索关键词
sortstring排序:newest/popular/price_low/price_high
GET
/api/marketplace/categories
获取模板市场的所有分类列表。
GET
/api/skills
获取技能市场的技能列表,支持分类、搜索和排序。
categorystring分类筛选
searchstring搜索关键词
sortstring排序:downloads/rating/newest
difficultystring难度:入门/进阶/高级
GET
/api/ai-tools/list
获取所有 AI 工具的列表(82 个工具,含名称、描述、积分价格)。
GET
/api/ai-tools/stats
获取 AI 工具全局使用统计(总使用次数、今日次数、用户数)。
GET
/api/toolchains
获取场景工具链列表(写作配图、短视频、健康日报等多步编排工具)。
GET
/api/huangli
获取老黄历信息(当日宜忌、吉神凶煞等传统文化数据)。
GET
/api/weather/current?lat=&lon=
获取当前天气信息,支持经纬度或 IP 定位。
GET
/api/weather/warning?lat=&lon=
获取气象预警信息(台风/暴雨/高温等灾害预警)。
🔒 认证接口(需要 API Key)
POST
/api/publish
发布文章到平台。支持 Markdown 格式,文章将进入审核流程,通过后自动发布。
titlestring文章标题(必填)
contentstringMarkdown 正文(必填)
categorystring分类 slug(可选)
tagsstring[]标签数组(可选)
cover_imagestring封面图 URL(可选)
// 发布文章示例
const res = await fetch('https://spark1.cn/api/publish', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: '我的第一篇 API 文章',
content: '# 标题\n\n这是正文内容...',
tags: ['AI', '技术']
})
});
const data = await res.json();
// { success: true, article: { id, slug, status: 'pending_review' } }
POST
/api/ai-tools
调用 AI 工具(82 个工具可选)。消耗积分,每个工具首次免费。
toolstring工具 ID(如 title-gen, summarize, code-helper 等)
inputstring输入内容
optionsobject工具特定选项(如风格、数量等)
// 调用 AI 工具示例:生成爆款标题
const res = await fetch('https://spark1.cn/api/ai-tools', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
tool: 'title-gen',
input: '2026年最值得学习的AI技术',
options: { count: 5, platform: '公众号' }
})
});
⚡ 限速与配额
| 接口类型 | 限速 | 说明 |
|---|---|---|
| 通用 API | 100 次/分钟 | 按 IP 计数 |
| 认证接口 | 10 次/分钟 | 登录/注册相关 |
| AI 工具调用 | 按工具独立限速 | 每个工具首次免费 |
| 工具链选链 | 12 次/分钟 | 需登录,24h 缓存 |
📌 超出限速时返回
429 Too Many Requests,响应体包含错误信息和重试建议。
📋 响应格式
成功响应
{
"success": true,
"data": { ... } // 或 "articles", "templates" 等具体字段
}
错误响应
{
"error": "错误描述信息"
}
常见 HTTP 状态码
200请求成功
400参数错误(缺少必填字段或格式不正确)
401未认证(缺少或无效的 API Key)
429请求过于频繁,请稍后重试
500服务器内部错误
🚀 快速接入
// Node.js 完整示例:获取文章列表 + 调用AI工具
// 1. 获取最新文章(公开接口,无需认证)
const articles = await fetch('https://spark1.cn/api/articles?page=1&limit=5')
.then(r => r.json());
console.log(`最新 ${articles.articles.length} 篇文章`);
// 2. 调用 AI 工具(需认证)
const result = await fetch('https://spark1.cn/api/ai-tools', {
method: 'POST',
headers: {
'X-API-Key': process.env.SPARK1_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
tool: 'code-helper',
input: 'console.log("Hello World")',
options: { action: 'explain', language: 'JavaScript' }
})
}).then(r => r.json());
console.log(result.result);