genmagic 0.0.0-stage → 0.1.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 O-mega Enterprise, Inc
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 CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # GenMagic for JavaScript and the command line
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
+ One API key and one pay-as-you-go balance for 460+ AI models: images, video with sound, speech, music and text. Veo, Kling, Seedance, Wan, Hailuo, Runway, Nano Banana, GPT Image, FLUX, Seedream and more, each with its price shown before you run it.
4
+
5
+ ```bash
6
+ npm install genmagic
7
+ export GENMAGIC_API_KEY=... # free key, one minute: https://genmagic.co/get-api-key?utm_source=npm&utm_medium=readme
8
+ ```
9
+
10
+ No dependencies. Node 18 or newer.
11
+
12
+ ## Images
13
+
14
+ ```js
15
+ import GenMagic from "genmagic";
16
+
17
+ const gm = new GenMagic();
18
+ const { url, costCents } = await gm.image("A red fox in snow, 35mm photo", {
19
+ model: "google/gemini-nano-banana-2.1", // leave out for GenMagic's default
20
+ size: "1792x1024",
21
+ });
22
+ ```
23
+
24
+ ## Video
25
+
26
+ `video` starts the job and waits for the clip. Use `startVideo` and `getVideo` to poll yourself.
27
+
28
+ ```js
29
+ const clip = await gm.video("Waves at sunset, slow drone shot", {
30
+ model: "alibaba/wan-3.0",
31
+ aspectRatio: "9:16",
32
+ duration: 5,
33
+ sound: true,
34
+ image: "https://example.com/opening-frame.png", // optional
35
+ });
36
+ console.log(clip.url);
37
+ ```
38
+
39
+ ## Speech, music, text
40
+
41
+ ```js
42
+ import { writeFile } from "node:fs/promises";
43
+
44
+ const voice = await gm.speech("Welcome to the show");
45
+ await writeFile("welcome.mp3", voice.bytes);
46
+
47
+ const track = await gm.music("Calm lo-fi beat, 80 bpm");
48
+
49
+ const answer = await gm.chat("Write a hook for a video about foxes", { model: "anthropic/claude-haiku-5.5" });
50
+ ```
51
+
52
+ ## Models and prices
53
+
54
+ ```js
55
+ const videoModels = await gm.models("video"); // needs no key
56
+ const balance = await gm.usage();
57
+ ```
58
+
59
+ A refusal throws a `GenMagicError` with `status`, `code` and GenMagic's own message (for example how to top up when the balance is too low).
60
+
61
+ ## Command line
62
+
63
+ ```bash
64
+ npx genmagic image "A red fox in snow" --out fox.png
65
+ npx genmagic video "Waves at sunset" --aspect 9:16 --duration 5 --out waves.mp4
66
+ npx genmagic speech "Welcome to the show" --out welcome.mp3
67
+ npx genmagic models video
68
+ npx genmagic balance
69
+ ```
70
+
71
+ ## Also from GenMagic
72
+
73
+ The same key works in [n8n](https://genmagic.co/n8n?utm_source=npm&utm_medium=readme), [Zapier](https://genmagic.co/zapier?utm_source=npm&utm_medium=readme), [Make](https://genmagic.co/make?utm_source=npm&utm_medium=readme), [ComfyUI](https://genmagic.co/comfyui?utm_source=npm&utm_medium=readme) and through [MCP](https://genmagic.co/mcp?utm_source=npm&utm_medium=readme) in Claude, ChatGPT and Cursor. The REST API is OpenAI-compatible: [reference](https://genmagic.co/developers?utm_source=npm&utm_medium=readme).
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ /** The GenMagic command line: images, video, speech and music from one key. */
3
+ import { writeFile } from "node:fs/promises";
4
+ import { GenMagic, GenMagicError, VERSION } from "../src/index.js";
5
+
6
+ const HELP = `genmagic ${VERSION}: 460+ AI models on one key and one pay-as-you-go balance.
7
+
8
+ Usage:
9
+ genmagic image "a red fox in snow" [--model id] [--size 1792x1024] [--from url] [--out fox.png]
10
+ genmagic video "waves at sunset" [--model id] [--aspect 9:16] [--duration 4] [--from url] [--out clip.mp4]
11
+ genmagic speech "Hello there" [--voice name] [--model id] --out hello.mp3
12
+ genmagic music "calm lo-fi beat" [--model id] --out track.mp3
13
+ genmagic models [image|video|text|audio]
14
+ genmagic balance
15
+
16
+ Set GENMAGIC_API_KEY first. A free key takes a minute:
17
+ https://genmagic.co/get-api-key?utm_source=npm&utm_medium=cli
18
+ `;
19
+
20
+ function parse(argv) {
21
+ const positional = [];
22
+ const flags = {};
23
+ for (let i = 0; i < argv.length; i++) {
24
+ if (argv[i].startsWith("--")) {
25
+ flags[argv[i].slice(2)] = argv[i + 1];
26
+ i++;
27
+ } else positional.push(argv[i]);
28
+ }
29
+ return { positional, flags };
30
+ }
31
+
32
+ async function saveFrom(url, out) {
33
+ const response = await fetch(url);
34
+ if (!response.ok) throw new Error(`Could not download ${url}: ${response.status}`);
35
+ await writeFile(out, new Uint8Array(await response.arrayBuffer()));
36
+ }
37
+
38
+ function report(result, out) {
39
+ const cost = result.costCents === undefined ? "" : ` ($${(result.costCents / 100).toFixed(3)})`;
40
+ console.log(`${out ?? result.url}${cost}`);
41
+ }
42
+
43
+ async function main() {
44
+ const [command, ...rest] = process.argv.slice(2);
45
+ const { positional, flags } = parse(rest);
46
+ const prompt = positional.join(" ");
47
+ const gm = new GenMagic({ client: `genmagic-cli/${VERSION}` });
48
+
49
+ switch (command) {
50
+ case "image": {
51
+ const result = await gm.image(prompt, { model: flags.model, size: flags.size, image: flags.from });
52
+ if (flags.out) await saveFrom(result.url, flags.out);
53
+ return report(result, flags.out);
54
+ }
55
+ case "video": {
56
+ const result = await gm.video(prompt, {
57
+ model: flags.model,
58
+ aspectRatio: flags.aspect,
59
+ duration: flags.duration ? Number(flags.duration) : undefined,
60
+ image: flags.from,
61
+ });
62
+ if (flags.out) await saveFrom(result.url, flags.out);
63
+ return report(result, flags.out);
64
+ }
65
+ case "speech":
66
+ case "music": {
67
+ if (!flags.out) throw new Error(`${command} needs --out <file>.`);
68
+ const result = command === "speech"
69
+ ? await gm.speech(prompt, { voice: flags.voice, model: flags.model })
70
+ : await gm.music(prompt, { model: flags.model });
71
+ await writeFile(flags.out, result.bytes);
72
+ return report(result, flags.out);
73
+ }
74
+ case "models": {
75
+ for (const model of await gm.models(positional[0])) {
76
+ const price = model.pricing?.est_per_generation_usd;
77
+ console.log(`${model.id}${price === undefined ? "" : ` about $${price}`}`);
78
+ }
79
+ return;
80
+ }
81
+ case "balance":
82
+ return console.log(JSON.stringify(await gm.usage(), null, 2));
83
+ default:
84
+ return console.log(HELP);
85
+ }
86
+ }
87
+
88
+ main().catch((error) => {
89
+ console.error(error instanceof GenMagicError || error instanceof Error ? error.message : String(error));
90
+ process.exit(1);
91
+ });
package/package.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "genmagic",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Official GenMagic client and CLI: one API key and one pay-as-you-go balance for 460+ AI models. Generate images, video with sound, speech, music and text with Veo, Kling, Seedance, Wan, Nano Banana, GPT Image, FLUX and more.",
5
+ "keywords": ["ai", "genmagic", "image-generation", "video-generation", "text-to-image", "text-to-video", "image-to-video", "text-to-speech", "tts", "music-generation", "ai-video", "ai-image", "veo", "kling", "seedance", "wan", "hailuo", "runway", "flux", "nano-banana", "gpt-image", "seedream", "openai-compatible", "generative-ai", "api-client", "cli"],
6
+ "homepage": "https://genmagic.co/developers?utm_source=npm&utm_medium=package",
7
+ "bugs": { "email": "hello@genmagic.co" },
8
+ "author": "GenMagic <hello@genmagic.co> (https://genmagic.co)",
9
+ "license": "MIT",
10
+ "type": "module",
11
+ "main": "./src/index.js",
12
+ "types": "./src/index.d.ts",
13
+ "exports": { ".": { "types": "./src/index.d.ts", "default": "./src/index.js" } },
14
+ "bin": { "genmagic": "bin/genmagic.js" },
15
+ "files": ["src", "bin", "README.md", "LICENSE"],
16
+ "engines": { "node": ">=18" },
17
+ "scripts": { "test": "node --test test/index.test.js" }
18
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ export declare const VERSION: string;
2
+
3
+ export declare class GenMagicError extends Error {
4
+ status: number;
5
+ code?: string;
6
+ constructor(message: string, status: number, code?: string);
7
+ }
8
+
9
+ export interface GenMagicOptions {
10
+ /** Defaults to the GENMAGIC_API_KEY environment variable. */
11
+ apiKey?: string;
12
+ baseURL?: string;
13
+ /** X-GenMagic-Client value, "name/version". */
14
+ client?: string;
15
+ }
16
+
17
+ export interface Cost {
18
+ costCents?: number;
19
+ creditsRemaining?: number;
20
+ }
21
+
22
+ export interface ImageOptions {
23
+ /** Any image model id from models("image"). */
24
+ model?: string;
25
+ size?: "1024x1024" | "1792x1024" | "1024x1792";
26
+ /** A reference image URL, to edit or build on. */
27
+ image?: string;
28
+ type?: "image" | "logo";
29
+ }
30
+
31
+ export interface VideoOptions {
32
+ /** Any video model id from models("video"). */
33
+ model?: string;
34
+ aspectRatio?: "16:9" | "9:16" | "1:1";
35
+ duration?: number;
36
+ resolution?: string;
37
+ sound?: boolean;
38
+ /** Opening image URL. */
39
+ image?: string;
40
+ lastFrame?: string;
41
+ references?: string[];
42
+ }
43
+
44
+ export interface FileResult extends Cost {
45
+ url?: string;
46
+ bytes: Uint8Array;
47
+ contentType?: string;
48
+ }
49
+
50
+ export declare class GenMagic {
51
+ constructor(options?: GenMagicOptions);
52
+ image(prompt: string, options?: ImageOptions): Promise<Cost & { url: string; raw: unknown }>;
53
+ startVideo(prompt: string, options?: VideoOptions): Promise<{ id: string; status: string; [key: string]: unknown }>;
54
+ getVideo(id: string): Promise<{ id: string; status: string; url?: string; cost_cents?: number; [key: string]: unknown }>;
55
+ video(prompt: string, options?: VideoOptions & { pollSeconds?: number; timeoutSeconds?: number }): Promise<{ id: string; url: string; costCents?: number; raw: unknown }>;
56
+ speech(text: string, options?: { voice?: string; model?: string }): Promise<FileResult>;
57
+ music(prompt: string, options?: { model?: string }): Promise<FileResult>;
58
+ chat(input: string | { role: string; content: unknown }[], options: { model: string }): Promise<Cost & { text: string; raw: unknown }>;
59
+ models(category?: "image" | "video" | "text" | "audio"): Promise<{ id: string; name?: string; pricing?: Record<string, unknown>; [key: string]: unknown }[]>;
60
+ usage(): Promise<Record<string, unknown>>;
61
+ }
62
+
63
+ export default GenMagic;
package/src/index.js ADDED
@@ -0,0 +1,162 @@
1
+ /**
2
+ * GenMagic's official client: one API key and one pay-as-you-go balance for 460+ AI models.
3
+ * No dependencies. Every call names this package in X-GenMagic-Client, so GenMagic can tell usage
4
+ * through it apart from a key owner's other API use.
5
+ * API reference: https://genmagic.co/openapi.json
6
+ */
7
+ export const VERSION = "0.1.0";
8
+ const DEFAULT_BASE_URL = "https://genmagic.co";
9
+ const KEY_HELP = "Create a free key at https://genmagic.co/get-api-key?utm_source=npm&utm_medium=package and set GENMAGIC_API_KEY.";
10
+
11
+ /** A refusal from GenMagic (a wrong key, too little balance, a model's refusal), in its own words. */
12
+ export class GenMagicError extends Error {
13
+ constructor(message, status, code) {
14
+ super(message);
15
+ this.name = "GenMagicError";
16
+ this.status = status;
17
+ this.code = code;
18
+ }
19
+ }
20
+
21
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
22
+
23
+ function compact(object) {
24
+ return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== undefined && value !== null));
25
+ }
26
+
27
+ function costOf(headers) {
28
+ const cost = headers.get("x-cost-cents");
29
+ const left = headers.get("x-credits-remaining");
30
+ return {
31
+ costCents: cost === null ? undefined : Number(cost),
32
+ creditsRemaining: left === null ? undefined : Number(left),
33
+ };
34
+ }
35
+
36
+ export class GenMagic {
37
+ /** @param {{ apiKey?: string, baseURL?: string, client?: string }} [options] */
38
+ constructor(options = {}) {
39
+ this.apiKey = options.apiKey ?? globalThis.process?.env?.GENMAGIC_API_KEY;
40
+ this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
41
+ this.client = options.client ?? `genmagic-sdk-js/${VERSION}`;
42
+ }
43
+
44
+ async #send(method, path, { body, auth = true, query } = {}) {
45
+ if (auth && !this.apiKey) throw new GenMagicError(`No API key. ${KEY_HELP}`, 401, "missing_api_key");
46
+ const url = new URL(this.baseURL + path);
47
+ for (const [name, value] of Object.entries(query ?? {})) {
48
+ if (value !== undefined && value !== null) url.searchParams.set(name, String(value));
49
+ }
50
+ const response = await fetch(url, {
51
+ method,
52
+ headers: {
53
+ ...(auth ? { Authorization: `Bearer ${this.apiKey}` } : {}),
54
+ ...(body ? { "Content-Type": "application/json" } : {}),
55
+ "X-GenMagic-Client": this.client,
56
+ },
57
+ body: body ? JSON.stringify(body) : undefined,
58
+ });
59
+ if (!response.ok) {
60
+ const text = await response.text();
61
+ let message = text;
62
+ let code;
63
+ try {
64
+ const parsed = JSON.parse(text);
65
+ message = parsed?.error?.message ?? text;
66
+ code = parsed?.error?.code;
67
+ } catch {
68
+ // Not JSON: keep the text as it came.
69
+ }
70
+ throw new GenMagicError(message || `GenMagic answered ${response.status}`, response.status, code);
71
+ }
72
+ return response;
73
+ }
74
+
75
+ /** Make an image. Returns its URL and what it cost. */
76
+ async image(prompt, options = {}) {
77
+ const response = await this.#send("POST", "/api/v1/images/generations", {
78
+ body: compact({ prompt, model: options.model, size: options.size, image: options.image, type: options.type }),
79
+ });
80
+ const data = await response.json();
81
+ return { url: data.data?.[0]?.url, ...costOf(response.headers), raw: data };
82
+ }
83
+
84
+ /** Start a video and return its job without waiting. */
85
+ async startVideo(prompt, options = {}) {
86
+ const response = await this.#send("POST", "/api/v1/videos", {
87
+ body: compact({
88
+ prompt,
89
+ model: options.model,
90
+ aspect_ratio: options.aspectRatio,
91
+ duration: options.duration,
92
+ resolution: options.resolution,
93
+ generate_audio: options.sound,
94
+ image: options.image,
95
+ last_frame: options.lastFrame,
96
+ references: options.references,
97
+ }),
98
+ });
99
+ return response.json();
100
+ }
101
+
102
+ /** Read a video job. */
103
+ async getVideo(id) {
104
+ const response = await this.#send("GET", `/api/v1/videos/${encodeURIComponent(id)}`);
105
+ return response.json();
106
+ }
107
+
108
+ /** Make a video and wait for the clip (polls every `pollSeconds`, gives up after `timeoutSeconds`). */
109
+ async video(prompt, options = {}) {
110
+ const { pollSeconds = 8, timeoutSeconds = 900, ...settings } = options;
111
+ const job = await this.startVideo(prompt, settings);
112
+ const deadline = Date.now() + timeoutSeconds * 1000;
113
+ while (Date.now() < deadline) {
114
+ await sleep(pollSeconds * 1000);
115
+ const video = await this.getVideo(job.id);
116
+ if (video.status === "completed") return { id: job.id, url: video.url, costCents: video.cost_cents, raw: video };
117
+ if (video.status === "failed") {
118
+ throw new GenMagicError(video.error?.message ?? video.error ?? "The video failed", 502, "video_failed");
119
+ }
120
+ }
121
+ throw new GenMagicError(`Video ${job.id} is still processing; read it later with getVideo.`, 504, "video_timeout");
122
+ }
123
+
124
+ async #file(path, body) {
125
+ const response = await this.#send("POST", path, { body });
126
+ const bytes = new Uint8Array(await response.arrayBuffer());
127
+ return { url: response.headers.get("x-media-url") ?? undefined, bytes, contentType: response.headers.get("content-type") ?? undefined, ...costOf(response.headers) };
128
+ }
129
+
130
+ /** Turn text into speech. Returns the audio bytes and its hosted URL. */
131
+ speech(text, options = {}) {
132
+ return this.#file("/api/v1/audio/speech", compact({ input: text, voice: options.voice, model: options.model }));
133
+ }
134
+
135
+ /** Make an original music track from a description. */
136
+ music(prompt, options = {}) {
137
+ return this.#file("/api/v1/audio/music", compact({ prompt, model: options.model }));
138
+ }
139
+
140
+ /** Chat with any text model: a string or OpenAI-style messages. Returns the answer's text. */
141
+ async chat(input, options = {}) {
142
+ const messages = typeof input === "string" ? [{ role: "user", content: input }] : input;
143
+ if (!options.model) throw new GenMagicError("chat needs a model: list them with models('text').", 400, "missing_model");
144
+ const response = await this.#send("POST", "/api/v1/chat/completions", { body: { model: options.model, messages } });
145
+ const data = await response.json();
146
+ return { text: data.choices?.[0]?.message?.content, ...costOf(response.headers), raw: data };
147
+ }
148
+
149
+ /** The model catalog with prices. Needs no key. Category: image, video, text or audio. */
150
+ async models(category) {
151
+ const response = await this.#send("GET", "/api/v1/models", { auth: false, query: { category } });
152
+ return (await response.json()).data;
153
+ }
154
+
155
+ /** The key's balance and spend. */
156
+ async usage() {
157
+ const response = await this.#send("GET", "/api/v1/usage");
158
+ return response.json();
159
+ }
160
+ }
161
+
162
+ export default GenMagic;