跳转到主内容

快速开始

Creatoria Agent API 文档

#快速开始

本指南将帮助你在 5 分钟内完成 Creatoria Agent API 的接入。

#前置条件

  1. 一个 Creatoria 平台账号
  2. 一个有效的 API Key
  3. 至少一个 Project

#第一步:获取 API Key

登录 Creatoria 平台后,进入 设置 > API Keys 页面创建一个新的 API Key。

API Key 创建后只会显示一次,请妥善保存。

#第二步:发送第一个请求

使用 API Key 列出你的所有 Agent:

bashcurl -X GET "https://your-domain.com/v1/agents" \
  -H "X-API-Key: sk_your_api_key_here" \
  -H "X-Project-Id: your-project-id"

成功响应:

json{
  "data": [
    {
      "id": "agent_abc123",
      "name": "客服助手",
      "model": "zhipu/glm-4",
      "status": "active",
      "createdAt": "2026-01-15T08:00:00Z"
    }
  ],
  "meta": {
    "total": 1,
    "page": 1,
    "limit": 20,
    "totalPages": 1,
    "hasNext": false,
    "hasPrev": false
  }
}

#第三步:创建 Agent

bashcurl -X POST "https://your-domain.com/v1/agents" \
  -H "X-API-Key: sk_your_api_key_here" \
  -H "X-Project-Id: your-project-id" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "我的助手",
    "systemPrompt": "你是一个友善的 AI 助手。",
    "model": "zhipu/glm-4"
  }'

#第四步:与 Agent 对话

#非流式对话

bashcurl -X POST "https://your-domain.com/v1/agents/agent_abc123/chat" \
  -H "X-API-Key: sk_your_api_key_here" \
  -H "X-Project-Id: your-project-id" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "你好,请介绍一下你自己",
    "stream": false
  }'

#流式对话

bashcurl -X POST "https://your-domain.com/v1/agents/agent_abc123/chat" \
  -H "X-API-Key: sk_your_api_key_here" \
  -H "X-Project-Id: your-project-id" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "你好,请介绍一下你自己",
    "stream": true
  }'

流式响应使用 SSE (Server-Sent Events) 格式:

data: {"sessionId":"sess_xxx","delta":{"content":"你好"}}

data: {"sessionId":"sess_xxx","delta":{"content":"!我是"}}

data: {"sessionId":"sess_xxx","done":true,"usage":{"inputTokens":50,"outputTokens":30,"totalTokens":80}}

data: [DONE]

#第五步:管理对话历史

系统会自动为每次新对话创建会话(Session),后续消息使用同一 sessionId 即可继续对话:

bashcurl -X POST "https://your-domain.com/v1/agents/agent_abc123/chat" \
  -H "X-API-Key: sk_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "sess_xxx",
    "message": "请继续上面的话题",
    "stream": true
  }'

#下一步