#认证
所有 API 请求都需要通过认证。Creatoria Agent API 使用 API Key 进行身份验证。
#API Key 认证
在每个请求的 Header 中传入 API Key:
X-API-Key: sk_your_api_key_here
#示例
bashcurl -X GET "https://your-domain.com/v1/agents" \
-H "X-API-Key: sk_your_api_key_here"
#Project 上下文
部分操作(如创建 Agent)需要 Project 上下文。通过 X-Project-Id 请求头传入:
X-Project-Id: proj_abc123
如果 API Key 本身已绑定了 Project,则无需额外传入此头。但如果 API Key 没有绑定 Project,创建 Agent 等操作需要显式指定。
#权限与角色
API Key 的权限通过其 permissions 字段控制,映射到以下角色:
| API Key 权限 | 映射角色 | 允许操作 |
|---|---|---|
admin | admin | 所有操作(GET、POST、PATCH、PUT、DELETE) |
write | member | 读取和写入操作(GET、POST、PATCH) |
read | viewer | 仅读取操作(GET) |
#权限检查规则
每个端点都声明了所需的权限,例如:
| 权限标识 | 说明 |
|---|---|
agents:create | 创建 Agent |
agents:update | 更新 Agent |
agents:delete | 删除 Agent |
agent:chat | 与 Agent 对话 |
session:create | 创建会话 |
session:read | 查看会话 |
session:update | 更新会话 |
session:delete | 删除会话 |
messages:read | 查看消息历史 |
kb:read | 查看知识库 |
kb:create | 创建知识库 |
kb:write | 更新知识库 |
kb:delete | 删除知识库 |
kb:upload | 上传文档 |
rag:search | 搜索知识库 |
tools:create | 创建工具配置 |
tools:update | 更新工具配置 |
tools:delete | 删除工具配置 |
webhooks:create | 创建 Webhook |
webhooks:read | 查看 Webhook |
webhooks:update | 更新 Webhook |
webhooks:delete | 删除 Webhook |
#多租户架构
Creatoria 使用三级租户架构:
Organization (组织)
└── Project (项目)
└── Agent (智能体)
- Organization: 最顶层的隔离单元,拥有独立的资源和配额
- Project: 项目级别的隔离,用于管理不同的业务场景
- Agent: 最小的资源单元,属于某个 Project
API Key 在创建时会关联到 Organization,可选关联到特定 Project。
#安全建议
- 不要将 API Key 暴露在前端代码中,仅在后端服务器中使用
- 为不同环境使用不同的 API Key(开发、测试、生产)
- 定期轮换 API Key,删除不再使用的 Key
- 使用最小权限原则:只赋予 API Key 实际需要的权限