Updated on 2026-05-18 GMT+08:00

Creating an AI API Key

Function

Create an AI API key. It is used for AI API key-based authentication.

Constraints

The AI API key function can be used only when the whitelist is enabled.

Calling Method

For details, see Calling APIs.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    apig:app:addAiApiKey

    Write

    instance *

    • g:ResourceTag/<tag-key>

    • g:EnterpriseProjectId

    -

    -

URI

POST /v2/{project_id}/apigw/instances/{instance_id}/apps/{app_id}/ai-api-keys

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain it, see Obtaining a Project ID.

instance_id

Yes

String

Gateway ID, which can be obtained from the gateway information on the APIG console.

app_id

Yes

String

Credential ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is a token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

ai_api_key

No

String

AI API key value. If no value is specified, a random string is automatically generated in the background.

Enter 8 to 128 characters. Only letters, digits, and special characters +-_/= are allowed.

Minimum: 8

Maximum: 128

alias

No

String

Alias of the AI API key. Enter 1 to 100 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Minimum: 1

Maximum: 100

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

ai_api_key

String

AI API key value. If no value is specified, a random string is automatically generated in the background.

Enter 8 to 128 characters. Only letters, digits, and special characters +-_/= are allowed.

Minimum: 8

Maximum: 128

alias

String

Alias of the AI API key. Enter 1 to 100 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Minimum: 1

Maximum: 100

app_id

String

Credential ID.

Minimum: 32

Maximum: 36

create_time

String

Creation time.

id

String

AI API key ID.

Minimum: 32

Maximum: 36

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 403

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 404

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

Create an AI API key that is manually entered.

{
  "ai_api_key" : "GjOD3g80AABuuFeEJpVQADBlAjBh3UzC7i3gFxUDb5pWBz9wUcw9+8/bFZ1B",
  "alias" : "test1"
}

Example Responses

Status code: 200

Created

  • Example 1

    {
      "ai_api_key" : "GjOD3g80AABuuFeEJpVQADBlAjBh3UzC7i3gFxUDb5pWBz9wUcw9+8/bFZ1B",
      "alias" : "test1",
      "app_id" : "9ed8b7fe84224de681e7d7a5587e76dc",
      "create_time" : "2020-07-24T02:37:24.835128293Z",
      "id" : "32dc8ca22d1b4b9cb94022186880576b"
    }
  • Example 2

    {
      "ai_api_key" : "GjOD3g80AABuuFeEJpVQADBlAjBh3UzC7i3gFxUDb5pWBz9wUcw9+8/bFZ1B",
      "alias" : "",
      "app_id" : "9ed8b7fe84224de681e7d7a5587e76dc",
      "create_time" : "2020-07-24T02:37:24.835128293Z",
      "id" : "32dc8ca22d1b4b9cb94022186880576b"
    }

Status code: 400

Bad Request

{
  "error_code" : "APIG.2012",
  "error_msg" : "Invalid parameter value,parameterName:app_id. Please refer to the support documentation"
}

Status code: 401

Unauthorized

{
  "error_code" : "APIG.1002",
  "error_msg" : "Incorrect token or token resolution failed"
}

Status code: 403

Forbidden

{
  "error_code" : "APIG.1005",
  "error_msg" : "No permissions to request this method"
}

Status code: 404

Not Found

{
  "error_code" : "APIG.3004",
  "error_msg" : "App 9ed8b7fe84224de681e7d7a5587e76dc does not exist"
}

Status code: 500

Internal Server Error

{
  "error_code" : "APIG.9999",
  "error_msg" : "System error"
}

Status Codes

Status Code

Description

200

Created

400

Bad Request

401

Unauthorized

403

Forbidden

404

Not Found

500

Internal Server Error

Error Codes

See Error Codes.