Updating an API Key
Function
The update API enables administrators to dynamically configure existing API Keys and adjust their settings. As workload requirements evolve, the purpose or ownership of an API key may change. This API supports updating the key's description and access permissions to ensure that API key assets remain aligned with workload needs. It maintains security while preserving the flexibility to restore operations when needed.
API constraints:
-
Authentication: Requests to this API must include a valid IAM token (X-Auth-Token) in the request header and have the corresponding fine-grained permission: modelarts:apiKey:create for update.
-
Tenant Isolation: The scope of API operations is determined by the project/domain associated with the current token. The project_id is automatically populated from the authentication context. Cross-tenant operations are not supported.
-
Immutable fields: label and id. If these fields are included in the request body, the server ignores them and retains their original values. Modifiable fields: description, allow_all, ip_whitelist, resident_model_version_whitelist, and endpoint_whitelist.
URI
PUT /v2/{project_id}/maas/api-auth/api-keys/{key_id}
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition: Project ID, which uniquely identifies tenant resources in Huawei Cloud and is associated with a specific region. It is used to locate the project space to which the resources belong when calling Huawei Cloud APIs. You can obtain the value by calling the API for obtaining a project ID and name. Constraints: N/A Range: N/A Default Value: N/A |
| key_id | Yes | String | Definition: API key ID. You can obtain the value by calling the API for querying the API key list. Constraints: N/A Range: N/A Default Value: N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| id | No | String | Definition: API key ID. You can obtain the value by calling the API for querying the API key list. Constraints: The value cannot be modified. Range: N/A Default Value: N/A |
| description | No | String | Definition: Description of the API key. A string of up to 100 characters. Constraints: N/A Range: N/A Default Value: Empty string. |
| allow_all | Yes | Boolean | Definition: Specifies whether access is allowed from all IP addresses. Constraints: N/A Range: Default Value: true |
| ip_whitelist | No | Array of strings | Definition: The API key IP address whitelist is a security feature in Huawei Cloud Model as a Service (MaaS) that restricts the use of an API key to specified IP addresses when calling model services. This helps prevent unauthorized use if the API key is compromised. Example values: Constraints: IP address validation rules:
|
| resident_model_version_whitelist | No | Definition: Whitelist of resident model versions, which restricts the resident model versions that can be accessed. Range: N/A | |
| endpoint_whitelist | No | EndpointWhitelist object | Definition: Whitelist of endpoints, which restricts the endpoints that can be accessed. Range: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| overall | No | String | Definition: Model service scope (including the model services and their versions) where the API key takes effect. Constraints: N/A Range: Default Value: Empty string. |
| whitelist | No | Array of Whitelist objects | Definition: Whitelist of resident model versions. Each entry specifies a resident model and its version that can be accessed. Range: Whitelist object array. For details, see the field breakdown below. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| resident_model_id | No | String | Definition: Resident model ID. The following uses the Chrome browser as an example to describe how to obtain the resident model ID: On the Real-Time Inference > Built-in Services page in the MaaS console, press F12 to open DevTools. Choose the Network tab and search for query. Click the entry whose name starts with query?business_type=payment. In the Response tab, search for the desired model name, such as DeepSeek-V4.1-Flash. The value of the resident_model_id parameter is the resident model ID. Constraints: N/A Range: N/A Default Value: N/A |
| version_whitelist | No | String | Definition: Whitelisted versions of the resident model that can be accessed. Separate multiple versions with commas (,). The following uses the Chrome browser as an example to describe how to obtain the resident model version name: On the Real-Time Inference > Built-in Services page in the MaaS console, press F12 to open DevTools. Choose the Network tab and search for query. Click the entry whose name starts with query?business_type=payment. In the Response tab, search for the desired model name, such as DeepSeek-V4.1-Flash. The ID of the data whose version_name is DeepSeek-V4.1-Flash under version_list is the resident model version. Constraints: N/A Range: N/A Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| overall | No | String | Definition: Overall bypass policy. Constraints: N/A Range: The value "all" indicates that all requests are allowed to bypass. An empty string indicates that the overall bypass function is disabled. Default Value: Empty string. |
| whitelist | No | Array of strings | Definition: Whitelist of endpoint IDs. Only the endpoints in the whitelist can be accessed. You can obtain the ID by calling the API for querying endpoints. Constraints: N/A |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| id | String | Definition: Unique ID of an API key, which is automatically generated by the system. Range: N/A |
| api_key | String | Definition: Plaintext of the original API key generated by the inference service (returned only once during creation). A string of up to 255 characters. Range: N/A |
| label | String | Definition: Display name of the API key, which is the same as the label in the request. Range: N/A |
| description | String | Definition: Description of the API key, which is the same as the description in the request. A string of up to 100 characters. Range: N/A |
| allow_all | Boolean | Definition: Specifies whether access is allowed from all IP addresses. Range: |
| ip_whitelist | Array of strings | Definition: IP address whitelist. The effective value is displayed in the command output. Range: N/A |
| resident_model_version_whitelist | Definition: Whitelist information of the resident model version, which is the same as the value in the request. Range: N/A | |
| endpoint_whitelist | EndpointWhitelist object | Definition: Whitelist information of the endpoint, which is the same as the value in the request. Range: N/A |
| Parameter | Type | Description |
|---|---|---|
| overall | String | Definition: Model service scope (including the model services and their versions) where the API key takes effect. Range: |
| whitelist | Array of Whitelist objects | Definition: Whitelist of resident model versions. Each entry specifies a resident model and its version that can be accessed. Range: Whitelist object array. For details, see the field breakdown below. |
| Parameter | Type | Description |
|---|---|---|
| resident_model_id | String | Definition: Resident model ID. The following uses the Chrome browser as an example to describe how to obtain the resident model ID: On the Real-Time Inference > Built-in Services page in the MaaS console, press F12 to open DevTools. Choose the Network tab and search for query. Click the entry whose name starts with query?business_type=payment. In the Response tab, search for the desired model name, such as DeepSeek-V4.1-Flash. The value of the resident_model_id parameter is the resident model ID. Range: N/A |
| version_whitelist | String | Definition: Whitelisted versions of the resident model that can be accessed. Separate multiple versions with commas (,). The following uses the Chrome browser as an example to describe how to obtain the resident model version name: On the Real-Time Inference > Built-in Services page in the MaaS console, press F12 to open DevTools. Choose the Network tab and search for query. Click the entry whose name starts with query?business_type=payment. In the Response tab, search for the desired model name, such as DeepSeek-V4.1-Flash. The ID of the data whose version_name is DeepSeek-V4.1-Flash under version_list is the resident model version. Range: N/A |
| Parameter | Type | Description |
|---|---|---|
| overall | String | Definition: Overall bypass policy. Range: The value "all" indicates that all requests are allowed to bypass. An empty string indicates that the overall bypass function is disabled. |
| whitelist | Array of strings | Definition: Whitelist of endpoint IDs. Only the endpoints in the whitelist can be accessed. You can obtain the ID by calling the API for querying endpoints. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_msg | String | Definition: Error message. Range: N/A |
| error_code | String | Definition: Error code. Range: N/A |
Example Requests
-
The permission scope is not limited.
PUT https://{endpoint}/v2/{project_id}/maas/api-auth/api-keys/801dbb99-34e6-43c0-a6b0-a45695c2a653 { "description" : "test-Modify.", "allow_all" : true } -
PUT https://{endpoint}/v2/{project_id}/maas/api-auth/api-keys/801dbb99-34e6-43c0-a6b0-a45695c2a653 { "description" : "test-Modify 1.", "allow_all" : false, "ip_whitelist" : [ "192.168.1.1", "192.168.1.10-192.168.1.100", "192.168.10.0/24" ], "resident_model_version_whitelist" : { "overall" : "", "whitelist" : [ { "resident_model_id" : "8f7b4934-88a5-48ed-8188-f479e202453f", "version_whitelist" : "all" }, { "resident_model_id" : "2e34e492-5920-4d12-9910-7cef0d0f6a44", "version_whitelist" : "91d41083-2b04-4f78-b346-ba455ee4fa62" } ] }, "endpoint_whitelist" : { "overall" : "none", "whitelist" : [ ] } }
Example Responses
Status code: 200
{
"id" : "801dbb99-34e6-43c0-a6b0-a45695c2a653",
"label" : "ak-ooKnYK",
"description" : "test-Modify 1.",
"allow_all" : false,
"ip_whitelist" : [ "192.168.1.1", "192.168.1.10-192.168.1.100", "192.168.10.0/24" ],
"resident_model_version_whitelist" : {
"overall" : "",
"whitelist" : [ {
"resident_model_id" : "8f7b4934-88a5-48ed-8188-f479e202453f",
"version_whitelist" : "all"
}, {
"resident_model_id" : "2e34e492-5920-4d12-9910-7cef0d0f6a44",
"version_whitelist" : "91d41083-2b04-4f78-b346-ba455ee4fa62"
} ]
},
"endpoint_whitelist" : {
"overall" : "none",
"whitelist" : [ ]
}
} Status code: 403
{
"error_msg" : "Invalid token.",
"error_code" : "ModelArts.0104"
} Status Codes
| Status Code | Description |
|---|---|
| 200 | API key modified. |
| 403 | The user authentication token is abnormal. |
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot