@kvidai/sdk 0.0.0-stage → 0.2.2

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/README.md CHANGED
@@ -1,3 +1,153 @@
1
- # Temporary Holding Version
1
+ # @kvidai/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript SDK for the [kvidai](https://kvid.ai) AI video platform — auth, AI video/image/voice generation, media upload, presets, and the conversational agent.
4
+
5
+ ```bash
6
+ npm i @kvidai/sdk
7
+ ```
8
+
9
+ Works in Node.js and React Native (uses global `fetch` / `AbortSignal`; no Node‑only APIs).
10
+
11
+ ## Credentials
12
+
13
+ kvidai uses two credentials:
14
+
15
+ - **Strapi JWT** — identity: login + API‑key management (`console.kvid.ai`). Get it with `auth.login()`.
16
+ - **APIM api‑key** (32‑hex) — generation, media, preset, agent (`api.kvid.ai`). Get/create it with `auth.generateKey()` (or the `loginAndGetApiKey` shortcut).
17
+
18
+ ```ts
19
+ import { KvidaiClient } from '@kvidai/sdk';
20
+
21
+ const client = new KvidaiClient({
22
+ environment: 'prod', // 'prod' | 'staging' | 'dev' (default 'prod')
23
+ // jwt: '<strapi-jwt>', // for auth/key management
24
+ // apiKey: '<apim-32hex>', // for generation/media/preset/agent
25
+ });
26
+ ```
27
+
28
+ ## Quick start — generate a video
29
+
30
+ ```ts
31
+ const client = new KvidaiClient({ environment: 'prod' });
32
+
33
+ // 1. Log in and get an API key in one call
34
+ const { apiKey, user } = await client.auth.loginAndGetApiKey('you@example.com', 'password');
35
+ client.setCredentials({ apiKey });
36
+
37
+ // 2. Create a generation job
38
+ const { requestId, model } = await client.generation.textToVideo({
39
+ model: 'wan',
40
+ prompt: 'A cat walking on a sunny beach, cinematic',
41
+ });
42
+
43
+ // 3. Poll to completion and get the result URL
44
+ const result = await client.generation.waitForResult({ requestId, model });
45
+ console.log(result.url); // https://cdn.kvid.ai/...
46
+ ```
47
+
48
+ `waitForResult` encapsulates the real polling policy: 3 s interval, up to 200 attempts, tolerates up to 5 consecutive 5xx, and a 90 s result fetch for the fal→CDN upload. Pass `{ signal }` to cancel, or override `pollIntervalMs` / `maxAttempts`.
49
+
50
+ ## Modules
51
+
52
+ ### `client.auth` (Strapi JWT)
53
+
54
+ ```ts
55
+ const { jwt, user } = await client.auth.login({ identifier, password });
56
+ await client.auth.me();
57
+ await client.auth.products(); // APIM products
58
+ await client.auth.listKeys(); // your API keys (masked)
59
+ await client.auth.keyDetail(subscriptionId); // full key
60
+ await client.auth.generateKey({ email, productId });
61
+ await client.auth.regenerateKey({ subscriptionId, email });
62
+ await client.auth.revokeKey(subscriptionId);
63
+ await client.auth.creditSummary(email);
64
+ await client.auth.loginAndGetApiKey(identifier, password); // login + reuse/create key
65
+ ```
66
+
67
+ ### `client.generation` (APIM api‑key)
68
+
69
+ ```ts
70
+ client.generation.textToVideo({ model, prompt, ... });
71
+ client.generation.imageToVideo({ model, image_url, ... });
72
+ client.generation.referenceToVideo({ model, ... });
73
+ client.generation.videoToVideo({ model, input_video_url, ... });
74
+ client.generation.textToImage({ model, prompt, ... }); // e.g. model: 'nano-banana'
75
+ client.generation.imageToImage({ model, image_url, ... });
76
+ client.generation.talkV2V({ model, audio_url, input_video /* or image_url */ });
77
+ client.generation.voice({ model, text });
78
+
79
+ client.generation.status(requestId); // one status poll
80
+ client.generation.waitForResult({ requestId, model }); // poll → result
81
+ ```
82
+
83
+ Create methods return `{ requestId, model }`. `waitForResult` returns `{ url, requestId, model }`.
84
+
85
+ ### `client.media` (APIM api‑key)
86
+
87
+ ```ts
88
+ const cdnUrl = await client.media.upload(file); // presign → PUT → CDN url (browser File; <90 MB)
89
+ // or the low-level steps:
90
+ const presigned = await client.media.presign({ filename, mimeType, size });
91
+ // PUT your bytes to presigned.uploadUrl yourself (useful on React Native)
92
+ await client.media.completeUpload({ ... });
93
+ await client.media.list();
94
+ ```
95
+
96
+ On React Native (no `File`), use `presign()` + your own `fetch(uploadUrl, { method: 'PUT', body })` + `completeUpload()`.
97
+
98
+ ### `client.preset` (APIM api‑key)
99
+
100
+ ```ts
101
+ client.preset.list(); client.preset.get(id);
102
+ client.preset.create({ name, settings }); client.preset.update(id, { ... });
103
+ client.preset.delete(id); client.preset.duplicate(id);
104
+ ```
105
+
106
+ ### `client.agent` — conversational video agent (SSE, APIM api‑key)
107
+
108
+ ```ts
109
+ const { projectId } = await client.agent.createProject('My video');
110
+
111
+ await client.agent.generate(
112
+ { projectId, message: 'Make a 30s promo about coffee', chatHistory: [] },
113
+ (event) => console.log(event.type) // streamed events: tool_start, tool_end, done, error, ...
114
+ );
115
+
116
+ const project = await client.agent.getProjectResult(projectId); // { renderUrl, sceneCount, composition }
117
+ ```
118
+
119
+ ## Error handling
120
+
121
+ Every failure throws a typed `KvidaiError`:
122
+
123
+ ```ts
124
+ import { KvidaiError } from '@kvidai/sdk';
125
+
126
+ try {
127
+ await client.generation.waitForResult({ requestId, model });
128
+ } catch (err) {
129
+ if (err instanceof KvidaiError) {
130
+ console.error(err.code, err.status, err.message);
131
+ // codes: INSUFFICIENT_CREDITS | GENERATION_FAILED | CANCELLED | POLL_ERROR
132
+ // | FILE_TOO_LARGE | TIMEOUT | NO_PRODUCT | API_ERROR | ...
133
+ }
134
+ }
135
+ ```
136
+
137
+ ## Environments
138
+
139
+ | env | APIM (generation/media) | Strapi (auth) |
140
+ | --------- | -------------------------------------------- | ------------------------- |
141
+ | `prod` | `https://api.kvid.ai` `/ai/generation` | `https://console.kvid.ai` |
142
+ | `staging` | `https://api.kvid.ai` `/ai/generation` | staging Strapi |
143
+ | `dev` | `https://api.kvid.ai` `/ai/generation-clone` | `http://localhost:1337` |
144
+
145
+ ## Notes
146
+
147
+ - API keys are shown in full **only once** (on create/regenerate); store them securely. Regenerating a key invalidates the old one immediately.
148
+ - A Strapi JWT expiring is independent from an APIM key expiring.
149
+ - Generation is **polling‑based** (no webhooks): use `waitForResult`.
150
+
151
+ ## License
152
+
153
+ MIT