创建后端
更新时间:2026-09-07
该接口用于在指定 AI 网关实例中创建可供 API 路由绑定的后端
注意事项:
backendServiceEndpoint不包含http://或https://;省略端口时,关闭 TLS 补全为80,SIMPLE补全为443,查询接口返回补全后的地址- 后端类型为
aiModel时需指定有效的模型供应商;除「供应商为custom且协议为raw」外,至少配置一个 API Key - 后端数量受实例配额限制
请求结构
Plain Text
1POST /?action=CreateBackend HTTP/1.1
2Host: bcc.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "instanceId": instanceId,
7 "name": name,
8 "backendType": backendType,
9 "aiModel": aiModel,
10 "provider": provider,
11 "backendServiceEndpoint": backendServiceEndpoint,
12 "backendDnsServers" : [backendDnsServer],
13 "backendApiKeys" : [backendApiKey],
14 "billingConfig": {
15 "inputTokenPrice": inputTokenPrice,
16 "outputTokenPrice": outputTokenPrice,
17 "cacheTokenPrice": cacheTokenPrice,
18 "priceUnit": priceUnit
19 },
20 "tlsConfig": {
21 "mode": mode,
22 "sni": sni
23 },
24 "connectionPool": {
25 "enabled": enabled,
26 "idleTimeout": idleTimeout,
27 "connectTimeout": connectTimeout,
28 "tcpKeepalive": {
29 "enabled": enabled,
30 "time": time,
31 "interval": interval,
32 "probes": probes
33 }
34 }
35}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| instanceId | String | 是 | RequestBody参数 | 网关实例 ID |
| name | String | 是 | RequestBody参数 | 后端名称 |
| backendType | String | 是 | RequestBody参数 | 后端类型:aiModel(AI 大模型)/ip(固定 IP)/domain(域名)/agent(Agent 服务) |
| aiModel | String | 否 | RequestBody参数 | AI 大模型接口协议:openai/anthropic/raw,仅后端类型为 aiModel 时生效,不传按 openai 处理 |
| provider | String | 否 | RequestBody参数 | 模型供应商,取值为 custom 或 DescribeBackendTypes 返回的供应商标识,仅后端类型为 aiModel 时生效且必填 |
| backendServiceEndpoint | String | 是 | RequestBody参数 | 服务地址,格式为 host[:port],AI 大模型可再带路径,不含 http:// 与 https://;省略端口时按 tlsConfig.mode 补全为 80 或 443 |
| backendDnsServers | List<AiGwBackendDnsServerDTO> | 否 | RequestBody参数 | 后端专用 DNS 服务器列表,最多 5 个,不传表示使用系统默认 DNS |
| backendApiKeys | List<String> | 否 | RequestBody参数 | 访问后端使用的 API Key 列表,后端类型为 aiModel 时除「provider 为 custom 且 aiModel 为 raw」外必填 |
| billingConfig | AiGwBackendBillingConfigDTO | 否 | RequestBody参数 | Token 计费配置,用于计算调用该后端产生的 Token 费用,不传表示不配置计费 |
| tlsConfig | AiGwBackendTlsConfigDTO | 否 | RequestBody参数 | 访问后端时的 TLS 配置,不传表示不启用 TLS |
| connectionPool | AiGwBackendConnectionPoolConfigDTO | 否 | RequestBody参数 | 访问后端时的连接池配置,不传表示使用系统默认的连接超时策略 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| backendId | String | 后端 ID |
错误码
| 错误码 | 错误描述 | HTTP状态码 | 中文解释 |
|---|---|---|---|
| MethodArgumentNotValidException | MethodArgumentNotValidException: instanceId must not be blank | 400 | 必填参数缺失或格式不合法,具体字段名见错误描述,如 instanceId、name、backendType、backendServiceEndpoint 不能为空 |
| HttpMessageNotReadable | Http Message Not Readable: JSON parse error | 400 | 请求体不是合法 JSON,无法解析,请检查 JSON 语法和字段类型 |
| ResourceNotExist | Backend type not exist. | 404 | backendType 不在支持范围内,可先调用 DescribeBackendTypes 获取可选的后端类型 |
| ParamCheckError | Invalid AiModel URL. | 404 | 后端连接配置校验不通过,具体不合法项见错误描述,如服务地址不是合法的 host[:port][/path]、模型供应商无效、API Key 为空或含首尾空格、TLS 模式非法或缺少 SNI、连接池与 DNS 参数超出取值范围 |
| InstanceNotExist | Instance not exist. | 404 | instanceId 对应的网关实例不存在、不属于当前账号或已释放 |
| QuotaCheckError | Backend count exceed quota {quota}. | 413 | 该实例下后端数量已达配额上限 {quota},请删除不再使用的后端或申请提升配额 |
| HttpMediaTypeException | HttpMediaTypeException: Content-Type 'text/plain' is not supported | 415 | 请求的 Content-Type 不受支持,请使用 application/json |
请求示例
Plain Text
1POST /?action=CreateBackend HTTP/1.1
2Host: bcc.bj.baidubce.com
3Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2015-08-11T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de
4
5{
6 "instanceId": "gw-a1b2c3d4",
7 "name": "自定义 OpenAI 兼容后端",
8 "backendType": "aiModel",
9 "aiModel": "openai",
10 "provider": "custom",
11 "backendServiceEndpoint": "api.example.com/v1",
12 "backendDnsServers": [
13 {
14 "ip": "10.0.0.2",
15 "port": 53
16 },
17 {
18 "ip": "10.0.0.3",
19 "port": 53
20 }
21 ],
22 "backendApiKeys": [
23 "example-api-key-primary",
24 "example-api-key-standby"
25 ],
26 "billingConfig": {
27 "inputTokenPrice": 0.002,
28 "outputTokenPrice": 0.008,
29 "cacheTokenPrice": 0.001,
30 "priceUnit": "PER_1K"
31 },
32 "tlsConfig": {
33 "mode": "SIMPLE",
34 "sni": "api.example.com"
35 },
36 "connectionPool": {
37 "enabled": true,
38 "idleTimeout": 300,
39 "connectTimeout": 5,
40 "tcpKeepalive": {
41 "enabled": true,
42 "time": 60,
43 "interval": 10,
44 "probes": 3
45 }
46 }
47}
返回示例
Plain Text
1HTTP/1.1 200 OK
2x-bce-request-id: 1214cca7-4ad5-451d-9215-71cb844c0a50
3Date: Wed, 03 Dec 2014 06:42:19 GMT
4Content-Type: application/json;charset=UTF-8
5Server: BWS
6
7{
8 "backendId": "bd-a1b2c3d4"
9}
评价此篇文章
