Python SDK
Official Python client library for the API Router Console API.
Why use the SDK
- Typed models — every response is a pydantic v2 model, so IDEs autocomplete fields and parsers reject malformed data.
- Transparent auth — the SDK exchanges your API key for a Bearer token at construction time and auto-refreshes on expiry. You never call
loginByApiKeymanually. - Sync + async —
WltClient(sync) andAsyncWltClient(async) share an identical method surface. - Retries built in — failed network calls and expired-token responses are retried automatically.
Installation
pip install wlt-platform
Quick start
from wlt import WltClient
client = WltClient(
api_key="your-api-key",
base_url="https://console.example.com",
)
# List your API keys (Secrets)
result = client.secrets.list(page_num=1, page_size=20)
print(result.page_info.list)
# Stream a chat completion
for chunk in client.model_lab.stream(
provider="dashscope",
model_name="Qwen2.5-72B-Instruct",
user_prompt="Hello!",
):
print(chunk, end="", flush=True)
client.close()
For async usage, use
AsyncWltClientwithawaiton each method.
Configuration
For this environment, set base_url to https://console.example.com.
client = WltClient(
api_key="your-api-key", # Required. Auto-exchanged for Bearer token
base_url="https://console.example.com",
timeout=30.0, # Request timeout in seconds (default: 30)
max_retries=2, # Max retry attempts (default: 2)
)
Base URL resolution
Priority, highest → lowest:
| Priority | Source |
|---|---|
| 1 | Constructor base_url argument (or CLI --base-url) |
| 2 | WLT_BASE_URL environment variable |
| 3 | base_url field in ~/.wlt/config.json (CLI users only) |
| 4 | Built-in default |
Trailing slashes are stripped automatically; https://host/ and https://host are equivalent.
Module reference
| Module | Accessor | Methods |
|---|---|---|
| User | client.user | 1 |
| Secret | client.secrets | 8 |
| ApiKey | client.api_keys | 7 |
| Usage | client.usage | 4 |
| Billing | client.billing | 4 |
| Payment | client.payment | 5 |
| Model Gallery | client.model_gallery | 3 |
| Model Lab | client.model_lab | 3 |
Admin scope
A separate AdminClient handles admin-scope operations (billing reports, end-customer CRUD, model pricing, credits, rate limits, and context records). It authenticates with an admin username and password — no captcha, no API key — and issues a session token scoped to admin-only endpoints. Instantiate it alongside WltClient when the caller must act as an administrator.
from wlt import AdminClient
admin = AdminClient(
username="admin",
password="your-admin-password",
base_url="https://console.example.com",
)
info = admin.auth.info() # admin identity
totals = admin.billing.customer_total( # billing rollup
start_time="2026-06-01 00:00:00",
end_time="2026-06-30 23:59:59",
)
customers = admin.customer.list(page_num=1, page_size=20) # customer CRUD
| Module | Accessor | Methods |
|---|---|---|
| Auth | admin.auth | 1 |
| Billing | admin.billing | 6 |
| Customer | admin.customer | 3 |
| Pricing | admin.pricing | 9 |
| Credits | admin.credits | 2 |
| Rate Limit | admin.rate_limit | 2 |
| Context | admin.context | 3 |