API 文档
REST API 接口详细说明
API 概述
AI Prompt Studio 提供 RESTful API 接口,允许第三方应用程序与系统进行集成。
基础信息
- 基础URL:
http://localhost:8080/api/v1 - 数据格式:JSON
- 字符编码:UTF-8
- HTTP方法:GET, POST, PUT, DELETE
响应格式
{
"code": 200,
"message": "success",
"data": {...}
}
身份验证
API 使用 Token 进行身份验证。
获取 Token
POST /auth/token
{
"username": "your_username",
"password": "your_password"
}
使用 Token
在请求头中添加:
Authorization: Bearer your_token_here
提示词接口
管理提示词的相关接口。
获取提示词列表
GET /prompts
参数:
page- 页码(可选,默认1)limit- 每页数量(可选,默认20)category- 分类ID(可选)type- 类型(text/image/video,可选)
获取单个提示词
GET /prompts/{id}
创建提示词
POST /prompts
{
"title": "提示词标题",
"content": "提示词内容",
"type": "text",
"category_id": 1,
"tags": ["标签1", "标签2"]
}
更新提示词
PUT /prompts/{id}
删除提示词
DELETE /prompts/{id}
分类接口
管理提示词分类的相关接口。
获取分类列表
GET /categories
创建分类
POST /categories
{
"name": "分类名称",
"description": "分类描述",
"parent_id": null
}
更新分类
PUT /categories/{id}
删除分类
DELETE /categories/{id}
搜索接口
提示词搜索相关接口。
全文搜索
GET /search
参数:
q- 搜索关键词(必需)type- 类型筛选(可选)category- 分类筛选(可选)tags- 标签筛选(可选)page- 页码(可选,默认1)limit- 每页数量(可选,默认20)
高级搜索
POST /search/advanced
{
"query": "搜索关键词",
"filters": {
"type": ["text", "image"],
"category_ids": [1, 2, 3],
"tags": ["标签1", "标签2"],
"date_range": {
"start": "2024-01-01",
"end": "2024-12-31"
}
},
"sort": {
"field": "created_at",
"order": "desc"
},
"page": 1,
"limit": 20
}
示例代码
以下是一些常用的 API 调用示例。
JavaScript 示例
// 获取提示词列表
fetch('http://localhost:8080/api/v1/prompts', {
headers: {
'Authorization': 'Bearer your_token_here',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data));
Python 示例
import requests
headers = {
'Authorization': 'Bearer your_token_here',
'Content-Type': 'application/json'
}
response = requests.get(
'http://localhost:8080/api/v1/prompts',
headers=headers
)
data = response.json()