CreateCredential - 创建凭证
在指定工作空间内创建凭证,用于智能体访问外部服务时的鉴权。当前仅支持 apiKey 类型,凭证内容通过 credentialMetadata 以 JSON 字符串传入,写入后只能以脱敏形式查询。
接口说明
在工作空间中创建凭证,用于 Connector 等服务的鉴权。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
调试
授权信息
|
操作 |
访问级别 |
资源类型 |
条件关键字 |
关联操作 |
|
agentcore:CreateCredential |
create |
*Credential
|
无 | 无 |
请求语法
POST /workspaces/{workspaceId}/credentials HTTP/1.1
路径参数
|
名称 |
类型 |
必填 |
描述 |
示例值 |
| workspaceId |
string |
是 |
工作空间 ID。 |
ws-123456 |
请求参数
|
名称 |
类型 |
必填 |
描述 |
示例值 |
| body |
object |
否 |
创建凭证的请求内容。 |
|
| credentialMetadata |
string |
是 |
凭证内容,取值为 JSON 字符串。credentialType 为 apiKey 时只能包含 apiKey 一个字段,且取值不能为空。写入后仅支持脱敏查询。 |
{"apiKey":"sk-example-value"} |
| credentialType |
string |
是 |
凭证类型。当前仅支持 apiKey。 |
apiKey |
| description |
string |
否 |
凭证描述,长度不超过 256 个字符。 |
线上环境调用模型服务使用的 API Key |
| name |
string |
是 |
凭证名称。在工作空间内唯一,只能包含字母、数字、点、下划线和连字符,长度为 3~128 个字符,且不能使用运行时保留名称。 |
model-api-key |
| resourceRefs |
array<object> |
否 |
resourceScope 为 SPECIFIED 时必须为非空数组。每项包含 resourceType、resourceId;resourceName 可选。 |
|
|
object |
否 |
|||
| resourceId |
string |
否 |
资源的唯一标识。 |
agent-xxxx |
| resourceName |
string |
否 |
资源名称,资源已删除时为空。 |
my-agent |
| resourceType |
string |
否 |
资源类型,如 agent。 |
agent |
| resourceScope |
string |
否 |
ALL 表示全部资源;SPECIFIED 表示仅应用到 resourceRefs 指定的资源。 |
ALL |
| clientToken |
string |
否 |
暂不支持 |
暂不支持 |
返回参数
|
名称 |
类型 |
描述 |
示例值 |
|
object |
|||
| code |
string |
业务状态码。 |
SUCCESS |
| data |
object |
创建的凭证信息。 |
|
| createdAt |
string |
创建时间,采用 RFC 3339 格式的 UTC 时间。 |
2026-08-12T03:04:05Z |
| credentialId |
string |
凭证 ID。 |
cred-123456 |
| credentialMetadata |
string |
凭证内容的脱敏结果。credentialType 为 apiKey 时,apiKey 的取值以等长的 * 返回。 |
{"apiKey":"****************"} |
| credentialType |
string |
凭证类型。当前仅支持 apiKey。 |
apiKey |
| description |
string |
凭证描述,长度不超过 256 个字符。 |
线上环境调用模型服务使用的 API Key |
| name |
string |
凭证名称。在工作空间内唯一,只能包含字母、数字、点、下划线和连字符,长度为 3~128 个字符,且不能使用运行时保留名称。 |
model-api-key |
| regionId |
string |
资源所在的地域 ID。 |
cn-hangzhou |
| resourceRefs |
array<object> |
每项包含 resourceType、resourceId、resourceName。资源已删除时 resourceName 为空。 |
|
|
object |
|||
| resourceId |
string |
资源的唯一标识。 |
agent-xxxx |
| resourceName |
string |
资源名称,资源已删除时为空。 |
my-agent |
| resourceType |
string |
资源类型,如 agent。 |
agent |
| resourceScope |
string |
凭证资源应用范围 |
ALL |
| updatedAt |
string |
最近一次修改的时间,采用 RFC 3339 格式的 UTC 时间。 |
2026-08-12T03:04:05Z |
| workspaceId |
string |
工作空间 ID。 |
ws-123456 |
| httpStatusCode |
integer |
HTTP 状态码。 |
200 |
| message |
string |
响应消息。请求失败时返回错误描述。 |
success |
| requestId |
string |
请求 ID。 |
request-123456 |
| success |
boolean |
请求是否成功。 |
示例
正常返回示例
JSON格式
{
"code": "SUCCESS",
"data": {
"createdAt": "2026-08-12T03:04:05Z",
"credentialId": "cred-123456",
"credentialMetadata": "{\"apiKey\":\"****************\"}",
"credentialType": "apiKey",
"description": "线上环境调用模型服务使用的 API Key",
"name": "model-api-key",
"regionId": "cn-hangzhou",
"resourceRefs": [
{
"resourceId": "agent-xxxx",
"resourceName": "my-agent",
"resourceType": "agent"
}
],
"resourceScope": "ALL",
"updatedAt": "2026-08-12T03:04:05Z",
"workspaceId": "ws-123456"
},
"httpStatusCode": 200,
"message": "success",
"requestId": "request-123456",
"success": true
}
错误码
访问错误中心查看更多错误码。
变更历史
更多信息,参考变更详情。