Files
taiji-AI-PAD/Docs/前后端调试说明/API文档/05-渠道合作伙伴.md
T
2025-12-26 08:06:11 +00:00

6.3 KiB

渠道合作伙伴 API

基础URL: http://localhost:8002/api/channel

权限说明: 需要渠道管理员(channel_admin)或更高权限登录


目录

  1. 租户管理相关
  2. 资源申请相关
  3. 计费统计相关

租户管理相关

1. 获取租户列表

GET /api/channel/tenants

响应示例:

{
  "success": true,
  "data": {
    "tenants": [
      {
        "id": "tenant-uuid-1",
        "name": "企业客户A",
        "email": "contact@company-a.com",
        "subscriptionTier": "pro",
        "balance": 1500.00,
        "creditLimit": 2000.00,
        "status": "active",
        "createdAt": "2025-12-01T00:00:00Z"
      }
    ]
  }
}

2. 创建租户

POST /api/channel/tenants/create

请求体:

{
  "name": "企业客户B",
  "email": "contact@company-b.com",
  "password": "securepass123",
  "subscriptionTier": "enterprise"
}

请求参数说明:

  • name (string, 必需): 租户名称
  • email (string, 必需): 租户邮箱,用于登录
  • password (string, 必需): 租户密码
  • subscriptionTier (string, 可选): 订阅等级,默认为 free

subscriptionTier可选值: free, pro, enterprise

curl示例:

# 使用渠道管理员token创建租户
curl -s -X POST "http://localhost:8002/api/channel/tenants/create" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $CHANNEL_TOKEN" \
  -d '{
    "name": "张三",
    "email": "zhangsan@company.com",
    "password": "User@123456",
    "subscriptionTier": "pro"
  }'

响应示例:

{
  "success": true,
  "data": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "name": "张三",
    "email": "zhangsan@company.com"
  },
  "message": "租户创建成功"
}

注意: 创建成功后,租户可使用 role=user 登录系统。


3. 分配租户资源

PUT /api/channel/tenants/{tenant_id}/resources

请求体:

{
  "agents": [
    {
      "agentId": "agent-uuid-1",
      "quantity": 10
    }
  ],
  "models": [
    {
      "modelName": "gpt-4o-mini",
      "rpm": 60,
      "tpm": 60000
    }
  ],
  "customAgentResources": {
    "cpu": 4.0,
    "memory": 8.0
  }
}

请求参数说明:

  • agents (array, 必需): Agent资源分配列表
    • agentId (string): Agent的UUID或名称
    • quantity (int): 分配数量
  • models (array, 必需): 模型资源分配列表
    • modelName (string): 模型供应商名称
    • rpm (int): 每分钟请求数限制
    • tpm (int): 每分钟Token数限制
  • customAgentResources (object, 可选): 自定义Agent资源
    • cpu (float): CPU核心数
    • memory (float): 内存大小(GB)

curl示例:

# 为租户分配资源
curl -s -X PUT "http://localhost:8002/api/channel/tenants/${TENANT_ID}/resources" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $CHANNEL_TOKEN" \
  -d '{
    "agents": [
      {"agentId": "通用助手", "quantity": 5},
      {"agentId": "代码助手", "quantity": 3},
      {"agentId": "数据分析师", "quantity": 2}
    ],
    "models": [
      {"modelName": "OpenAI", "rpm": 100, "tpm": 100000}
    ]
  }'

响应示例:

{
  "success": true,
  "message": "资源分配成功"
}

4. 更新租户计费设置

PUT /api/channel/tenants/{tenant_id}/billing

请求体:

{
  "subscriptionTier": "enterprise",
  "discount": 15.0
}

请求参数说明:

  • subscriptionTier (string, 必需): 订阅等级,可选值:free, pro, enterprise
  • discount (float, 必需): 折扣比例,0-100之间

curl示例:

# 更新租户计费设置
curl -s -X PUT "http://localhost:8002/api/channel/tenants/${TENANT_ID}/billing" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $CHANNEL_TOKEN" \
  -d '{"subscriptionTier": "pro", "discount": 10.0}'

响应示例:

{
  "success": true,
  "message": "计费设置更新成功"
}

5. 为租户充值

POST /api/channel/tenants/{tenant_id}/recharge

请求体:

{
  "amount": 1000.00
}

请求参数说明:

  • amount (float, 必需): 充值金额,必须大于0

curl示例:

# 为租户充值
curl -s -X POST "http://localhost:8002/api/channel/tenants/${TENANT_ID}/recharge" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $CHANNEL_TOKEN" \
  -d '{"amount": 5000.0}'

响应示例:

{
  "success": true,
  "data": {
    "tenantId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "newBalance": 5000.0,
    "rechargeAmount": 5000.0
  }
}

6. 设置租户授信额度

PUT /api/channel/tenants/{tenant_id}/credit

请求体:

{
  "creditLimit": 5000.00
}

请求参数说明:

  • creditLimit (float, 必需): 授信额度,必须大于等于0

curl示例:

# 设置租户授信额度
curl -s -X PUT "http://localhost:8002/api/channel/tenants/${TENANT_ID}/credit" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $CHANNEL_TOKEN" \
  -d '{"creditLimit": 10000.0}'

响应示例:

{
  "success": true,
  "data": {
    "tenantId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "creditLimit": 10000.0
  }
}

资源申请相关

7. 申请资源

POST /api/channel/resources/apply

请求体示例(申请模型):

{
  "type": "model",
  "modelName": "gpt-4",
  "rpm": 100,
  "tpm": 100000,
  "reason": "客户需求增长"
}

响应示例:

{
  "success": true,
  "data": {
    "id": "application-uuid-1",
    "status": "pending"
  },
  "message": "申请已提交,等待审批"
}

计费统计相关

8. 获取渠道计费统计

GET /api/channel/billing/stats

查询参数:

  • startTime (string, 必需): 开始时间
  • endTime (string, 必需): 结束时间
  • tenantName (string, 可选): 租户名称筛选
  • minCalls (int, 可选): 最小调用次数
  • maxCalls (int, 可选): 最大调用次数
  • export (string, 可选): 导出格式

响应示例:

{
  "success": true,
  "data": {
    "tenantStats": [
      {
        "tenantId": "tenant-uuid-1",
        "tenantName": "企业客户A",
        "calls": 1580,
        "totalEU": 158.0,
        "totalCost": 158.00
      }
    ],
    "callRecords": []
  }
}