Skip to main content

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.ts files.
  • Transparent auth — your API key is exchanged for a Bearer token internally and refreshed on expiry. You never call loginByApiKey manually.
  • SSE-aware — modelLab.stream() returns a native async iterator over response chunks.
  • CJS + ESM — works in both require and import style 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:

PrioritySource
1Constructor baseUrl argument
2WLT_BASE_URL environment variable
3baseUrl / base_url in ~/.wlt/config.json (CLI users only)
4Built-in default

Trailing slashes are stripped automatically.

Module reference​

ModuleAccessorMethods
Userclient.user1
Secretclient.secrets8
ApiKeyclient.apiKeys7
Usageclient.usage4
Billingclient.billing4
Paymentclient.payment5
Model Galleryclient.modelGallery3
Model Labclient.modelLab3

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
ModuleAccessorMethods
Authadmin.auth1
Billingadmin.billing6
Customeradmin.customer3
Pricingadmin.pricing9
Creditsadmin.credits2
Rate Limitadmin.rateLimit2
Contextadmin.context3