新建自定义模型接入点
更新时间:2026-11-24
接口说明
- 本接口用于在账号级模型服务注册表中新建一个自定义模型接入点。
- source 仅支持 CUSTOM_ENDPOINT。星点模型由平台预置、只读,不通过本接口创建。
- modelName 账号内唯一,且不得与星点模型重名,创建后不可修改;冲突返回 409 ModelServiceAlreadyExists。
- baseURL 必须是 https 公网地址,拒绝回环、私网、链路本地等非公网地址。
- apiKey 加密存储,响应和列表均不回显,仅返回末 4 位。
请求结构
Plain Text
1POST /v1/agents/createModelService HTTP/1.1
2Host: aw-harness.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "source": "CUSTOM_ENDPOINT",
7 "modelName": "glm-5",
8 "downstreamModelId": "glm-5",
9 "baseURL": "https://your-gateway.example.com/v1",
10 "apiKey": "sk-xxxxxxxxxxxx",
11 "contextWindow": 128000,
12 "maxOutput": 16000
13}
请求头域
除公共头域外,无其它特殊头域。
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| source | String | 是 | RequestBody参数 | 仅支持 CUSTOM_ENDPOINT;其他取值返回 400。 |
| modelName | String | 是 | RequestBody参数 | 模型名称,1~40 字符,账号内唯一,且不得与星点模型重名。创建后不可修改。 |
| downstreamModelId | String | 否 | RequestBody参数 | 运行期发给下游的 model 参数,不超过 128 字符;为空时运行期取 modelName。 |
| baseURL | String | 是 | RequestBody参数 | 模型服务地址,必须为 https 公网地址,不超过 512 字符。拒绝回环、私网、链路本地等非公网地址。 |
| apiKey | String | 是 | RequestBody参数 | 模型服务凭据,不超过 512 字节,加密存储,响应和列表均不回显。 |
| contextWindow | Integer | 是 | RequestBody参数 | 上下文窗口 token 数,必须为正整数。 |
| maxOutput | Integer | 是 | RequestBody参数 | 单次回复最大输出 token 数,必须为正整数且不超过 contextWindow。 |
返回头域
除公共头域,无其它特殊头域。
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| serviceId | String | 自建模型资源 ID,ms- 前缀。 |
| modelName | String | 模型名称。 |
| source | String | 固定为 CUSTOM_ENDPOINT。 |
错误码
| 错误码 | 错误描述 | HTTP状态码 | 中文解释 |
|---|---|---|---|
| InvalidArgument | The request parameters are invalid. | 400 | 字段取值非法,如 baseURL 非 https 公网地址、maxOutput 超过 contextWindow、modelName 长度越界。字段错误可通过 details[].field 定位。 |
| Forbidden | Operation requires an admin caller. | 403 | 缺少鉴权账号、跨账号访问他人资源,或携带 Actor 头调用仅限管理员的写接口。 |
| ModelServiceAlreadyExists | Model service already exists. | 409 | 模型名称已存在或与星点模型重名。 |
| PersistFailed | Failed to persist the model service. | 500 | 服务端存储读写失败,可重试。 |
| Internal | Internal server error. | 500 | 服务端内部错误,保留 requestId 联系维护方。 |
请求示例
Plain Text
1POST http://aw-harness.bj.baidubce.com/v1/agents/createModelService
2Host: aw-harness.bj.baidubce.com
3Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2015-08-11T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de
4Content-Type: application/json
5
6{
7 "source": "CUSTOM_ENDPOINT",
8 "modelName": "glm-5",
9 "baseURL": "https://your-gateway.example.com/v1",
10 "apiKey": "sk-xxxxxxxxxxxx",
11 "contextWindow": 128000,
12 "maxOutput": 16000
13}
返回示例
Plain Text
1HTTP/1.1 200 OK
2Content-Type: application/json;charset=UTF-8
3x-bce-request-id: 9f3d0e6a-1c2b-4d5e-8a7f-0b1c2d3e4f5a
4Server: BWS
5
6{
7 "result": {
8 "serviceId": "ms-3f8a1c2d",
9 "modelName": "glm-5",
10 "source": "CUSTOM_ENDPOINT"
11 },
12 "requestId": "9f3d0e6a-1c2b-4d5e-8a7f-0b1c2d3e4f5a"
13}
评价此篇文章
