@renderingvideo/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RenderingVideo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,292 @@
1
+ # @renderingvideo/sdk
2
+
3
+ Official Node.js SDK for the RenderingVideo API. Create videos programmatically with ease.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @renderingvideo/sdk
9
+ # or
10
+ yarn add @renderingvideo/sdk
11
+ # or
12
+ pnpm add @renderingvideo/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { RenderingVideo } from '@renderingvideo/sdk';
19
+
20
+ // Initialize client
21
+ const client = new RenderingVideo({ apiKey: 'sk-your-api-key' });
22
+
23
+ // Create a video task
24
+ const task = await client.video.create({
25
+ config: {
26
+ meta: { version: '2.0.0', width: 1920, height: 1080, fps: 30 },
27
+ tracks: [
28
+ {
29
+ clips: [
30
+ { type: 'text', text: 'Hello World', start: 0, duration: 5 }
31
+ ]
32
+ }
33
+ ]
34
+ }
35
+ });
36
+
37
+ // Start rendering
38
+ const renderTask = await client.video.render(task.taskId, {
39
+ webhookUrl: 'https://your-server.com/webhook'
40
+ });
41
+
42
+ console.log('Task ID:', renderTask.taskId);
43
+ console.log('Status:', renderTask.status);
44
+ ```
45
+
46
+ ## Features
47
+
48
+ - **Video Creation**: Create and render videos programmatically
49
+ - **Task Management**: List, get, and delete video tasks
50
+ - **File Management**: Upload and manage assets (images, videos, audio)
51
+ - **Preview Links**: Create temporary preview links without consuming credits
52
+ - **Credit Management**: Check your credit balance
53
+ - **Webhook Support**: Configure webhooks for completion notifications
54
+ - **TypeScript**: Full TypeScript support with type definitions
55
+ - **Zero Dependencies**: No external runtime dependencies
56
+
57
+ ## API Reference
58
+
59
+ ### Client Initialization
60
+
61
+ ```typescript
62
+ import { RenderingVideo } from '@renderingvideo/sdk';
63
+
64
+ // With options object
65
+ const client = new RenderingVideo({
66
+ apiKey: 'sk-xxx', // Required: Your API key
67
+ baseUrl: 'https://...', // Optional: Custom API URL
68
+ timeout: 30000 // Optional: Request timeout in ms (default: 30000)
69
+ });
70
+
71
+ // Or with positional arguments
72
+ const client = new RenderingVideo('sk-xxx', { timeout: 60000 });
73
+ ```
74
+
75
+ ### Video Operations
76
+
77
+ ```typescript
78
+ // Create video task (does not start rendering)
79
+ const task = await client.video.create({
80
+ config: { ... }, // VideoSchema configuration
81
+ metadata: { key: 'value' } // Optional: Custom metadata
82
+ });
83
+
84
+ // Create and immediately start rendering
85
+ const task = await client.video.createAndRender({
86
+ config: { ... },
87
+ webhookUrl: 'https://...', // Optional: Webhook for completion notification
88
+ numWorkers: 5 // Optional: Number of render workers (default: 5)
89
+ });
90
+
91
+ // List video tasks
92
+ const { tasks, pagination } = await client.video.list({
93
+ page: 1,
94
+ limit: 20,
95
+ status: 'completed' // Optional: Filter by status
96
+ });
97
+
98
+ // Get task details
99
+ const task = await client.video.get('task-id');
100
+
101
+ // Trigger rendering
102
+ const renderTask = await client.video.render('task-id', {
103
+ webhookUrl: 'https://...',
104
+ numWorkers: 5
105
+ });
106
+
107
+ // Delete a task
108
+ const result = await client.video.delete('task-id');
109
+ console.log(result.deleted, result.remoteDeleted);
110
+ ```
111
+
112
+ ### File Operations
113
+
114
+ ```typescript
115
+ // Upload a single file (Browser)
116
+ const fileInput = document.querySelector('#file-input');
117
+ const { assets } = await client.files.uploadFile(fileInput.files[0]);
118
+
119
+ // Upload from buffer (Node.js)
120
+ const fs = require('fs');
121
+ const buffer = fs.readFileSync('./image.png');
122
+ const { assets } = await client.files.uploadBuffer(buffer, 'image.png', 'image/png');
123
+
124
+ // Upload with FormData
125
+ const formData = new FormData();
126
+ formData.append('file', blob, 'video.mp4');
127
+ const { assets } = await client.files.upload(formData);
128
+
129
+ // List uploaded files
130
+ const { files, pagination } = await client.files.list({
131
+ page: 1,
132
+ limit: 50,
133
+ type: 'image' // Optional: Filter by 'image', 'video', or 'audio'
134
+ });
135
+
136
+ // Delete a file
137
+ const result = await client.files.delete('asset-id');
138
+ ```
139
+
140
+ ### Preview Operations
141
+
142
+ ```typescript
143
+ // Create a temporary preview (7 days validity, no credits)
144
+ const preview = await client.preview.create({
145
+ meta: { version: '2.0.0', width: 1920, height: 1080 },
146
+ tracks: [...]
147
+ });
148
+ console.log(preview.previewUrl, preview.tempId);
149
+
150
+ // Get preview configuration
151
+ const { config } = await client.preview.get('temp-id');
152
+
153
+ // Convert preview to permanent task (no rendering)
154
+ const result = await client.preview.convert('temp-id', {
155
+ category: 'marketing' // Optional
156
+ });
157
+
158
+ // Convert and immediately render
159
+ const result = await client.preview.render('temp-id', {
160
+ category: 'api', // Optional
161
+ webhookUrl: 'https://...', // Optional
162
+ numWorkers: 5 // Optional
163
+ });
164
+ ```
165
+
166
+ ### Credits
167
+
168
+ ```typescript
169
+ // Get credit balance
170
+ const { credits } = await client.credits.get();
171
+ console.log(`Available: ${credits} credits`);
172
+
173
+ // Check if enough credits
174
+ const hasEnough = await client.credits.hasEnough(100);
175
+ ```
176
+
177
+ ## Error Handling
178
+
179
+ ```typescript
180
+ import {
181
+ RenderingVideoError,
182
+ AuthenticationError,
183
+ InvalidApiKeyError,
184
+ InsufficientCreditsError,
185
+ ValidationError,
186
+ NotFoundError,
187
+ AlreadyRenderingError,
188
+ UploadError,
189
+ StorageLimitError,
190
+ } from '@renderingvideo/sdk';
191
+
192
+ try {
193
+ const task = await client.video.create({ config: {...} });
194
+ } catch (error) {
195
+ if (error instanceof InsufficientCreditsError) {
196
+ console.log('Not enough credits');
197
+ } else if (error instanceof AlreadyRenderingError) {
198
+ console.log('Task is already rendering');
199
+ } else if (error instanceof ValidationError) {
200
+ console.log('Invalid config:', error.message);
201
+ } else if (error instanceof NotFoundError) {
202
+ console.log('Task not found');
203
+ } else if (error instanceof StorageLimitError) {
204
+ console.log('Storage quota exceeded');
205
+ } else if (error instanceof RenderingVideoError) {
206
+ console.log(`API error [${error.code}]: ${error.message}`);
207
+ }
208
+ }
209
+ ```
210
+
211
+ ## Webhook Handling
212
+
213
+ When rendering completes, the webhook receives:
214
+
215
+ ```typescript
216
+ interface WebhookPayload {
217
+ taskId: string;
218
+ renderTaskId: string;
219
+ status: 'completed' | 'failed';
220
+ videoUrl?: string;
221
+ error?: string | null;
222
+ timestamp: string;
223
+ }
224
+ ```
225
+
226
+ Example Express.js handler:
227
+
228
+ ```typescript
229
+ app.post('/webhook', express.json(), (req, res) => {
230
+ const { taskId, status, videoUrl, error } = req.body;
231
+
232
+ if (status === 'completed') {
233
+ console.log(`Video ${taskId} ready: ${videoUrl}`);
234
+ } else {
235
+ console.log(`Video ${taskId} failed: ${error}`);
236
+ }
237
+
238
+ res.status(200).send('OK');
239
+ });
240
+ ```
241
+
242
+ ## TypeScript Support
243
+
244
+ This SDK is written in TypeScript and provides full type definitions.
245
+
246
+ ```typescript
247
+ import type {
248
+ // Configuration
249
+ VideoConfig,
250
+ VideoMeta,
251
+ Track,
252
+ Clip,
253
+ Asset,
254
+ // Task
255
+ Task,
256
+ TaskList,
257
+ TaskStatus,
258
+ // Files
259
+ UploadedFile,
260
+ UploadResult,
261
+ FileList,
262
+ // Preview
263
+ PreviewResult,
264
+ PreviewConfig,
265
+ // Credits
266
+ Credits,
267
+ // Options
268
+ CreateVideoOptions,
269
+ RenderOptions,
270
+ ListTasksOptions,
271
+ ClientOptions,
272
+ } from '@renderingvideo/sdk';
273
+ ```
274
+
275
+ ## Credit Calculation
276
+
277
+ - **Cost = Video duration (seconds) × Quality multiplier**
278
+
279
+ | Quality | Short Edge | Multiplier |
280
+ |---------|------------|------------|
281
+ | 720p | ≥720px | 1.0 |
282
+ | 1080p | ≥1080px | 1.5 |
283
+ | 2K | ≥1440px | 2.0 |
284
+
285
+ ## Requirements
286
+
287
+ - Node.js 18.0.0 or higher
288
+ - No external runtime dependencies
289
+
290
+ ## License
291
+
292
+ MIT License