TypeScript SDK
Official TypeScript client library for the API Router Console API.
- Node.js: >= 16.0.0
- TypeScript: >= 5.0 (for development)
Why use the SDK
- First-class TypeScript types — every request and response is fully typed; the SDK ships its own
.d.tsfiles. - Transparent auth — your API key is exchanged for a Bearer token internally and refreshed on expiry. You never call
loginByApiKeymanually. - SSE-aware —
modelLab.stream()returns a native async iterator over response chunks. - CJS + ESM — works in both
requireandimportstyle projects.
Installation
npm install wlt-platform
# or
yarn add wlt-platform
pnpm add wlt-platform
Quick start
import { WltClient } from 'wlt-platform';
const client = new WltClient({
apiKey: 'your-api-key',
baseUrl: 'https://console.example.com',
});
// List your API keys (Secrets)
const result = await client.secrets.list({ pageNum: 1, pageSize: 20 });
console.log(result.pageInfo.list);
// Stream a chat completion
for await (const chunk of client.modelLab.stream({
provider: 'dashscope',
modelName: 'Qwen2.5-72B-Instruct',
userPrompt: 'Hello!',
})) {
process.stdout.write(chunk);
}
Configuration
For this environment, set baseUrl to https://console.example.com.
import { WltClient } from 'wlt-platform';
const client = new WltClient({
apiKey: 'your-api-key', // required
baseUrl: 'https://console.example.com',
timeout: 60_000, // default 30000
maxRetries: 3, // default 2
defaultHeaders: { 'X-Custom': 'v' },
});
Base URL resolution
Priority, highest → lowest:
| Priority | Source |
|---|---|
| 1 | Constructor baseUrl argument |
| 2 | WLT_BASE_URL environment variable |
| 3 | baseUrl / base_url in ~/.wlt/config.json (CLI users only) |
| 4 | Built-in default |
Trailing slashes are stripped automatically.
Module reference
| Module | Accessor | Methods |
|---|---|---|
| User | client.user | 1 |
| Secret | client.secrets | 8 |
| ApiKey | client.apiKeys | 7 |
| Usage | client.usage | 4 |
| Billing | client.billing | 4 |
| Payment | client.payment | 5 |
| Model Gallery | client.modelGallery | 3 |
| Model Lab | client.modelLab | 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.
import { AdminClient } from 'wlt-platform';
const admin = new AdminClient({
username: 'admin',
password: 'your-admin-password',
baseUrl: 'https://console.example.com',
});
const info = await admin.auth.info(); // admin identity
const totals = await admin.billing.customerTotal({ // billing rollup
startTime: '2026-06-01 00:00:00',
endTime: '2026-06-30 23:59:59',
});
const customers = await admin.customer.list({ pageNum: 1, pageSize: 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.rateLimit | 2 |
| Context | admin.context | 3 |