quantum-ai-sdk 0.2.0 → 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/dist/account.d.ts +22 -0
- package/dist/account.js +47 -0
- package/dist/agent.d.ts +12 -0
- package/dist/agent.js +114 -0
- package/dist/audio.d.ts +82 -0
- package/dist/audio.js +140 -0
- package/dist/auth.d.ts +7 -0
- package/dist/auth.js +8 -0
- package/dist/batch.d.ts +22 -0
- package/dist/batch.js +32 -0
- package/dist/chat.d.ts +27 -0
- package/dist/chat.js +122 -0
- package/dist/client.d.ts +264 -0
- package/dist/client.js +498 -0
- package/dist/compute.d.ts +37 -0
- package/dist/compute.js +56 -0
- package/dist/contact.d.ts +12 -0
- package/dist/contact.js +26 -0
- package/dist/credits.d.ts +27 -0
- package/dist/credits.js +40 -0
- package/dist/documents.d.ts +17 -0
- package/dist/documents.js +42 -0
- package/dist/embeddings.d.ts +7 -0
- package/dist/embeddings.js +14 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +70 -0
- package/dist/image.d.ts +12 -0
- package/dist/image.js +28 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +33 -0
- package/dist/jobs.d.ts +46 -0
- package/dist/jobs.js +128 -0
- package/dist/keys.d.ts +17 -0
- package/dist/keys.js +24 -0
- package/dist/models.d.ts +12 -0
- package/dist/models.js +16 -0
- package/dist/rag.d.ts +22 -0
- package/dist/rag.js +44 -0
- package/dist/realtime.d.ts +121 -0
- package/dist/realtime.js +259 -0
- package/dist/session.d.ts +7 -0
- package/dist/session.js +17 -0
- package/dist/types.d.ts +1018 -0
- package/dist/types.js +5 -0
- package/dist/video.d.ts +46 -0
- package/dist/video.js +74 -0
- package/dist/voices.d.ts +27 -0
- package/dist/voices.js +55 -0
- package/package.json +3 -3
package/dist/client.js
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
import { parseAPIError } from "./errors.js";
|
|
2
|
+
import { chat, chatStream } from "./chat.js";
|
|
3
|
+
import { chatSession } from "./session.js";
|
|
4
|
+
import { agentRun, missionRun } from "./agent.js";
|
|
5
|
+
import { generateImage, editImage } from "./image.js";
|
|
6
|
+
import { speak, transcribe, soundEffects, generateMusic, dialogue, speechToSpeech, isolateVoice, remixVoice, dub, align, voiceDesign, starfishTTS, } from "./audio.js";
|
|
7
|
+
import { generateVideo, videoStudio, videoTranslate, videoPhotoAvatar, videoDigitalTwin, videoAvatars, videoTemplates, videoHeygenVoices, } from "./video.js";
|
|
8
|
+
import { embed } from "./embeddings.js";
|
|
9
|
+
import { extractDocument, chunkDocument, processDocument } from "./documents.js";
|
|
10
|
+
import { ragSearch, ragCorpora, surrealRagSearch, surrealRagProviders } from "./rag.js";
|
|
11
|
+
import { listModels, getPricing } from "./models.js";
|
|
12
|
+
import { accountBalance, accountUsage, accountUsageSummary, accountPricing, } from "./account.js";
|
|
13
|
+
import { createJob, getJob, pollJob, listJobs, chatJob, streamJob, generate3D } from "./jobs.js";
|
|
14
|
+
import { createKey, listKeys, revokeKey } from "./keys.js";
|
|
15
|
+
import { computeTemplates, computeProvision, computeInstances, computeInstance, computeDelete, computeSSHKey, computeKeepalive, } from "./compute.js";
|
|
16
|
+
import { listVoices, cloneVoice, deleteVoice } from "./voices.js";
|
|
17
|
+
import { realtimeConnect, realtimeSession, realtimeEnd, realtimeRefresh } from "./realtime.js";
|
|
18
|
+
import { batchSubmit, batchSubmitJsonl, batchJobs, batchJob } from "./batch.js";
|
|
19
|
+
import { creditPacks, creditPurchase, creditBalance, creditTiers, devProgramApply } from "./credits.js";
|
|
20
|
+
import { authApple } from "./auth.js";
|
|
21
|
+
import { DEFAULT_BASE_URL } from "./types.js";
|
|
22
|
+
/**
|
|
23
|
+
* QuantumClient is the Quantum AI API client.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const client = new QuantumClient("qai_key_xxx");
|
|
28
|
+
*
|
|
29
|
+
* const resp = await client.chat({
|
|
30
|
+
* model: "claude-sonnet-4-6",
|
|
31
|
+
* messages: [{ role: "user", content: "Hello!" }],
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class QuantumClient {
|
|
36
|
+
apiKey;
|
|
37
|
+
baseUrl;
|
|
38
|
+
_fetch;
|
|
39
|
+
constructor(apiKey, options) {
|
|
40
|
+
this.apiKey = apiKey;
|
|
41
|
+
this.baseUrl = options?.baseUrl ?? DEFAULT_BASE_URL;
|
|
42
|
+
this._fetch = options?.fetch ?? globalThis.fetch.bind(globalThis);
|
|
43
|
+
}
|
|
44
|
+
/** @internal — used by realtime module to build WebSocket URL. */
|
|
45
|
+
get _baseUrl() {
|
|
46
|
+
return this.baseUrl;
|
|
47
|
+
}
|
|
48
|
+
/** @internal — used by realtime module for auth. */
|
|
49
|
+
get _apiKey() {
|
|
50
|
+
return this.apiKey;
|
|
51
|
+
}
|
|
52
|
+
// ── Chat ──────────────────────────────────────────────────────────
|
|
53
|
+
/** Send a non-streaming chat request. */
|
|
54
|
+
async chat(req) {
|
|
55
|
+
return chat(this, req);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Send a streaming chat request. Returns an AsyncIterableIterator of StreamEvents.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* for await (const event of client.chatStream({
|
|
63
|
+
* model: "gpt-5-mini",
|
|
64
|
+
* messages: [{ role: "user", content: "Write a haiku" }],
|
|
65
|
+
* })) {
|
|
66
|
+
* process.stdout.write(event.delta?.text ?? "");
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
async *chatStream(req, signal) {
|
|
71
|
+
yield* chatStream(this, req, signal);
|
|
72
|
+
}
|
|
73
|
+
// ── Session Chat ────────────────────────────────────────────────
|
|
74
|
+
/**
|
|
75
|
+
* Send a session-based chat request. The server manages conversation history.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* // Start a new session
|
|
80
|
+
* const resp = await client.chatSession({
|
|
81
|
+
* message: "Hello!",
|
|
82
|
+
* model: "claude-sonnet-4-6",
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Continue the conversation
|
|
86
|
+
* const resp2 = await client.chatSession({
|
|
87
|
+
* session_id: resp.session_id,
|
|
88
|
+
* message: "Tell me more",
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
async chatSession(req) {
|
|
93
|
+
return chatSession(this, req);
|
|
94
|
+
}
|
|
95
|
+
// ── Agent ───────────────────────────────────────────────────────
|
|
96
|
+
/**
|
|
97
|
+
* Run a server-side agent orchestration. Streams SSE events as the
|
|
98
|
+
* conductor delegates work to workers.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* for await (const event of client.agentRun({
|
|
103
|
+
* task: "Research the latest AI papers and summarize them",
|
|
104
|
+
* })) {
|
|
105
|
+
* console.log(event.type, event);
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async *agentRun(req, signal) {
|
|
110
|
+
yield* agentRun(this, req, signal);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Run a full mission orchestration. Streams SSE events as the conductor
|
|
114
|
+
* plans, delegates, and workers execute.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* for await (const event of client.missionRun({
|
|
119
|
+
* goal: "Build a REST API server in Go",
|
|
120
|
+
* })) {
|
|
121
|
+
* console.log(event.type, event);
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
async *missionRun(req, signal) {
|
|
126
|
+
yield* missionRun(this, req, signal);
|
|
127
|
+
}
|
|
128
|
+
// ── Image ─────────────────────────────────────────────────────────
|
|
129
|
+
/** Generate images from a text prompt. */
|
|
130
|
+
async generateImage(req) {
|
|
131
|
+
return generateImage(this, req);
|
|
132
|
+
}
|
|
133
|
+
/** Edit images using an AI model. */
|
|
134
|
+
async editImage(req) {
|
|
135
|
+
return editImage(this, req);
|
|
136
|
+
}
|
|
137
|
+
// ── Audio ─────────────────────────────────────────────────────────
|
|
138
|
+
/** Generate speech from text. */
|
|
139
|
+
async speak(req) {
|
|
140
|
+
return speak(this, req);
|
|
141
|
+
}
|
|
142
|
+
/** Convert speech to text. */
|
|
143
|
+
async transcribe(req) {
|
|
144
|
+
return transcribe(this, req);
|
|
145
|
+
}
|
|
146
|
+
/** Generate sound effects from a text prompt (ElevenLabs). */
|
|
147
|
+
async soundEffects(req) {
|
|
148
|
+
return soundEffects(this, req);
|
|
149
|
+
}
|
|
150
|
+
/** Generate music from a text prompt. */
|
|
151
|
+
async generateMusic(req) {
|
|
152
|
+
return generateMusic(this, req);
|
|
153
|
+
}
|
|
154
|
+
/** Generate multi-speaker dialogue audio (ElevenLabs). */
|
|
155
|
+
async dialogue(req) {
|
|
156
|
+
return dialogue(this, req);
|
|
157
|
+
}
|
|
158
|
+
/** Convert speech audio to a different voice (ElevenLabs). */
|
|
159
|
+
async speechToSpeech(req) {
|
|
160
|
+
return speechToSpeech(this, req);
|
|
161
|
+
}
|
|
162
|
+
/** Remove background noise and isolate speech (ElevenLabs). */
|
|
163
|
+
async isolateVoice(req) {
|
|
164
|
+
return isolateVoice(this, req);
|
|
165
|
+
}
|
|
166
|
+
/** Transform a voice by modifying attributes (ElevenLabs). */
|
|
167
|
+
async remixVoice(req) {
|
|
168
|
+
return remixVoice(this, req);
|
|
169
|
+
}
|
|
170
|
+
/** Dub audio/video into a target language (ElevenLabs). */
|
|
171
|
+
async dub(req) {
|
|
172
|
+
return dub(this, req);
|
|
173
|
+
}
|
|
174
|
+
/** Get word-level timestamps for audio+text alignment (ElevenLabs). */
|
|
175
|
+
async align(req) {
|
|
176
|
+
return align(this, req);
|
|
177
|
+
}
|
|
178
|
+
/** Generate voice previews from a text description (ElevenLabs). */
|
|
179
|
+
async voiceDesign(req) {
|
|
180
|
+
return voiceDesign(this, req);
|
|
181
|
+
}
|
|
182
|
+
/** Generate speech using HeyGen's Starfish TTS model. */
|
|
183
|
+
async starfishTTS(req) {
|
|
184
|
+
return starfishTTS(this, req);
|
|
185
|
+
}
|
|
186
|
+
// ── Video ─────────────────────────────────────────────────────────
|
|
187
|
+
/**
|
|
188
|
+
* Generate a video from a text prompt.
|
|
189
|
+
*
|
|
190
|
+
* Video generation is slow (30s-5min). For production use, consider
|
|
191
|
+
* submitting via the Jobs API instead.
|
|
192
|
+
*/
|
|
193
|
+
async generateVideo(req) {
|
|
194
|
+
return generateVideo(this, req);
|
|
195
|
+
}
|
|
196
|
+
/** Create a talking-head video via HeyGen Studio. Returns an async job. */
|
|
197
|
+
async videoStudio(req) {
|
|
198
|
+
return videoStudio(this, req);
|
|
199
|
+
}
|
|
200
|
+
/** Submit a video translation job via HeyGen. Returns an async job. */
|
|
201
|
+
async videoTranslate(req) {
|
|
202
|
+
return videoTranslate(this, req);
|
|
203
|
+
}
|
|
204
|
+
/** Create a photo avatar via HeyGen. Returns an async job. */
|
|
205
|
+
async videoPhotoAvatar(req) {
|
|
206
|
+
return videoPhotoAvatar(this, req);
|
|
207
|
+
}
|
|
208
|
+
/** Create a digital twin via HeyGen. Returns an async job. */
|
|
209
|
+
async videoDigitalTwin(req) {
|
|
210
|
+
return videoDigitalTwin(this, req);
|
|
211
|
+
}
|
|
212
|
+
/** List available HeyGen avatars. */
|
|
213
|
+
async videoAvatars() {
|
|
214
|
+
return videoAvatars(this);
|
|
215
|
+
}
|
|
216
|
+
/** List available HeyGen templates. */
|
|
217
|
+
async videoTemplates() {
|
|
218
|
+
return videoTemplates(this);
|
|
219
|
+
}
|
|
220
|
+
/** List available HeyGen voices. */
|
|
221
|
+
async videoHeygenVoices() {
|
|
222
|
+
return videoHeygenVoices(this);
|
|
223
|
+
}
|
|
224
|
+
// ── Embeddings ────────────────────────────────────────────────────
|
|
225
|
+
/** Generate text embeddings for the given inputs. */
|
|
226
|
+
async embed(req) {
|
|
227
|
+
return embed(this, req);
|
|
228
|
+
}
|
|
229
|
+
// ── Documents ─────────────────────────────────────────────────────
|
|
230
|
+
/** Extract text content from a document (PDF, image, etc.). */
|
|
231
|
+
async extractDocument(req) {
|
|
232
|
+
return extractDocument(this, req);
|
|
233
|
+
}
|
|
234
|
+
/** Chunk a document into smaller pieces for embedding or processing. */
|
|
235
|
+
async chunkDocument(req) {
|
|
236
|
+
return chunkDocument(this, req);
|
|
237
|
+
}
|
|
238
|
+
/** Process a document with extraction + optional instructions. */
|
|
239
|
+
async processDocument(req) {
|
|
240
|
+
return processDocument(this, req);
|
|
241
|
+
}
|
|
242
|
+
// ── RAG ───────────────────────────────────────────────────────────
|
|
243
|
+
/** Search Vertex AI RAG corpora for relevant documentation. */
|
|
244
|
+
async ragSearch(req) {
|
|
245
|
+
return ragSearch(this, req);
|
|
246
|
+
}
|
|
247
|
+
/** List available Vertex AI RAG corpora. */
|
|
248
|
+
async ragCorpora() {
|
|
249
|
+
return ragCorpora(this);
|
|
250
|
+
}
|
|
251
|
+
/** Search provider API documentation via SurrealDB vector search. */
|
|
252
|
+
async surrealRagSearch(req) {
|
|
253
|
+
return surrealRagSearch(this, req);
|
|
254
|
+
}
|
|
255
|
+
/** List available documentation providers in SurrealDB RAG. */
|
|
256
|
+
async surrealRagProviders() {
|
|
257
|
+
return surrealRagProviders(this);
|
|
258
|
+
}
|
|
259
|
+
// ── Models ────────────────────────────────────────────────────────
|
|
260
|
+
/** List all available models with provider and pricing information. */
|
|
261
|
+
async listModels() {
|
|
262
|
+
return listModels(this);
|
|
263
|
+
}
|
|
264
|
+
/** Get the complete pricing table for all models. */
|
|
265
|
+
async getPricing() {
|
|
266
|
+
return getPricing(this);
|
|
267
|
+
}
|
|
268
|
+
// ── Account ───────────────────────────────────────────────────────
|
|
269
|
+
/** Get the account credit balance. */
|
|
270
|
+
async accountBalance() {
|
|
271
|
+
return accountBalance(this);
|
|
272
|
+
}
|
|
273
|
+
/** Get paginated usage history. */
|
|
274
|
+
async accountUsage(query) {
|
|
275
|
+
return accountUsage(this, query);
|
|
276
|
+
}
|
|
277
|
+
/** Get monthly usage summary. */
|
|
278
|
+
async accountUsageSummary(months) {
|
|
279
|
+
return accountUsageSummary(this, months);
|
|
280
|
+
}
|
|
281
|
+
/** Get the full pricing table (model ID -> pricing entry map). */
|
|
282
|
+
async accountPricing() {
|
|
283
|
+
return accountPricing(this);
|
|
284
|
+
}
|
|
285
|
+
// ── Jobs ──────────────────────────────────────────────────────────
|
|
286
|
+
/** Create an async job. Returns the job ID for polling. */
|
|
287
|
+
async createJob(req) {
|
|
288
|
+
return createJob(this, req);
|
|
289
|
+
}
|
|
290
|
+
/** Check the status of an async job. */
|
|
291
|
+
async getJob(jobId) {
|
|
292
|
+
return getJob(this, jobId);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Poll a job until completion or timeout.
|
|
296
|
+
*
|
|
297
|
+
* @param jobId - Job ID to poll.
|
|
298
|
+
* @param intervalMs - Polling interval in milliseconds (default 2000).
|
|
299
|
+
* @param maxAttempts - Maximum poll attempts before timeout (default 150).
|
|
300
|
+
*/
|
|
301
|
+
async pollJob(jobId, intervalMs, maxAttempts) {
|
|
302
|
+
return pollJob(this, jobId, intervalMs, maxAttempts);
|
|
303
|
+
}
|
|
304
|
+
/** List all jobs for the authenticated user. */
|
|
305
|
+
async listJobs() {
|
|
306
|
+
return listJobs(this);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Submit a chat completion as an async job.
|
|
310
|
+
* Use for long-running models (e.g. Opus) where sync chat may time out.
|
|
311
|
+
* Params are the same shape as ChatRequest (model, messages, tools, etc.)
|
|
312
|
+
*/
|
|
313
|
+
async chatJob(req) {
|
|
314
|
+
return chatJob(this, req);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Stream job progress via SSE. Yields events as the job runs.
|
|
318
|
+
* Events: progress (status update), complete (with result), error.
|
|
319
|
+
*/
|
|
320
|
+
streamJob(jobId, signal) {
|
|
321
|
+
return streamJob(this, jobId, signal);
|
|
322
|
+
}
|
|
323
|
+
/** Generate a 3D model via the async jobs system. */
|
|
324
|
+
async generate3D(model, prompt, imageUrl) {
|
|
325
|
+
return generate3D(this, model, prompt, imageUrl);
|
|
326
|
+
}
|
|
327
|
+
// ── API Keys ──────────────────────────────────────────────────────
|
|
328
|
+
/** Create a scoped API key. */
|
|
329
|
+
async createKey(req) {
|
|
330
|
+
return createKey(this, req);
|
|
331
|
+
}
|
|
332
|
+
/** List all API keys for the authenticated user. */
|
|
333
|
+
async listKeys() {
|
|
334
|
+
return listKeys(this);
|
|
335
|
+
}
|
|
336
|
+
/** Revoke an API key. */
|
|
337
|
+
async revokeKey(id) {
|
|
338
|
+
return revokeKey(this, id);
|
|
339
|
+
}
|
|
340
|
+
// ── Compute ───────────────────────────────────────────────────────
|
|
341
|
+
/** Get available compute templates with pricing. */
|
|
342
|
+
async computeTemplates() {
|
|
343
|
+
return computeTemplates(this);
|
|
344
|
+
}
|
|
345
|
+
/** Provision a new GPU compute instance. */
|
|
346
|
+
async computeProvision(req) {
|
|
347
|
+
return computeProvision(this, req);
|
|
348
|
+
}
|
|
349
|
+
/** List all compute instances for the authenticated user. */
|
|
350
|
+
async computeInstances() {
|
|
351
|
+
return computeInstances(this);
|
|
352
|
+
}
|
|
353
|
+
/** Get full status of a single compute instance. */
|
|
354
|
+
async computeInstance(id) {
|
|
355
|
+
return computeInstance(this, id);
|
|
356
|
+
}
|
|
357
|
+
/** Tear down a compute instance and finalize billing. */
|
|
358
|
+
async computeDelete(id) {
|
|
359
|
+
return computeDelete(this, id);
|
|
360
|
+
}
|
|
361
|
+
/** Inject an SSH public key into a running instance. */
|
|
362
|
+
async computeSSHKey(id, req) {
|
|
363
|
+
return computeSSHKey(this, id, req);
|
|
364
|
+
}
|
|
365
|
+
/** Reset the inactivity timer on a compute instance. */
|
|
366
|
+
async computeKeepalive(id) {
|
|
367
|
+
return computeKeepalive(this, id);
|
|
368
|
+
}
|
|
369
|
+
// ── Voice Management ──────────────────────────────────────────────
|
|
370
|
+
/** List all available voices (ElevenLabs). */
|
|
371
|
+
async listVoices() {
|
|
372
|
+
return listVoices(this);
|
|
373
|
+
}
|
|
374
|
+
/** Create an instant voice clone from audio samples (ElevenLabs). */
|
|
375
|
+
async cloneVoice(req) {
|
|
376
|
+
return cloneVoice(this, req);
|
|
377
|
+
}
|
|
378
|
+
/** Delete a cloned voice (ElevenLabs). */
|
|
379
|
+
async deleteVoice(id) {
|
|
380
|
+
return deleteVoice(this, id);
|
|
381
|
+
}
|
|
382
|
+
// ── Realtime Voice ────────────────────────────────────────────────
|
|
383
|
+
/**
|
|
384
|
+
* Open a realtime voice session via WebSocket (proxy path).
|
|
385
|
+
* Returns [sender, receiver] for bidirectional audio communication.
|
|
386
|
+
*/
|
|
387
|
+
async realtimeConnect(config) {
|
|
388
|
+
return realtimeConnect(this, config);
|
|
389
|
+
}
|
|
390
|
+
/** Request an ephemeral token for direct xAI voice connection (lower latency). */
|
|
391
|
+
async realtimeSession() {
|
|
392
|
+
return realtimeSession(this);
|
|
393
|
+
}
|
|
394
|
+
/** End a realtime session and finalize billing. */
|
|
395
|
+
async realtimeEnd(sessionId, durationSeconds) {
|
|
396
|
+
return realtimeEnd(this, sessionId, durationSeconds);
|
|
397
|
+
}
|
|
398
|
+
/** Refresh an ephemeral token for long sessions (>4 min). */
|
|
399
|
+
async realtimeRefresh(sessionId) {
|
|
400
|
+
return realtimeRefresh(this, sessionId);
|
|
401
|
+
}
|
|
402
|
+
// ── Batch Processing ──────────────────────────────────────────────
|
|
403
|
+
/** Submit a batch of jobs for processing. */
|
|
404
|
+
async batchSubmit(req) {
|
|
405
|
+
return batchSubmit(this, req);
|
|
406
|
+
}
|
|
407
|
+
/** Submit a batch of jobs using JSONL format. */
|
|
408
|
+
async batchSubmitJsonl(jsonl) {
|
|
409
|
+
return batchSubmitJsonl(this, jsonl);
|
|
410
|
+
}
|
|
411
|
+
/** List all batch jobs for the account. */
|
|
412
|
+
async batchJobs() {
|
|
413
|
+
return batchJobs(this);
|
|
414
|
+
}
|
|
415
|
+
/** Get the status and result of a single batch job. */
|
|
416
|
+
async batchJob(id) {
|
|
417
|
+
return batchJob(this, id);
|
|
418
|
+
}
|
|
419
|
+
// ── Credits ───────────────────────────────────────────────────────
|
|
420
|
+
/** List available credit packs (no auth required). */
|
|
421
|
+
async creditPacks() {
|
|
422
|
+
return creditPacks(this);
|
|
423
|
+
}
|
|
424
|
+
/** Purchase a credit pack. Returns a checkout URL for payment. */
|
|
425
|
+
async creditPurchase(req) {
|
|
426
|
+
return creditPurchase(this, req);
|
|
427
|
+
}
|
|
428
|
+
/** Get the current credit balance. */
|
|
429
|
+
async creditBalance() {
|
|
430
|
+
return creditBalance(this);
|
|
431
|
+
}
|
|
432
|
+
/** List available credit tiers (no auth required). */
|
|
433
|
+
async creditTiers() {
|
|
434
|
+
return creditTiers(this);
|
|
435
|
+
}
|
|
436
|
+
/** Apply for the developer program. */
|
|
437
|
+
async devProgramApply(req) {
|
|
438
|
+
return devProgramApply(this, req);
|
|
439
|
+
}
|
|
440
|
+
// ── Auth ──────────────────────────────────────────────────────────
|
|
441
|
+
/** Authenticate with Apple Sign-In. */
|
|
442
|
+
async authApple(req) {
|
|
443
|
+
return authApple(this, req);
|
|
444
|
+
}
|
|
445
|
+
// ── Internal HTTP helpers ─────────────────────────────────────────
|
|
446
|
+
/**
|
|
447
|
+
* Send a JSON request and decode the JSON response.
|
|
448
|
+
* @internal
|
|
449
|
+
*/
|
|
450
|
+
async _doJSON(method, path, body) {
|
|
451
|
+
const headers = {
|
|
452
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
453
|
+
};
|
|
454
|
+
const init = { method, headers };
|
|
455
|
+
if (body !== undefined) {
|
|
456
|
+
headers["Content-Type"] = "application/json";
|
|
457
|
+
init.body = JSON.stringify(body);
|
|
458
|
+
}
|
|
459
|
+
const response = await this._fetch(`${this.baseUrl}${path}`, init);
|
|
460
|
+
const meta = {
|
|
461
|
+
requestId: response.headers.get("X-QAI-Request-Id") ?? "",
|
|
462
|
+
model: response.headers.get("X-QAI-Model") ?? "",
|
|
463
|
+
costTicks: 0,
|
|
464
|
+
};
|
|
465
|
+
const costHeader = response.headers.get("X-QAI-Cost-Ticks");
|
|
466
|
+
if (costHeader) {
|
|
467
|
+
meta.costTicks = parseInt(costHeader, 10) || 0;
|
|
468
|
+
}
|
|
469
|
+
if (!response.ok) {
|
|
470
|
+
throw await parseAPIError(response, meta.requestId);
|
|
471
|
+
}
|
|
472
|
+
const data = (await response.json());
|
|
473
|
+
return { data, meta };
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Send a JSON request expecting an SSE (text/event-stream) response.
|
|
477
|
+
* Returns the raw Response for the caller to read SSE events from.
|
|
478
|
+
* @internal
|
|
479
|
+
*/
|
|
480
|
+
async _doStreamRaw(path, body, signal) {
|
|
481
|
+
const headers = {
|
|
482
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
483
|
+
"Content-Type": "application/json",
|
|
484
|
+
Accept: "text/event-stream",
|
|
485
|
+
};
|
|
486
|
+
const response = await this._fetch(`${this.baseUrl}${path}`, {
|
|
487
|
+
method: "POST",
|
|
488
|
+
headers,
|
|
489
|
+
body: JSON.stringify(body),
|
|
490
|
+
signal,
|
|
491
|
+
});
|
|
492
|
+
if (!response.ok) {
|
|
493
|
+
const requestId = response.headers.get("X-QAI-Request-Id") ?? "";
|
|
494
|
+
throw await parseAPIError(response, requestId);
|
|
495
|
+
}
|
|
496
|
+
return response;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { DeleteResponse, InstanceResponse, InstancesResponse, ProvisionRequest, ProvisionResponse, SSHKeyRequest, StatusResponse, TemplatesResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Get available compute templates with pricing.
|
|
5
|
+
* @internal — called by QuantumClient.computeTemplates()
|
|
6
|
+
*/
|
|
7
|
+
export declare function computeTemplates(client: QuantumClient): Promise<TemplatesResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Provision a new GPU compute instance.
|
|
10
|
+
* @internal — called by QuantumClient.computeProvision()
|
|
11
|
+
*/
|
|
12
|
+
export declare function computeProvision(client: QuantumClient, req: ProvisionRequest): Promise<ProvisionResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* List all compute instances for the authenticated user.
|
|
15
|
+
* @internal — called by QuantumClient.computeInstances()
|
|
16
|
+
*/
|
|
17
|
+
export declare function computeInstances(client: QuantumClient): Promise<InstancesResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Get full status of a single compute instance.
|
|
20
|
+
* @internal — called by QuantumClient.computeInstance()
|
|
21
|
+
*/
|
|
22
|
+
export declare function computeInstance(client: QuantumClient, id: string): Promise<InstanceResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Tear down a compute instance and finalize billing.
|
|
25
|
+
* @internal — called by QuantumClient.computeDelete()
|
|
26
|
+
*/
|
|
27
|
+
export declare function computeDelete(client: QuantumClient, id: string): Promise<DeleteResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Inject an SSH public key into a running instance.
|
|
30
|
+
* @internal — called by QuantumClient.computeSSHKey()
|
|
31
|
+
*/
|
|
32
|
+
export declare function computeSSHKey(client: QuantumClient, id: string, req: SSHKeyRequest): Promise<StatusResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Reset the inactivity timer on a compute instance.
|
|
35
|
+
* @internal — called by QuantumClient.computeKeepalive()
|
|
36
|
+
*/
|
|
37
|
+
export declare function computeKeepalive(client: QuantumClient, id: string): Promise<StatusResponse>;
|
package/dist/compute.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get available compute templates with pricing.
|
|
3
|
+
* @internal — called by QuantumClient.computeTemplates()
|
|
4
|
+
*/
|
|
5
|
+
export async function computeTemplates(client) {
|
|
6
|
+
const { data } = await client._doJSON("GET", "/qai/v1/compute/templates", undefined);
|
|
7
|
+
return data;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Provision a new GPU compute instance.
|
|
11
|
+
* @internal — called by QuantumClient.computeProvision()
|
|
12
|
+
*/
|
|
13
|
+
export async function computeProvision(client, req) {
|
|
14
|
+
const { data } = await client._doJSON("POST", "/qai/v1/compute/provision", req);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* List all compute instances for the authenticated user.
|
|
19
|
+
* @internal — called by QuantumClient.computeInstances()
|
|
20
|
+
*/
|
|
21
|
+
export async function computeInstances(client) {
|
|
22
|
+
const { data } = await client._doJSON("GET", "/qai/v1/compute/instances", undefined);
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get full status of a single compute instance.
|
|
27
|
+
* @internal — called by QuantumClient.computeInstance()
|
|
28
|
+
*/
|
|
29
|
+
export async function computeInstance(client, id) {
|
|
30
|
+
const { data } = await client._doJSON("GET", `/qai/v1/compute/instance/${id}`, undefined);
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Tear down a compute instance and finalize billing.
|
|
35
|
+
* @internal — called by QuantumClient.computeDelete()
|
|
36
|
+
*/
|
|
37
|
+
export async function computeDelete(client, id) {
|
|
38
|
+
const { data } = await client._doJSON("DELETE", `/qai/v1/compute/instance/${id}`, undefined);
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Inject an SSH public key into a running instance.
|
|
43
|
+
* @internal — called by QuantumClient.computeSSHKey()
|
|
44
|
+
*/
|
|
45
|
+
export async function computeSSHKey(client, id, req) {
|
|
46
|
+
const { data } = await client._doJSON("POST", `/qai/v1/compute/instance/${id}/ssh-key`, req);
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reset the inactivity timer on a compute instance.
|
|
51
|
+
* @internal — called by QuantumClient.computeKeepalive()
|
|
52
|
+
*/
|
|
53
|
+
export async function computeKeepalive(client, id) {
|
|
54
|
+
const { data } = await client._doJSON("POST", `/qai/v1/compute/instance/${id}/keepalive`, undefined);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ContactRequest, StatusResponse } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Send a contact form message. This is a public endpoint (no auth required).
|
|
4
|
+
*
|
|
5
|
+
* Unlike other SDK methods, this is a standalone function rather than a
|
|
6
|
+
* QuantumClient method because it does not require an API key.
|
|
7
|
+
*
|
|
8
|
+
* @param req - Contact form data.
|
|
9
|
+
* @param baseUrl - API base URL (defaults to production).
|
|
10
|
+
* @param fetchFn - Custom fetch implementation.
|
|
11
|
+
*/
|
|
12
|
+
export declare function contact(req: ContactRequest, baseUrl?: string, fetchFn?: typeof globalThis.fetch): Promise<StatusResponse>;
|
package/dist/contact.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DEFAULT_BASE_URL } from "./types.js";
|
|
2
|
+
import { parseAPIError } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Send a contact form message. This is a public endpoint (no auth required).
|
|
5
|
+
*
|
|
6
|
+
* Unlike other SDK methods, this is a standalone function rather than a
|
|
7
|
+
* QuantumClient method because it does not require an API key.
|
|
8
|
+
*
|
|
9
|
+
* @param req - Contact form data.
|
|
10
|
+
* @param baseUrl - API base URL (defaults to production).
|
|
11
|
+
* @param fetchFn - Custom fetch implementation.
|
|
12
|
+
*/
|
|
13
|
+
export async function contact(req, baseUrl, fetchFn) {
|
|
14
|
+
const url = `${baseUrl ?? DEFAULT_BASE_URL}/qai/v1/contact`;
|
|
15
|
+
const doFetch = fetchFn ?? globalThis.fetch.bind(globalThis);
|
|
16
|
+
const response = await doFetch(url, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: { "Content-Type": "application/json" },
|
|
19
|
+
body: JSON.stringify(req),
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const requestId = response.headers.get("X-QAI-Request-Id") ?? "";
|
|
23
|
+
throw await parseAPIError(response, requestId);
|
|
24
|
+
}
|
|
25
|
+
return (await response.json());
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { CreditPacksResponse, CreditPurchaseRequest, CreditPurchaseResponse, CreditBalanceResponse, CreditTiersResponse, DevProgramApplyRequest, DevProgramApplyResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* List available credit packs. No authentication required.
|
|
5
|
+
* @internal — called by QuantumClient.creditPacks()
|
|
6
|
+
*/
|
|
7
|
+
export declare function creditPacks(client: QuantumClient): Promise<CreditPacksResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Purchase a credit pack. Returns a checkout URL for payment.
|
|
10
|
+
* @internal — called by QuantumClient.creditPurchase()
|
|
11
|
+
*/
|
|
12
|
+
export declare function creditPurchase(client: QuantumClient, req: CreditPurchaseRequest): Promise<CreditPurchaseResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Get the current credit balance.
|
|
15
|
+
* @internal — called by QuantumClient.creditBalance()
|
|
16
|
+
*/
|
|
17
|
+
export declare function creditBalance(client: QuantumClient): Promise<CreditBalanceResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* List available credit tiers. No authentication required.
|
|
20
|
+
* @internal — called by QuantumClient.creditTiers()
|
|
21
|
+
*/
|
|
22
|
+
export declare function creditTiers(client: QuantumClient): Promise<CreditTiersResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Apply for the developer program.
|
|
25
|
+
* @internal — called by QuantumClient.devProgramApply()
|
|
26
|
+
*/
|
|
27
|
+
export declare function devProgramApply(client: QuantumClient, req: DevProgramApplyRequest): Promise<DevProgramApplyResponse>;
|