文档中心/ 百度搭子/ 企业版使用指南/ API参考/ 凭证管理/ 创建凭证

创建凭证

POST
https://api.dumate.cn/api/v1/vaults/{vaultId}/credentials

本接口用于在凭证空间(Vault)中创建凭证(Credential),返回新建凭证的详细信息及标识。

权限说明

使用API Key鉴权调用API流程,具体调用流程,请查看认证鉴权。

请求参数

Headers 参数
除公共头域外,无其它特殊头域
URL 参数
`vaultId` 用于定位所属凭证空间。
vaultId string

凭证(Credential)所属凭证空间(Vault)标识。
该凭证空间必须处于 active 状态且属于当前租户。

可选
Body 参数
根据 `auth.type` 的不同,凭证配置对象所需字段有所差异,详见下方参数说明。
name string

凭证(Credential)名称。
不能为空。

必选
auth object {9}

凭证配置对象。
字段随 auth.type 变化。

必选
显示子属性 隐藏子属性
type string

凭证类型。
可选值:
mcp_oauth:OAuth 访问令牌。
static_bearer:静态 Bearer Token。
environment_variable:环境变量。

必选
mcpServerUrl string

MCP 服务地址。
type 为 mcp_oauth、static_bearer 时必填。
该 MCP 服务须可访问、鉴权有效且至少返回一个工具。

可选
token string

静态 Bearer Token。
type 为 static_bearer 时必填。

可选
accessToken string

OAuth 访问令牌。
type 为 mcp_oauth 时必填。

可选
expiresAt string

访问令牌过期时间,RFC 3339 时间戳。
仅 type 为 mcp_oauth 时使用;设置了 auth.refresh.refreshToken 时必填。
填写时必须晚于当前时间。

可选
refresh object {4}

OAuth 刷新配置。
仅 type 为 mcp_oauth 时使用。

可选
显示子属性 隐藏子属性
clientId string

OAuth 客户端标识。

可选
refreshToken string

OAuth Refresh Token。
填写后 auth.expiresAt 变为必填。

可选
tokenEndpoint string

OAuth Token Endpoint。

可选
tokenEndpointAuth object {2}

Token Endpoint 鉴权配置。

可选
显示子属性 隐藏子属性
type string

Token Endpoint 鉴权类型,示例为 client_secret_post。

可选
clientSecret string

OAuth Client Secret。

可选
secretName string

环境变量名称。
type 为 environment_variable 时必填。

可选
secretValue string

环境变量值。
type 为 environment_variable 时必填。

可选
networking object {2}

环境变量凭证的网络访问策略。
仅 type 为 environment_variable 时使用。

可选
显示子属性 隐藏子属性
type string

网络策略类型,示例为 limited。

可选
allowedHosts array

允许访问的主机列表。

可选
显示子属性 隐藏子属性
items string
请求结构
POST /api/v1/vaults/{vaultId}/credentials HTTP/1.1
Host: api.dumate.cn
Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/json

{
  "name": "示例静态 Token 凭证",
  "auth": {
    "type": "static_bearer",
    "mcpServerUrl": "<MCP_SERVER_URL>",
    "token": "<STATIC_BEARER_TOKEN>"
  }
}

示例代码

curl
curl --location --request POST "https://api.dumate.cn/api/v1/vaults/vault_7b41ea1b855049a6/credentials" \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--data '{
    "name": "示例静态 Token 凭证",
    "auth": {
        "type": "static_bearer",
        "mcpServerUrl": "<MCP_SERVER_URL>",
        "token": "<STATIC_BEARER_TOKEN>"
    }
}'
curl
curl --location --request POST "https://api.dumate.cn/api/v1/vaults/vault_7b41ea1b855049a6/credentials" \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--data '{
    "name": "示例 MCP OAuth 凭证",
    "auth": {
        "type": "mcp_oauth",
        "mcpServerUrl": "<MCP_SERVER_URL>",
        "accessToken": "<ACCESS_TOKEN>",
        "expiresAt": "2026-08-18T14:00:00Z",
        "refresh": {
            "clientId": "<clientId>",
            "refreshToken": "<REFRESH_TOKEN>",
            "tokenEndpoint": "<OAUTH_TOKEN_ENDPOINT>",
            "tokenEndpointAuth": {
                "type": "client_secret_post",
                "clientSecret": "<CLIENT_SECRET>"
            }
        }
    }
}'
curl --location --request POST "https://api.dumate.cn/api/v1/vaults/vault_7b41ea1b855049a6/credentials" \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <YOUR_API_KEY>' \
--data '{
    "name": "示例环境变量凭证",
    "auth": {
        "type": "environment_variable",
        "secretName": "name",
        "secretValue": "value",
        "networking": {
            "type": "limited",
            "allowedHosts": [
                "<ALLOWED_HOST>"
            ]
        }
    }
}'

返回响应

Headers 参数
除公共头域外,无其它特殊头域
返回参数
id string

凭证(Credential)标识。

可选
vaultId string

所属凭证空间(Vault)标识。

可选
authType string

凭证(Credential)鉴权类型。可选值: mcp_oauth, static_bearer, environment_variable

可选
mcpServerUrl string

MCP 服务地址;仅 mcp_oauth、static_bearer 类型返回。

可选
mcpId string

MCP 连接标识;仅 mcp_oauth、static_bearer 类型返回。

可选
name string

凭证(Credential)名称。

可选
status string

凭证(Credential)状态。可选值: active(有效), revoked(已删除)

可选
createdAt string

创建时间,ISO 8601 格式。

可选
updatedAt string

最近更新时间,ISO 8601 格式。

可选
JSON
{
  "id": "cred_1e19ca151c9042b2",
  "vaultId": "vault_7b41ea1b855049a6",
  "authType": "static_bearer",
  "mcpServerUrl": "<MCP_SERVER_URL>",
  "mcpId": "07e6b9ac-061b-4198-9b5e-31618a03292d",
  "name": "示例静态 Token 凭证",
  "status": "active",
  "createdAt": "2026-08-18T14:56:03Z",
  "updatedAt": "2026-08-18T14:56:03Z"
}
JSON
{
  "id": "cred_cfdcc61776e14e92",
  "vaultId": "vault_ef011e50e617459e",
  "authType": "mcp_oauth",
  "mcpServerUrl": "<MCP_SERVER_URL>",
  "mcpId": "166c71d0-6e15-4cd6-a400-d14d3a0e8c87",
  "name": "示例 MCP OAuth 凭证",
  "status": "active",
  "createdAt": "2026-08-18T13:00:12Z",
  "updatedAt": "2026-08-18T13:00:12Z"
}
JSON
{
  "id": "cred_b50b7268f6fa414e",
  "vaultId": "vault_5a883f6a97f54843",
  "authType": "environment_variable",
  "name": "自定义环境变量",
  "status": "active",
  "createdAt": "2026-08-18T14:21:15Z",
  "updatedAt": "2026-08-18T14:21:15Z"
}