Package Exports
- videorouter-sdk
Readme
@videorouter/sdk
Official TypeScript/JavaScript SDK for VideoRouter - AI Video Generation API.
Generate videos using Wan 2.1, Kling, Luma, Sora, Veo, and more with a unified API.
Installation
npm install @videorouter/sdk
# or
yarn add @videorouter/sdk
# or
pnpm add @videorouter/sdkQuick Start
import { VideoRouter } from '@videorouter/sdk';
const client = new VideoRouter({
apiKey: process.env.VIDEOROUTER_API_KEY
});
// Generate a video and wait for completion
const result = await client.generateAndWait({
model: 'wavespeedai/wan-2.1-t2v-480p',
prompt: 'A majestic dragon flying over snow-capped mountains at sunset'
});
console.log('Video URL:', result.video_url);Usage
Initialize the Client
import { VideoRouter } from '@videorouter/sdk';
const client = new VideoRouter({
apiKey: 'vr_...', // Required: Your API key
baseUrl: 'https://...', // Optional: Custom API URL
timeout: 30000 // Optional: Request timeout (ms)
});Generate Videos
Text-to-Video
const job = await client.generate({
model: 'wavespeedai/wan-2.1-t2v-480p',
prompt: 'A cat walking across a sunlit room',
duration: 5
});
console.log('Job ID:', job.job_id);
console.log('Estimated cost:', job.estimated_cost, 'credits');Image-to-Video
const job = await client.generate({
model: 'klingai/kling-v2.5-turbo-pro',
prompt: 'Animate with gentle camera movement',
image_url: 'https://example.com/image.jpg',
duration: 5
});Interpolation (Start + End Image)
const job = await client.generate({
model: 'google/veo-3.1-fast',
prompt: 'Smooth transition between the two scenes',
image_url: 'https://example.com/start.jpg',
end_image_url: 'https://example.com/end.jpg'
});Poll for Completion
// Option 1: Generate then wait
const job = await client.generate({ ... });
const result = await client.waitForCompletion(job.job_id);
// Option 2: Generate and wait in one call
const result = await client.generateAndWait({ ... });
// With progress callback
const result = await client.waitForCompletion(job.job_id, {
pollInterval: 3000, // Check every 3 seconds
timeout: 600000, // Max 10 minutes
onStatusChange: (status) => console.log('Status:', status)
});Check Job Status
const status = await client.getJob('job_123');
switch (status.status) {
case 'pending':
console.log('Waiting to start...');
break;
case 'processing':
console.log('Generating video...');
break;
case 'completed':
console.log('Done!', status.video_url);
break;
case 'failed':
console.log('Error:', status.error);
break;
}List Available Models
// Get all models
const models = await client.getModels();
// Get by type
const textToVideo = await client.getModels({ type: 'text-to-video' });
const imageToVideo = await client.getModels({ type: 'image-to-video' });
// Convenience methods
const t2v = await client.getTextToVideoModels();
const i2v = await client.getImageToVideoModels();
const interp = await client.getInterpolationModels();Get Model Details
const model = await client.getModel('wavespeedai/wan-2.1-t2v-480p');
console.log('Name:', model.name);
console.log('Type:', model.type);
console.log('Cost:', model.costPerSecond, '$/sec');
console.log('Duration:', model.minDuration, '-', model.maxDuration, 'seconds');
console.log('Parameters:', model.parameters);Check Credit Balance
const { credits_balance } = await client.getBalance();
console.log('Credits:', credits_balance);Estimate Cost
const estimate = await client.estimateCost('wavespeedai/wan-2.1-t2v-480p', 5);
console.log('Estimated cost:', estimate.cost, 'credits');
console.log('Duration:', estimate.duration, 'seconds');
console.log('Model:', estimate.model.name);Error Handling
The SDK throws typed errors for different failure cases:
import {
VideoRouter,
AuthenticationError,
InsufficientCreditsError,
ValidationError,
RateLimitError,
PollTimeoutError,
GenerationError
} from '@videorouter/sdk';
try {
const result = await client.generateAndWait({ ... });
} catch (error) {
if (error instanceof AuthenticationError) {
console.log('Invalid API key');
} else if (error instanceof InsufficientCreditsError) {
console.log('Not enough credits');
} else if (error instanceof ValidationError) {
console.log('Invalid request:', error.message);
} else if (error instanceof RateLimitError) {
console.log('Rate limited, retry after:', error.retryAfter, 'seconds');
} else if (error instanceof PollTimeoutError) {
console.log('Timeout waiting for job:', error.jobId);
} else if (error instanceof GenerationError) {
console.log('Generation failed:', error.generationError);
}
}Available Models
Text-to-Video
| Model ID | Name | Cost/sec |
|---|---|---|
wavespeedai/wan-2.1-t2v-480p |
Wan 2.1 480p | $0.02 |
wavespeedai/wan-2.1-t2v-720p |
Wan 2.1 720p | $0.04 |
wan-video/wan-2.2-t2v-fast |
Wan 2.2 Fast | $0.05 |
pixverse/pixverse-v4 |
Pixverse V4 | $0.05 |
openai/sora-2-standard |
Sora 2 Standard | $0.21 |
openai/sora-2-pro |
Sora 2 Pro | $0.42 |
Image-to-Video
| Model ID | Name | Cost/sec |
|---|---|---|
wavespeedai/wan-2.1-i2v-480p |
Wan 2.1 I2V | $0.02 |
klingai/kling-v2.5-turbo-pro |
Kling V2.5 | $0.10 |
klingai/kling-v2.6 |
Kling V2.6 | $0.125 |
luma/ray-2-720p |
Luma Ray 2 | $0.10 |
luma/ray-flash-2-720p |
Luma Flash | $0.05 |
Interpolation
| Model ID | Name | Cost/sec |
|---|---|---|
google/veo-3.1-fast |
Veo 3.1 Fast | $0.10 |
wan-video/wan-2.2-i2v-fast |
Wan 2.2 Interp | $0.05 |
TypeScript Types
All types are exported for use in your code:
import type {
VideoModel,
ModelType,
JobStatus,
GenerateRequest,
GenerateResponse,
JobStatusResponse
} from '@videorouter/sdk';Requirements
- Node.js 18+ (uses native fetch)
- Or provide your own fetch implementation
License
MIT