认证方式
所有API请求都需要在Header中携带API Key进行认证。您可以在管理后台「API Key管理」中创建和管理您的密钥。
Authorization: Bearer sk-your-api-key-here
Content-Type: application/json
第一个调用
使用 POST /api/v1/agent/{agent_id}/invoke 接口调用指定智能体。
请求示例
curl -X POST https://api.pddun.net/api/v1/agent/restaurant-001/invoke \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"message": "今天有什么推荐菜?",
"context": {"user_id": "123", "session_id": "abc"}
}'
响应示例
{
"code": 0,
"message": "success",
"data": {
"agent_id": "restaurant-001",
"agent_name": "餐饮智能体",
"reply": "今日推荐:招牌红烧肉、清蒸鲈鱼、蒜蓉西兰花...",
"latency": 0.85,
"model": "doubao-seed-2.0-lite",
"tokens": {"prompt": 45, "completion": 78, "total": 123}
}
}
列出智能体
GET /api/v1/agents - 获取当前租户下所有可用智能体列表。
curl -X GET "https://api.pddun.net/api/v1/agents?industry=餐饮&page=1&size=20" \
-H "Authorization: Bearer sk-xxx"
错误码说明
| code | 说明 | 处理建议 |
|------|------|---------|
| 0 | 成功 | - |
| 401 | 未授权 | 检查API Key是否正确 |
| 403 | 无权限 | 检查租户权限配置 |
| 404 | 智能体不存在 | 检查agent_id是否正确 |
| 429 | 限流 | 降低调用频率或升级配额 |
| 500 | 服务端错误 | 联系技术支持 |
SDK 快速接入
Python
from pddun import PddunClient
client = PddunClient(api_key="sk-xxx")
response = client.agent.invoke(
agent_id="restaurant-001",
message="今天有什么推荐菜?"
)
print(response.reply)
Node.js
const { PddunClient } = require('@pddun/sdk');
const client = new PddunClient({ apiKey: 'sk-xxx' });
const response = await client.agent.invoke({
agentId: 'restaurant-001',
message: '今天有什么推荐菜?'
});
console.log(response.reply);