Skip to main content

ApiKey — Python SDK

Manage Bring-Your-Own-Key credentials for upstream providers.

Overview​

The ApiKey resource manages BYOK (Bring Your Own Key) credentials -- third-party provider keys (e.g. DashScope, OpenRouter) that you register with the gateway so it can relay your requests under your own quota. Methods cover listing, creating, updating, enabling/disabling, deleting, and connectivity testing.

Accessed via client.api_keys.

Available Operations​

MethodDescription
list()List API keys with pagination and optional filters
create()Create a new BYOK API key
update()Update an existing API key
delete()Delete an API key
changeStatus()Enable or disable an API key
testConnect()Test API key connectivity against the upstream provider
providers()List providers available for API keys

list​

List API keys with pagination and optional filters.

Example Usage​

from wlt import WltClient

client = WltClient(api_key="your-api-key", base_url="https://console.example.com")

result = client.api_keys.list(page_num=1, page_size=10)
for key in result.data.apiKeys.list:
print(key.id, key.name, key.provider, key.status)

# Filter by provider
result = client.api_keys.list(provider="dashscope")

Parameters​

ParameterTypeRequiredDefaultDescription
page_numintNo1Page number, starting from 1
page_sizeintNo10Items per page
providerstrNoNoneFilter by provider
timezonestrNoNoneTimezone for time field localization, e.g. "Asia/Shanghai"

Response​

Returns BaseResponse[ApiKeyResultVO].

ApiKeyResultVO fields:

FieldTypeDescription
totalApiCallsintTotal API call count
activeKeysintNumber of active keys
api_keysPageInfo[ApikeyVO]Paginated API key data

ApikeyVO fields:

FieldTypeDescription
idstrApiKey ID
namestrKey name
keystrKey content (masked)
providerstrProvider name
providerIdstrProvider ID
accountstrAccount info
accountIdstrAccount ID
projectIDstrProject ID
createddatetimeCreation time
lastUsedAtdatetimeLast used time
statusstrStatus
accessKeyIDstrAccessKey ID (masked)
accessKeySecretstrAccessKey Secret (masked)
resaleStatusstrResale status

Errors​

CodeExceptionWhen
2000 / 2002AuthenticationErrorAPI Key invalid
2007PermissionErrorPermission denied
3001AuthenticationErrorToken expired and refresh failed

create​

Create a new BYOK API key.

Example Usage​

from wlt import WltClient

client = WltClient(api_key="your-api-key", base_url="https://console.example.com")

new_key = client.api_keys.create(
provider="dashscope",
key_name="my-dashscope-key",
access_key_id="LTAI5t...",
access_key_secret="your-access-key-secret",
tpm_limit="100000",
token_limit="5000000",
)
print(f"Created key ID: {new_key.data.id}")
print(f"Key name: {new_key.data.name}")

Parameters​

ParameterTypeRequiredDefaultDescription
providerstrYes--Provider id (NOT display name); use the id field returned by api_keys.providers(), e.g. "dashscope", "openrouter".
key_namestrNoNoneKey name
statusintNoNoneInitial status
access_key_idstrNoNoneAccessKey ID
access_key_secretstrNoNoneAccessKey Secret
tpm_limitstrNoNoneTPM (tokens per minute) limit
token_limitstrNoNoneTotal token limit

Response​

Returns BaseResponse[ApikeyVO]. The data field contains the newly created API key info.

ApikeyVO fields: see client.api_keys.list() above.

Errors​

CodeExceptionWhen
1001ValidationErrorInvalid request parameters
2000 / 2002AuthenticationErrorAPI Key invalid
2007PermissionErrorPermission denied
3000APIErrorInvalid provider (e.g. passed display name instead of id)
3001AuthenticationErrorToken expired and refresh failed

update​

Update an existing API key.

Example Usage​

from wlt import WltClient

client = WltClient(api_key="your-api-key", base_url="https://console.example.com")

result = client.api_keys.update(
path_id="456",
id=456,
key_name="renamed-key",
tpm_limit="200000",
)
print(f"Success: {result.data}") # True

Parameters​

ParameterTypeRequiredDefaultDescription
path_idstrYes--ApiKey ID (URL path parameter, for routing)
idintNoNoneApiKey database primary key (used for locating the record)
providerstrNoNoneProvider (must be a valid BYOK provider if provided)
key_namestrNoNoneKey name
aliyun_account_idstrNoNoneAliyun account ID
statusintNoNoneStatus
access_key_idstrNoNoneAccessKey ID
access_key_secretstrNoNoneAccessKey Secret
resale_statusstrNoNoneResale status
tpm_limitstrNoNoneTPM limit
token_limitstrNoNoneTotal token limit

Response​

Returns BaseResponse[bool]. data=True on success.

Errors​

CodeExceptionWhen
1001ValidationErrorInvalid request parameters
1002NotFoundErrorAPI key not found
2000 / 2002AuthenticationErrorAPI Key invalid
2007PermissionErrorPermission denied
3001AuthenticationErrorToken expired and refresh failed

delete​

Delete an API key.

Example Usage​

from wlt import WltClient

client = WltClient(api_key="your-api-key", base_url="https://console.example.com")

result = client.api_keys.delete(id="456")
print(f"Success: {result.data}") # True

Parameters​

ParameterTypeRequiredDefaultDescription
idstrYes--ApiKey ID

Response​

Returns BaseResponse[bool]. data=True on success.

Errors​

CodeExceptionWhen
1001ValidationErrorInvalid request parameters
1002NotFoundErrorAPI key not found
2000 / 2002AuthenticationErrorAPI Key invalid
2007PermissionErrorPermission denied
3001AuthenticationErrorToken expired and refresh failed

changeStatus​

Enable or disable an API key.

Example Usage​

from wlt import WltClient

client = WltClient(api_key="your-api-key", base_url="https://console.example.com")

# Disable a key (status: 0=disable, 1=enable)
result = client.api_keys.change_status(id="456", status=0)
print(f"Success: {result.data}") # True

# Enable a key
result = client.api_keys.change_status(id="456", status=1)

Parameters​

ParameterTypeRequiredDefaultDescription
idstrYes--ApiKey ID
statusintYes--Target status: 1=enable, 0=disable

Response​

Returns BaseResponse[bool]. data=True on success.

Errors​

CodeExceptionWhen
1001ValidationErrorInvalid request parameters
1002NotFoundErrorAPI key not found
2000 / 2002AuthenticationErrorAPI Key invalid
2007PermissionErrorPermission denied
3001AuthenticationErrorToken expired and refresh failed

testConnect​

Test API key connectivity by relaying the credentials to the upstream provider.

Example Usage​

from wlt import WltClient

client = WltClient(api_key="your-api-key", base_url="https://console.example.com")

result = client.api_keys.test_connect(
provider="dashscope",
access_key_id="LTAI5t...",
access_key_secret="your-access-key-secret",
)
if result.data:
print("Connection successful!")
else:
print("Connection failed")

Parameters​

ParameterTypeRequiredDefaultDescription
aliyun_account_idstrNoNoneAliyun account ID (for providers that require it)
access_key_idstrNoNoneAccessKey ID
access_key_secretstrNoNoneAccessKey Secret
providerstrNoNoneProvider name

Response​

Returns BaseResponse[bool]. data=True if connection is successful.

Errors​

CodeExceptionWhen
2000 / 2002AuthenticationErrorAPI Key invalid
2007PermissionErrorPermission denied
3001AuthenticationErrorToken expired and refresh failed

providers​

Get the list of providers available for API keys.

Example Usage​

from wlt import WltClient

client = WltClient(api_key="your-api-key", base_url="https://console.example.com")

providers = client.api_keys.providers()
for p in providers.data:
print(p.id, p.name)

Parameters​

None.

Response​

Returns BaseResponse[list[ProviderVO]].

ProviderVO fields:

FieldTypeDescription
idstrProvider identifier
namestrProvider display name

Errors​

CodeExceptionWhen
2000 / 2002AuthenticationErrorAPI Key invalid
2007PermissionErrorPermission denied
3001AuthenticationErrorToken expired and refresh failed