本文档基于当前代码(Gin + /api/v1 路由)整理,所有成功响应统一格式:
{
"code": 0,
"data": { ... },
"message": "" // 可选
}失败会返回 HTTP 4xx/5xx,body 形如:{"code":400,"message":"错误描述"}。
- 服务基址:
http://localhost:4000 - API 前缀:
/api/v1 - 认证:当前无鉴权(TODO)
- 跨域:允许
http://localhost:3000、http://localhost:3001,并已开启Access-Control-Allow-Credentials: true。
GET /health→{ "status": "ok", "service": "ads-creative-platform" }GET /api/v1/ping→{ "message": "pong" }
POST /api/v1/copywriting/generate- Body:
{ "product_name": "苹果电脑" }- 成功返回:
{
"code": 0,
"data": {
"task_id": "uuid",
"cta_candidates": ["立即购买", "..."],
"selling_point_candidates": ["轻薄", "..."]
}
}POST /api/v1/copywriting/confirm- Body(至少要有一个卖点或编辑卖点):
{
"task_id": "uuid",
"selected_cta_index": 0,
"selected_sp_indexes": [0,1],
"edited_cta": "可选,覆盖候选",
"edited_sps": ["可选,覆盖选中卖点"],
"product_image_url": "可选",
"style": "可选",
"num_variants": 2,
"formats": ["1:1"]
}- 返回:
{ "code":0, "data": { "task_id": "...", "status": "queued|draft|..." } }
POST /api/v1/creative/generate- Body:
{
"title": "商品标题",
"selling_points": ["亮点1","亮点2"],
"product_image_url": "可选,商品图 URL",
"formats": ["1:1","16:9"],
"style": "可选",
"cta_text": "立即购买",
"num_variants": 2
}- 返回:
{ "task_id": "uuid", "status": "queued|draft|..." }
POST /api/v1/creative/start- Body:
{ "task_id": "uuid" } - 返回:
{ "task_id": "...", "status": "queued" }
GET /api/v1/creative/task/:id- 返回字段:
task_id,status,title,product_name,progress,error,created_at,completed_at,product_image_url,requested_formats,style,cta_text,num_variants,selling_points,creatives[] creatives元素:{ id, format, image_url, width, height, title?, product_name?, cta_text?, selling_points? }
DELETE /api/v1/creative/task/:id- 返回:
{ "task_id": "...", "status": "deleted" }
GET /api/v1/creative/tasks?page=1&page_size=20&status=processing|completed|...- 返回:
{ tasks: [], total, page, page_size, total_pages }
GET /api/v1/creative/assets?page=1&page_size=20&format=1:1&task_id=...- 返回:
{ assets: [], total, page, page_size, total_pages } assets元素:{ id/numeric_id?, task_id, format, width, height, storage_type, public_url, image_url?, title?, product_name?, cta_text?, selling_points?, created_at, updated_at }
POST /api/v1/experiments- Body:
{
"name": "首页 banner 实验",
"product_name": "可选",
"variants": [
{
"creative_id": 123, // 或素材 uuid(前端 types 支持 string/number)
"weight": 0.5,
"bucket_start": 0,
"bucket_end": 49,
"title": "可选",
"product_name": "可选",
"image_url": "可选",
"cta_text": "可选",
"selling_points": ["可选"]
}
]
}- 返回:
{ "experiment_id": "uuid", "status": "draft|active|..." }
GET /api/v1/experiments?page=1&page_size=20&status=active|archived|draft- 返回:
{ experiments:[{ experiment_id,name,product_name,status,created_at,start_at,end_at,variants[] }], total, page, page_size } variants同创建时的结构。
POST /api/v1/experiments/:id/status- Body:
{ "status": "active|stopped|archived" } - 返回:
{ experiment_id, status }
GET /api/v1/experiments/:id/assign?user_key=xxx- 返回:
{
"creative_id": 123,
"asset_uuid": "可选",
"task_id": 1,
"title": "...",
"product_name": "...",
"cta_text": "...",
"selling_points": ["..."],
"image_url": "素材图 URL"
}POST /api/v1/experiments/:id/hit- Body:
{ "creative_id": 123 } - 返回:
{ "status": "ok" }
POST /api/v1/experiments/:id/click- Body:
{ "creative_id": 123 } - 返回:
{ "status": "ok" }
GET /api/v1/experiments/:id/metrics- 返回:
{
"experiment_id": "...",
"variants": [
{ "creative_id": 123, "impressions": 10, "clicks": 2, "ctr": 0.2 }
]
}GET /api/v1/model_traces?page=1&page_size=20&status=running|success|failed&model_name=qwen|tongyi&trace_id=...- 返回:
{ traces: [{ trace_id, model_name, model_version, status, duration_ms, start_at, end_at, source, input_preview?, output_preview?, error_message? }], total, page, page_size }
GET /api/v1/model_traces/:id- 返回:
{ trace_id, model_name, model_version, status, duration_ms, start_at, end_at, source, input_preview?, output_preview?, error_message?, steps: [...] } steps元素:{ step_name, component, status, duration_ms, start_at, end_at, input_preview?, output_preview?, error_message? }
如需补充其它域名的 CORS,请在
internal/middleware/cors.go的allowedOrigins添加。当前 API 仍未接入鉴权,生产前需要加上认证/限流。