CreateApiKey

Updated at:

Creates a custom API key.

Operation description

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

rdsai:CreateApiKey

get

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

InstanceId

string

No

The instance name.

rds_copilot***_public_cn-*********6

Quantity

integer

No

The number of API keys to create. Default value: 1.

1

KeyName

string

No

The name of the API key.

api-*****

LimitType

string

No

The quota limit type. Valid values:

  • ratio: percentage-based

  • fixed: fixed value

  • auto: automatic allocation

Valid values:

  • auto :

    auto

  • fixed :

    fixed

  • ratio :

    ratio

fixed

LimitRate

number

No

The quota limit percentage.

0.2

TokenQuota

integer

No

The token quota for the current key.

100000

DailyTokenQuota

integer

No

The daily token quota for the API key.

1000000000

RoleName

string

No

RoleArn

string

No

Response elements

Element

Type

Description

Example

object

Schema of Response

RequestId

string

Id of the request

FE9C65D7-930F-57A5-A207-8C396329****

Success

boolean

The request result.

true

Message

string

The returned message.

success

Data

object

The returned data.

CustomKeyList

array<object>

The list of custom API keys.

object

ApiKey

string

Api Key

sk-rds-*****

KeyName

string

The name of the API key.

api-*****

TokenQuota

integer

The token quota for the current key.

100000

DailyTokenQuota

integer

The daily token quota for the API key.

0

LimitType

string

The quota limit type. Valid values:

  • fixed: fixed value

  • ratio: percentage-based

  • auto: automatic allocation

fixed

LimitRate

number

The quota limit percentage.

0.2

RoleArn

string

BaseUrl

string

The URL for model invocation.

http://xxx.yy/v1

SystemApiKey

string

The system-generated key.

sk-rds-xxx

Examples

Success response

JSON format

{
  "RequestId": "FE9C65D7-930F-57A5-A207-8C396329****",
  "Success": true,
  "Message": "success",
  "Data": {
    "CustomKeyList": [
      {
        "ApiKey": "sk-rds-*****",
        "KeyName": "api-*****",
        "TokenQuota": 100000,
        "DailyTokenQuota": 0,
        "LimitType": "fixed",
        "LimitRate": 0.2,
        "RoleArn": ""
      }
    ],
    "BaseUrl": "http://xxx.yy/v1",
    "SystemApiKey": "sk-rds-xxx"
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidIpWhitelistError Invalid IP address or CIDR in whitelist. The IP address or CIDR block in the whitelist is invalid.
400 DomainNotReadyError Domain is not ready yet, please try again later. The domain name is not ready.
400 InstanceQuotaExceededError Instance quota exceeded, cannot create new API key. The instance quota is exhausted, and no new API keys can be created.
400 CustomKeyLimitExceededError Custom key limit exceeded. The maximum number of custom keys has been exceeded.
400 InstanceNotFoundError No active instance found. No active instance was found.
400 InvalidQuotaValueError LimitType must be fixed or ratio. TokenQuota must be a positive integer and limitRate must be between 0.0 and 1.0. The key quota parameter is invalid.
400 QuotaSumExceededError Sum of custom key quotas exceeds instance total quota. The total quota of custom keys exceeds the total quota of the instance.
400 MoPostpayRatioNotAllowedError Ratio mode is not supported for POSTPAY instances. Use 'fixed' mode instead. Pay-as-you-go instances do not support the proportional quota mode.
400 MoProLikeCustomKeyNotAllowed Custom API keys are not supported for Pro or Enterprise instances. Custom API keys are not supported for Pro or Enterprise instances.
400 InvalidQuantityError Invalid quantity: must be an integer between 1 and 50. The quantity must be an integer from 1 to 50.
403 InvalidUserOrder There is no valid order for this UID. There is no valid order for this UID

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.