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
| Method | Description |
|---|---|
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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| page_num | int | No | 1 | Page number, starting from 1 |
| page_size | int | No | 10 | Items per page |
| provider | str | No | None | Filter by provider |
| timezone | str | No | None | Timezone for time field localization, e.g. "Asia/Shanghai" |
Response
Returns BaseResponse[ApiKeyResultVO].
ApiKeyResultVO fields:
| Field | Type | Description |
|---|---|---|
| totalApiCalls | int | Total API call count |
| activeKeys | int | Number of active keys |
| api_keys | PageInfo[ApikeyVO] | Paginated API key data |
ApikeyVO fields:
| Field | Type | Description |
|---|---|---|
| id | str | ApiKey ID |
| name | str | Key name |
| key | str | Key content (masked) |
| provider | str | Provider name |
| providerId | str | Provider ID |
| account | str | Account info |
| accountId | str | Account ID |
| projectID | str | Project ID |
| created | datetime | Creation time |
| lastUsedAt | datetime | Last used time |
| status | str | Status |
| accessKeyID | str | AccessKey ID (masked) |
| accessKeySecret | str | AccessKey Secret (masked) |
| resaleStatus | str | Resale status |
Errors
| Code | Exception | When |
|---|---|---|
2000 / 2002 | AuthenticationError | API Key invalid |
2007 | PermissionError | Permission denied |
3001 | AuthenticationError | Token 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| provider | str | Yes | -- | Provider id (NOT display name); use the id field returned by api_keys.providers(), e.g. "dashscope", "openrouter". |
| key_name | str | No | None | Key name |
| status | int | No | None | Initial status |
| access_key_id | str | No | None | AccessKey ID |
| access_key_secret | str | No | None | AccessKey Secret |
| tpm_limit | str | No | None | TPM (tokens per minute) limit |
| token_limit | str | No | None | Total 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
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Invalid request parameters |
2000 / 2002 | AuthenticationError | API Key invalid |
2007 | PermissionError | Permission denied |
3000 | APIError | Invalid provider (e.g. passed display name instead of id) |
3001 | AuthenticationError | Token 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| path_id | str | Yes | -- | ApiKey ID (URL path parameter, for routing) |
| id | int | No | None | ApiKey database primary key (used for locating the record) |
| provider | str | No | None | Provider (must be a valid BYOK provider if provided) |
| key_name | str | No | None | Key name |
| aliyun_account_id | str | No | None | Aliyun account ID |
| status | int | No | None | Status |
| access_key_id | str | No | None | AccessKey ID |
| access_key_secret | str | No | None | AccessKey Secret |
| resale_status | str | No | None | Resale status |
| tpm_limit | str | No | None | TPM limit |
| token_limit | str | No | None | Total token limit |
Response
Returns BaseResponse[bool]. data=True on success.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Invalid request parameters |
1002 | NotFoundError | API key not found |
2000 / 2002 | AuthenticationError | API Key invalid |
2007 | PermissionError | Permission denied |
3001 | AuthenticationError | Token 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| id | str | Yes | -- | ApiKey ID |
Response
Returns BaseResponse[bool]. data=True on success.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Invalid request parameters |
1002 | NotFoundError | API key not found |
2000 / 2002 | AuthenticationError | API Key invalid |
2007 | PermissionError | Permission denied |
3001 | AuthenticationError | Token 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| id | str | Yes | -- | ApiKey ID |
| status | int | Yes | -- | Target status: 1=enable, 0=disable |
Response
Returns BaseResponse[bool]. data=True on success.
Errors
| Code | Exception | When |
|---|---|---|
1001 | ValidationError | Invalid request parameters |
1002 | NotFoundError | API key not found |
2000 / 2002 | AuthenticationError | API Key invalid |
2007 | PermissionError | Permission denied |
3001 | AuthenticationError | Token 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| aliyun_account_id | str | No | None | Aliyun account ID (for providers that require it) |
| access_key_id | str | No | None | AccessKey ID |
| access_key_secret | str | No | None | AccessKey Secret |
| provider | str | No | None | Provider name |
Response
Returns BaseResponse[bool]. data=True if connection is successful.
Errors
| Code | Exception | When |
|---|---|---|
2000 / 2002 | AuthenticationError | API Key invalid |
2007 | PermissionError | Permission denied |
3001 | AuthenticationError | Token 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:
| Field | Type | Description |
|---|---|---|
| id | str | Provider identifier |
| name | str | Provider display name |
Errors
| Code | Exception | When |
|---|---|---|
2000 / 2002 | AuthenticationError | API Key invalid |
2007 | PermissionError | Permission denied |
3001 | AuthenticationError | Token expired and refresh failed |