重置 UAC API Key
前提条件
已获取阿里云账号或 RAM 用户的 AccessKey,并已为其授予调用本接口所需的 RAM 权限。建议将 AccessKey 配置为环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET,避免明文写入代码。
接口
/tokenplan/api-key-rotations本接口是阿里云 OpenAPI,采用 AccessKey 签名(签名算法 ACS3-HMAC-SHA256),不支持 Authorization: Bearer {API_KEY} 方式。请求需携带公共请求头 x-acs-action: RotateTokenPlanKey、x-acs-version: 2026-02-10、x-acs-date、x-acs-content-sha256、x-acs-signature-nonce 以及 Authorization。
推荐使用阿里云 SDK 或 OpenAPI Explorer 发起调用,可免去自行计算签名。详细说明见认证。
仅 API Key 变化,API Key ID 不变。
请求参数
所有参数均通过 Query String 传递。
ApiKeyIdstring必填API Key ID
返回参数
Successboolean调用接口是否成功:
true:成功
false:失败
Codestring响应状态码。
Messagestring响应信息。
Dataobject业务数据
ApiKeyIdstringAPI Key ID(系统生成)
SourceIdstringBaiLian 返回的 source_id
PlainApiKeystringBaiLian 返回的新明文 API Key(只在重置时返回一次)
MaskedApiKeystringBaiLian 返回的新 masked_api_key(如 sk_***cdef)
ResetAtstring重置时间
请求示例
本接口使用阿里云 OpenAPI 签名,下例中 ${SIGNATURE} 需按 ACS3-HMAC-SHA256 算法计算得出,x-acs-date、x-acs-signature-nonce 需替换为实际值。
curl -X POST "https://modelstudio.cn-beijing.aliyuncs.com/tokenplan/api-key-rotations?ApiKeyId=ak_123456" \
--header "x-acs-action: RotateTokenPlanKey" \
--header "x-acs-version: 2026-02-10" \
--header "x-acs-date: 2026-01-01T12:00:00Z" \
--header "x-acs-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" \
--header "x-acs-signature-nonce: ${SIGNATURE_NONCE}" \
--header "Authorization: ACS3-HMAC-SHA256 Credential=${ALIBABA_CLOUD_ACCESS_KEY_ID},SignedHeaders=host;x-acs-action;x-acs-content-sha256;x-acs-date;x-acs-signature-nonce;x-acs-version,Signature=${SIGNATURE}"
import os
from alibabacloud_modelstudio20260210.client import Client
from alibabacloud_modelstudio20260210 import models
from alibabacloud_tea_openapi import models as open_api_models
config = open_api_models.Config(
access_key_id=os.environ["ALIBABA_CLOUD_ACCESS_KEY_ID"],
access_key_secret=os.environ["ALIBABA_CLOUD_ACCESS_KEY_SECRET"],
endpoint="modelstudio.cn-beijing.aliyuncs.com",
)
client = Client(config)
request = models.RotateTokenPlanKeyRequest(
api_key_id="ak_123456",
)
response = client.rotate_token_plan_key(request)
print(response.body)
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.modelstudio20260210.AsyncClient;
import com.aliyun.sdk.service.modelstudio20260210.DefaultAsyncClientBuilder;
import com.aliyun.sdk.service.modelstudio20260210.models.RotateTokenPlanKeyRequest;
import com.aliyun.sdk.service.modelstudio20260210.models.RotateTokenPlanKeyResponse;
public class RotateTokenPlanKey {
public static void main(String[] args) throws Exception {
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
.accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
.accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
.build());
AsyncClient client = new DefaultAsyncClientBuilder()
.credentialsProvider(provider)
.region("cn-beijing")
.build();
RotateTokenPlanKeyRequest request = RotateTokenPlanKeyRequest.builder()
.apiKeyId("ak_123456")
.build();
RotateTokenPlanKeyResponse response = client.rotateTokenPlanKey(request).get();
System.out.println(response.getBody());
client.close();
}
}
返回示例
{
"Success": true,
"Data": {
"ApiKeyId": "ak_123456",
"SourceId": "123456",
"PlainApiKey": "sk-ws.abc123456",
"MaskedApiKey": "sk_***6",
"ResetAt": "2025-07-18T03:19:17Z"
}
}
错误码
如果调用失败,会返回错误信息。更多错误码及解决方法,请参见Token Plan API 错误码。