pixelapi 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 PixelAPI
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,176 @@
1
+ # PixelAPI JavaScript SDK
2
+
3
+ Official JavaScript/TypeScript client for [PixelAPI](https://pixelapi.dev) — the cheapest AI image generation, background removal, upscaling, and audio generation API.
4
+
5
+ **10 AI models, one API key, from $0.002/image.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/pixelapi)](https://www.npmjs.com/package/pixelapi)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue)](https://www.typescriptlang.org/)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install pixelapi
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```typescript
20
+ import { PixelAPI } from "pixelapi";
21
+
22
+ const client = new PixelAPI("pk_live_your_key");
23
+
24
+ // Generate an image ($0.003)
25
+ const result = await client.image.generate({ prompt: "a cat astronaut, digital art" });
26
+ const completed = await client.generation.wait(result.id);
27
+ console.log(completed.outputUrl);
28
+ ```
29
+
30
+ ## Features
31
+
32
+ ### 🖼️ Image Generation
33
+
34
+ ```typescript
35
+ // FLUX Schnell — fast, photorealistic (~3s)
36
+ const result = await client.image.generate({
37
+ prompt: "product on marble table, studio lighting",
38
+ model: "flux-schnell",
39
+ });
40
+
41
+ // SDXL — versatile, great for illustrations
42
+ const result = await client.image.generate({
43
+ prompt: "watercolor painting of mountains",
44
+ model: "sdxl",
45
+ });
46
+
47
+ const completed = await client.generation.wait(result.id);
48
+ console.log(completed.outputUrl);
49
+ ```
50
+
51
+ ### ✂️ Background Removal — $0.002/image
52
+
53
+ ```typescript
54
+ const result = await client.image.removeBackground({
55
+ imageUrl: "https://example.com/product.jpg",
56
+ });
57
+ const completed = await client.generation.wait(result.id);
58
+ console.log(completed.outputUrl); // Transparent PNG
59
+ ```
60
+
61
+ ### 🎨 Background Replacement — $0.005/image
62
+
63
+ ```typescript
64
+ const result = await client.image.replaceBackground({
65
+ imageUrl: "https://example.com/product.jpg",
66
+ prompt: "product on marble countertop, soft studio lighting",
67
+ });
68
+ ```
69
+
70
+ ### 🔍 4x Upscaling — $0.02/image
71
+
72
+ ```typescript
73
+ const result = await client.image.upscale({
74
+ imageUrl: "https://example.com/low-res.jpg",
75
+ });
76
+ ```
77
+
78
+ ### 👤 Face Restoration — $0.003/image
79
+
80
+ ```typescript
81
+ const result = await client.image.restoreFace({
82
+ imageUrl: "https://example.com/blurry-portrait.jpg",
83
+ });
84
+ ```
85
+
86
+ ### 🧹 Object Removal — $0.005/image
87
+
88
+ ```typescript
89
+ const result = await client.image.removeObject({
90
+ imageUrl: "https://example.com/photo.jpg",
91
+ maskUrl: "https://example.com/mask.png",
92
+ });
93
+ ```
94
+
95
+ ### 🎵 AI Music Generation — $0.005/track
96
+
97
+ ```typescript
98
+ const result = await client.audio.generate({
99
+ prompt: "upbeat electronic music for a product video",
100
+ duration: 15,
101
+ });
102
+ const completed = await client.generation.wait(result.id);
103
+ console.log(completed.outputUrl); // Audio URL
104
+ ```
105
+
106
+ ### 🔄 Polling for Results
107
+
108
+ ```typescript
109
+ // One-shot check
110
+ const status = await client.generation.get("gen_abc123");
111
+ console.log(status.status); // "pending" | "processing" | "completed" | "failed"
112
+
113
+ // Wait until done (timeout in ms)
114
+ const completed = await client.generation.wait("gen_abc123", {
115
+ timeout: 120000,
116
+ pollInterval: 2000,
117
+ });
118
+ ```
119
+
120
+ ## Error Handling
121
+
122
+ ```typescript
123
+ import { PixelAPI, AuthenticationError, RateLimitError, InsufficientCreditsError } from "pixelapi";
124
+
125
+ const client = new PixelAPI("pk_live_your_key");
126
+
127
+ try {
128
+ const result = await client.image.generate({ prompt: "hello world" });
129
+ } catch (error) {
130
+ if (error instanceof AuthenticationError) {
131
+ console.error("Invalid API key");
132
+ } else if (error instanceof RateLimitError) {
133
+ console.error(`Rate limited. Retry after ${error.retryAfter}s`);
134
+ } else if (error instanceof InsufficientCreditsError) {
135
+ console.error("Not enough credits — top up at pixelapi.dev/app");
136
+ }
137
+ }
138
+ ```
139
+
140
+ ## TypeScript
141
+
142
+ Full TypeScript support with exported types:
143
+
144
+ ```typescript
145
+ import type { Generation, GenerateImageOptions, WaitOptions } from "pixelapi";
146
+ ```
147
+
148
+ ## API Reference
149
+
150
+ | Method | Endpoint | Credits |
151
+ |--------|----------|---------|
152
+ | `client.image.generate()` | POST /v1/image/generate | 3 |
153
+ | `client.image.removeBackground()` | POST /v1/image/remove-background | 2 |
154
+ | `client.image.upscale()` | POST /v1/image/upscale | 20 |
155
+ | `client.image.restoreFace()` | POST /v1/image/restore-face | 3 |
156
+ | `client.image.removeObject()` | POST /v1/image/remove-object | 5 |
157
+ | `client.image.replaceBackground()` | POST /v1/image/replace-background | 5 |
158
+ | `client.audio.generate()` | POST /v1/audio/generate | 5 |
159
+ | `client.generation.get()` | GET /v1/image/{id} | 0 |
160
+ | `client.generation.wait()` | Polls GET /v1/image/{id} | 0 |
161
+
162
+ ## Requirements
163
+
164
+ - Node.js 18+ (uses native `fetch`)
165
+ - No external dependencies
166
+
167
+ ## Links
168
+
169
+ - **Documentation:** [pixelapi.dev/docs](https://pixelapi.dev/docs)
170
+ - **Dashboard:** [pixelapi.dev/app](https://pixelapi.dev/app)
171
+ - **API Reference:** [api.pixelapi.dev/docs](https://api.pixelapi.dev/docs)
172
+ - **Support:** support@pixelapi.dev
173
+
174
+ ## License
175
+
176
+ MIT
@@ -0,0 +1,34 @@
1
+ import type { Generation, GenerateImageOptions, RemoveBackgroundOptions, UpscaleOptions, RestoreFaceOptions, RemoveObjectOptions, ReplaceBackgroundOptions, GenerateAudioOptions, WaitOptions, PixelAPIOptions } from "./types";
2
+ declare class ImageResource {
3
+ private request;
4
+ constructor(request: (method: string, path: string, body?: unknown) => Promise<Record<string, unknown>>);
5
+ generate(options: GenerateImageOptions): Promise<Generation>;
6
+ removeBackground(options: RemoveBackgroundOptions): Promise<Generation>;
7
+ upscale(options: UpscaleOptions): Promise<Generation>;
8
+ restoreFace(options: RestoreFaceOptions): Promise<Generation>;
9
+ removeObject(options: RemoveObjectOptions): Promise<Generation>;
10
+ replaceBackground(options: ReplaceBackgroundOptions): Promise<Generation>;
11
+ }
12
+ declare class AudioResource {
13
+ private request;
14
+ constructor(request: (method: string, path: string, body?: unknown) => Promise<Record<string, unknown>>);
15
+ generate(options: GenerateAudioOptions): Promise<Generation>;
16
+ }
17
+ declare class GenerationResource {
18
+ private request;
19
+ constructor(request: (method: string, path: string, body?: unknown) => Promise<Record<string, unknown>>);
20
+ get(generationId: string): Promise<Generation>;
21
+ wait(generationId: string, options?: WaitOptions): Promise<Generation>;
22
+ }
23
+ export declare class PixelAPI {
24
+ readonly image: ImageResource;
25
+ readonly audio: AudioResource;
26
+ readonly generation: GenerationResource;
27
+ private baseUrl;
28
+ private apiKey;
29
+ private timeout;
30
+ constructor(apiKey: string, options?: PixelAPIOptions);
31
+ private request;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,EACX,eAAe,EAChB,MAAM,SAAS,CAAC;AAwDjB,cAAM,aAAa;IACL,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzG,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;IAM5D,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,UAAU,CAAC;IAKvE,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAKrD,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;IAK7D,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IAK/D,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;CAIhF;AAED,cAAM,aAAa;IACL,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzG,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;CAKnE;AAED,cAAM,kBAAkB;IACV,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzG,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI9C,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;CAkBjF;AAED,qBAAa,QAAQ;IACnB,SAAgB,KAAK,EAAE,aAAa,CAAC;IACrC,SAAgB,KAAK,EAAE,aAAa,CAAC;IACrC,SAAgB,UAAU,EAAE,kBAAkB,CAAC;IAE/C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;YAW3C,OAAO;CAoBtB"}
package/dist/client.js ADDED
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PixelAPI = void 0;
4
+ const errors_1 = require("./errors");
5
+ const VERSION = "0.1.0";
6
+ const DEFAULT_BASE_URL = "https://api.pixelapi.dev";
7
+ function toSnakeCase(obj) {
8
+ const result = {};
9
+ for (const [key, value] of Object.entries(obj)) {
10
+ if (value === undefined)
11
+ continue;
12
+ const snakeKey = key.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);
13
+ result[snakeKey] = value;
14
+ }
15
+ return result;
16
+ }
17
+ function parseGeneration(data) {
18
+ return {
19
+ id: data.id || data.generation_id || "",
20
+ status: data.status || "pending",
21
+ outputUrl: data.output_url,
22
+ model: data.model,
23
+ creditsUsed: data.credits_used,
24
+ error: data.error,
25
+ createdAt: data.created_at,
26
+ completedAt: data.completed_at,
27
+ };
28
+ }
29
+ async function handleResponse(response) {
30
+ let body;
31
+ try {
32
+ body = await response.json();
33
+ }
34
+ catch {
35
+ body = { detail: await response.text().catch(() => "Unknown error") };
36
+ }
37
+ if (response.ok)
38
+ return body;
39
+ const message = (body.detail || body.error || body.message || "Request failed");
40
+ const status = response.status;
41
+ if (status === 401)
42
+ throw new errors_1.AuthenticationError(message, status, body);
43
+ if (status === 402)
44
+ throw new errors_1.InsufficientCreditsError(message, status, body);
45
+ if (status === 404)
46
+ throw new errors_1.NotFoundError(message, status, body);
47
+ if (status === 422)
48
+ throw new errors_1.ValidationError(message, status, body);
49
+ if (status === 429) {
50
+ const retryAfter = response.headers.get("retry-after");
51
+ throw new errors_1.RateLimitError(message, status, body, retryAfter ? parseFloat(retryAfter) : undefined);
52
+ }
53
+ throw new errors_1.PixelAPIError(message, status, body);
54
+ }
55
+ function sleep(ms) {
56
+ return new Promise((resolve) => setTimeout(resolve, ms));
57
+ }
58
+ class ImageResource {
59
+ constructor(request) {
60
+ this.request = request;
61
+ }
62
+ async generate(options) {
63
+ const { prompt, model = "flux-schnell", ...rest } = options;
64
+ const body = toSnakeCase({ prompt, model, ...rest });
65
+ return parseGeneration(await this.request("POST", "/v1/image/generate", body));
66
+ }
67
+ async removeBackground(options) {
68
+ const body = toSnakeCase(options);
69
+ return parseGeneration(await this.request("POST", "/v1/image/remove-background", body));
70
+ }
71
+ async upscale(options) {
72
+ const body = toSnakeCase(options);
73
+ return parseGeneration(await this.request("POST", "/v1/image/upscale", body));
74
+ }
75
+ async restoreFace(options) {
76
+ const body = toSnakeCase(options);
77
+ return parseGeneration(await this.request("POST", "/v1/image/restore-face", body));
78
+ }
79
+ async removeObject(options) {
80
+ const body = toSnakeCase(options);
81
+ return parseGeneration(await this.request("POST", "/v1/image/remove-object", body));
82
+ }
83
+ async replaceBackground(options) {
84
+ const body = toSnakeCase(options);
85
+ return parseGeneration(await this.request("POST", "/v1/image/replace-background", body));
86
+ }
87
+ }
88
+ class AudioResource {
89
+ constructor(request) {
90
+ this.request = request;
91
+ }
92
+ async generate(options) {
93
+ const { prompt, duration = 15, ...rest } = options;
94
+ const body = toSnakeCase({ prompt, duration, ...rest });
95
+ return parseGeneration(await this.request("POST", "/v1/audio/generate", body));
96
+ }
97
+ }
98
+ class GenerationResource {
99
+ constructor(request) {
100
+ this.request = request;
101
+ }
102
+ async get(generationId) {
103
+ return parseGeneration(await this.request("GET", `/v1/image/${generationId}`));
104
+ }
105
+ async wait(generationId, options = {}) {
106
+ const { timeout = 120000, pollInterval = 1000 } = options;
107
+ const deadline = Date.now() + timeout;
108
+ while (true) {
109
+ const gen = await this.get(generationId);
110
+ if (gen.status === "completed")
111
+ return gen;
112
+ if (gen.status === "failed") {
113
+ throw new errors_1.PixelAPIError(gen.error || "Generation failed", undefined, { generationId, status: gen.status });
114
+ }
115
+ if (Date.now() >= deadline) {
116
+ throw new errors_1.TimeoutError(`Generation ${generationId} did not complete within ${timeout}ms`);
117
+ }
118
+ await sleep(pollInterval);
119
+ }
120
+ }
121
+ }
122
+ class PixelAPI {
123
+ constructor(apiKey, options = {}) {
124
+ this.apiKey = apiKey;
125
+ this.baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
126
+ this.timeout = options.timeout || 60000;
127
+ const request = this.request.bind(this);
128
+ this.image = new ImageResource(request);
129
+ this.audio = new AudioResource(request);
130
+ this.generation = new GenerationResource(request);
131
+ }
132
+ async request(method, path, body) {
133
+ const controller = new AbortController();
134
+ const timer = setTimeout(() => controller.abort(), this.timeout);
135
+ try {
136
+ const response = await fetch(`${this.baseUrl}${path}`, {
137
+ method,
138
+ headers: {
139
+ Authorization: `Bearer ${this.apiKey}`,
140
+ "Content-Type": "application/json",
141
+ "User-Agent": `pixelapi-js/${VERSION}`,
142
+ },
143
+ body: body ? JSON.stringify(body) : undefined,
144
+ signal: controller.signal,
145
+ });
146
+ return handleResponse(response);
147
+ }
148
+ finally {
149
+ clearTimeout(timer);
150
+ }
151
+ }
152
+ }
153
+ exports.PixelAPI = PixelAPI;
154
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,qCAQkB;AAclB,MAAM,OAAO,GAAG,OAAO,CAAC;AACxB,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,SAAS,WAAW,CAAC,GAA4B;IAC/C,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC3B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,eAAe,CAAC,IAA6B;IACpD,OAAO;QACL,EAAE,EAAG,IAAI,CAAC,EAAa,IAAK,IAAI,CAAC,aAAwB,IAAI,EAAE;QAC/D,MAAM,EAAG,IAAI,CAAC,MAA+B,IAAI,SAAS;QAC1D,SAAS,EAAE,IAAI,CAAC,UAAgC;QAChD,KAAK,EAAE,IAAI,CAAC,KAA2B;QACvC,WAAW,EAAE,IAAI,CAAC,YAAkC;QACpD,KAAK,EAAE,IAAI,CAAC,KAA2B;QACvC,SAAS,EAAE,IAAI,CAAC,UAAgC;QAChD,WAAW,EAAE,IAAI,CAAC,YAAkC;KACrD,CAAC;AACJ,CAAC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AAC,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,IAAY,EAAE,IAAc;QAChE,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;gBACrD,MAAM;gBACN,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;oBACtC,cAAc,EAAE,kBAAkB;oBAClC,YAAY,EAAE,eAAe,OAAO,EAAE;iBACvC;gBACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;gBAC7C,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B,CAAC,CAAC;YACH,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF;AAxCD,4BAwCC"}
@@ -0,0 +1,25 @@
1
+ export declare class PixelAPIError extends Error {
2
+ status?: number;
3
+ body?: Record<string, unknown>;
4
+ constructor(message: string, status?: number, body?: Record<string, unknown>);
5
+ }
6
+ export declare class AuthenticationError extends PixelAPIError {
7
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
8
+ }
9
+ export declare class RateLimitError extends PixelAPIError {
10
+ retryAfter?: number;
11
+ constructor(message?: string, status?: number, body?: Record<string, unknown>, retryAfter?: number);
12
+ }
13
+ export declare class InsufficientCreditsError extends PixelAPIError {
14
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
15
+ }
16
+ export declare class NotFoundError extends PixelAPIError {
17
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
18
+ }
19
+ export declare class ValidationError extends PixelAPIError {
20
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
21
+ }
22
+ export declare class TimeoutError extends PixelAPIError {
23
+ constructor(message: string);
24
+ }
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEnB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAM7E;AAED,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,SAA+B,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIjG;AAED,qBAAa,cAAe,SAAQ,aAAa;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;gBAER,OAAO,SAAwB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM;CAK/G;AAED,qBAAa,wBAAyB,SAAQ,aAAa;gBAC7C,OAAO,SAAyB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI3F;AAED,qBAAa,aAAc,SAAQ,aAAa;gBAClC,OAAO,SAAuB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIzF;AAED,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,SAAqB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIvF;AAED,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,EAAE,MAAM;CAI5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeoutError = exports.ValidationError = exports.NotFoundError = exports.InsufficientCreditsError = exports.RateLimitError = exports.AuthenticationError = exports.PixelAPIError = void 0;
4
+ class PixelAPIError extends Error {
5
+ constructor(message, status, body) {
6
+ super(message);
7
+ this.name = "PixelAPIError";
8
+ this.status = status;
9
+ this.body = body;
10
+ }
11
+ }
12
+ exports.PixelAPIError = PixelAPIError;
13
+ class AuthenticationError extends PixelAPIError {
14
+ constructor(message = "Invalid or missing API key", status = 401, body) {
15
+ super(message, status, body);
16
+ this.name = "AuthenticationError";
17
+ }
18
+ }
19
+ exports.AuthenticationError = AuthenticationError;
20
+ class RateLimitError extends PixelAPIError {
21
+ constructor(message = "Rate limit exceeded", status = 429, body, retryAfter) {
22
+ super(message, status, body);
23
+ this.name = "RateLimitError";
24
+ this.retryAfter = retryAfter;
25
+ }
26
+ }
27
+ exports.RateLimitError = RateLimitError;
28
+ class InsufficientCreditsError extends PixelAPIError {
29
+ constructor(message = "Insufficient credits", status = 402, body) {
30
+ super(message, status, body);
31
+ this.name = "InsufficientCreditsError";
32
+ }
33
+ }
34
+ exports.InsufficientCreditsError = InsufficientCreditsError;
35
+ class NotFoundError extends PixelAPIError {
36
+ constructor(message = "Resource not found", status = 404, body) {
37
+ super(message, status, body);
38
+ this.name = "NotFoundError";
39
+ }
40
+ }
41
+ exports.NotFoundError = NotFoundError;
42
+ class ValidationError extends PixelAPIError {
43
+ constructor(message = "Validation error", status = 422, body) {
44
+ super(message, status, body);
45
+ this.name = "ValidationError";
46
+ }
47
+ }
48
+ exports.ValidationError = ValidationError;
49
+ class TimeoutError extends PixelAPIError {
50
+ constructor(message) {
51
+ super(message);
52
+ this.name = "TimeoutError";
53
+ }
54
+ }
55
+ exports.TimeoutError = TimeoutError;
56
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,aAAc,SAAQ,KAAK;IAItC,YAAY,OAAe,EAAE,MAAe,EAAE,IAA8B;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAVD,sCAUC;AAED,MAAa,mBAAoB,SAAQ,aAAa;IACpD,YAAY,OAAO,GAAG,4BAA4B,EAAE,MAAM,GAAG,GAAG,EAAE,IAA8B;QAC9F,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAED,MAAa,cAAe,SAAQ,aAAa;IAG/C,YAAY,OAAO,GAAG,qBAAqB,EAAE,MAAM,GAAG,GAAG,EAAE,IAA8B,EAAE,UAAmB;QAC5G,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AARD,wCAQC;AAED,MAAa,wBAAyB,SAAQ,aAAa;IACzD,YAAY,OAAO,GAAG,sBAAsB,EAAE,MAAM,GAAG,GAAG,EAAE,IAA8B;QACxF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AALD,4DAKC;AAED,MAAa,aAAc,SAAQ,aAAa;IAC9C,YAAY,OAAO,GAAG,oBAAoB,EAAE,MAAM,GAAG,GAAG,EAAE,IAA8B;QACtF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AALD,sCAKC;AAED,MAAa,eAAgB,SAAQ,aAAa;IAChD,YAAY,OAAO,GAAG,kBAAkB,EAAE,MAAM,GAAG,GAAG,EAAE,IAA8B;QACpF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED,MAAa,YAAa,SAAQ,aAAa;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC"}
@@ -0,0 +1,34 @@
1
+ import type { Generation, GenerateImageOptions, RemoveBackgroundOptions, UpscaleOptions, RestoreFaceOptions, RemoveObjectOptions, ReplaceBackgroundOptions, GenerateAudioOptions, WaitOptions, PixelAPIOptions } from "./types";
2
+ declare class ImageResource {
3
+ private request;
4
+ constructor(request: (method: string, path: string, body?: unknown) => Promise<Record<string, unknown>>);
5
+ generate(options: GenerateImageOptions): Promise<Generation>;
6
+ removeBackground(options: RemoveBackgroundOptions): Promise<Generation>;
7
+ upscale(options: UpscaleOptions): Promise<Generation>;
8
+ restoreFace(options: RestoreFaceOptions): Promise<Generation>;
9
+ removeObject(options: RemoveObjectOptions): Promise<Generation>;
10
+ replaceBackground(options: ReplaceBackgroundOptions): Promise<Generation>;
11
+ }
12
+ declare class AudioResource {
13
+ private request;
14
+ constructor(request: (method: string, path: string, body?: unknown) => Promise<Record<string, unknown>>);
15
+ generate(options: GenerateAudioOptions): Promise<Generation>;
16
+ }
17
+ declare class GenerationResource {
18
+ private request;
19
+ constructor(request: (method: string, path: string, body?: unknown) => Promise<Record<string, unknown>>);
20
+ get(generationId: string): Promise<Generation>;
21
+ wait(generationId: string, options?: WaitOptions): Promise<Generation>;
22
+ }
23
+ export declare class PixelAPI {
24
+ readonly image: ImageResource;
25
+ readonly audio: AudioResource;
26
+ readonly generation: GenerationResource;
27
+ private baseUrl;
28
+ private apiKey;
29
+ private timeout;
30
+ constructor(apiKey: string, options?: PixelAPIOptions);
31
+ private request;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,EACX,eAAe,EAChB,MAAM,SAAS,CAAC;AAwDjB,cAAM,aAAa;IACL,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzG,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;IAM5D,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,UAAU,CAAC;IAKvE,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAKrD,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC;IAK7D,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IAK/D,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;CAIhF;AAED,cAAM,aAAa;IACL,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzG,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;CAKnE;AAED,cAAM,kBAAkB;IACV,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzG,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI9C,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;CAkBjF;AAED,qBAAa,QAAQ;IACnB,SAAgB,KAAK,EAAE,aAAa,CAAC;IACrC,SAAgB,KAAK,EAAE,aAAa,CAAC;IACrC,SAAgB,UAAU,EAAE,kBAAkB,CAAC;IAE/C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;YAW3C,OAAO;CAoBtB"}
@@ -0,0 +1,150 @@
1
+ import { PixelAPIError, AuthenticationError, RateLimitError, InsufficientCreditsError, NotFoundError, ValidationError, TimeoutError, } from "./errors";
2
+ const VERSION = "0.1.0";
3
+ const DEFAULT_BASE_URL = "https://api.pixelapi.dev";
4
+ function toSnakeCase(obj) {
5
+ const result = {};
6
+ for (const [key, value] of Object.entries(obj)) {
7
+ if (value === undefined)
8
+ continue;
9
+ const snakeKey = key.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);
10
+ result[snakeKey] = value;
11
+ }
12
+ return result;
13
+ }
14
+ function parseGeneration(data) {
15
+ return {
16
+ id: data.id || data.generation_id || "",
17
+ status: data.status || "pending",
18
+ outputUrl: data.output_url,
19
+ model: data.model,
20
+ creditsUsed: data.credits_used,
21
+ error: data.error,
22
+ createdAt: data.created_at,
23
+ completedAt: data.completed_at,
24
+ };
25
+ }
26
+ async function handleResponse(response) {
27
+ let body;
28
+ try {
29
+ body = await response.json();
30
+ }
31
+ catch {
32
+ body = { detail: await response.text().catch(() => "Unknown error") };
33
+ }
34
+ if (response.ok)
35
+ return body;
36
+ const message = (body.detail || body.error || body.message || "Request failed");
37
+ const status = response.status;
38
+ if (status === 401)
39
+ throw new AuthenticationError(message, status, body);
40
+ if (status === 402)
41
+ throw new InsufficientCreditsError(message, status, body);
42
+ if (status === 404)
43
+ throw new NotFoundError(message, status, body);
44
+ if (status === 422)
45
+ throw new ValidationError(message, status, body);
46
+ if (status === 429) {
47
+ const retryAfter = response.headers.get("retry-after");
48
+ throw new RateLimitError(message, status, body, retryAfter ? parseFloat(retryAfter) : undefined);
49
+ }
50
+ throw new PixelAPIError(message, status, body);
51
+ }
52
+ function sleep(ms) {
53
+ return new Promise((resolve) => setTimeout(resolve, ms));
54
+ }
55
+ class ImageResource {
56
+ constructor(request) {
57
+ this.request = request;
58
+ }
59
+ async generate(options) {
60
+ const { prompt, model = "flux-schnell", ...rest } = options;
61
+ const body = toSnakeCase({ prompt, model, ...rest });
62
+ return parseGeneration(await this.request("POST", "/v1/image/generate", body));
63
+ }
64
+ async removeBackground(options) {
65
+ const body = toSnakeCase(options);
66
+ return parseGeneration(await this.request("POST", "/v1/image/remove-background", body));
67
+ }
68
+ async upscale(options) {
69
+ const body = toSnakeCase(options);
70
+ return parseGeneration(await this.request("POST", "/v1/image/upscale", body));
71
+ }
72
+ async restoreFace(options) {
73
+ const body = toSnakeCase(options);
74
+ return parseGeneration(await this.request("POST", "/v1/image/restore-face", body));
75
+ }
76
+ async removeObject(options) {
77
+ const body = toSnakeCase(options);
78
+ return parseGeneration(await this.request("POST", "/v1/image/remove-object", body));
79
+ }
80
+ async replaceBackground(options) {
81
+ const body = toSnakeCase(options);
82
+ return parseGeneration(await this.request("POST", "/v1/image/replace-background", body));
83
+ }
84
+ }
85
+ class AudioResource {
86
+ constructor(request) {
87
+ this.request = request;
88
+ }
89
+ async generate(options) {
90
+ const { prompt, duration = 15, ...rest } = options;
91
+ const body = toSnakeCase({ prompt, duration, ...rest });
92
+ return parseGeneration(await this.request("POST", "/v1/audio/generate", body));
93
+ }
94
+ }
95
+ class GenerationResource {
96
+ constructor(request) {
97
+ this.request = request;
98
+ }
99
+ async get(generationId) {
100
+ return parseGeneration(await this.request("GET", `/v1/image/${generationId}`));
101
+ }
102
+ async wait(generationId, options = {}) {
103
+ const { timeout = 120000, pollInterval = 1000 } = options;
104
+ const deadline = Date.now() + timeout;
105
+ while (true) {
106
+ const gen = await this.get(generationId);
107
+ if (gen.status === "completed")
108
+ return gen;
109
+ if (gen.status === "failed") {
110
+ throw new PixelAPIError(gen.error || "Generation failed", undefined, { generationId, status: gen.status });
111
+ }
112
+ if (Date.now() >= deadline) {
113
+ throw new TimeoutError(`Generation ${generationId} did not complete within ${timeout}ms`);
114
+ }
115
+ await sleep(pollInterval);
116
+ }
117
+ }
118
+ }
119
+ export class PixelAPI {
120
+ constructor(apiKey, options = {}) {
121
+ this.apiKey = apiKey;
122
+ this.baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
123
+ this.timeout = options.timeout || 60000;
124
+ const request = this.request.bind(this);
125
+ this.image = new ImageResource(request);
126
+ this.audio = new AudioResource(request);
127
+ this.generation = new GenerationResource(request);
128
+ }
129
+ async request(method, path, body) {
130
+ const controller = new AbortController();
131
+ const timer = setTimeout(() => controller.abort(), this.timeout);
132
+ try {
133
+ const response = await fetch(`${this.baseUrl}${path}`, {
134
+ method,
135
+ headers: {
136
+ Authorization: `Bearer ${this.apiKey}`,
137
+ "Content-Type": "application/json",
138
+ "User-Agent": `pixelapi-js/${VERSION}`,
139
+ },
140
+ body: body ? JSON.stringify(body) : undefined,
141
+ signal: controller.signal,
142
+ });
143
+ return handleResponse(response);
144
+ }
145
+ finally {
146
+ clearTimeout(timer);
147
+ }
148
+ }
149
+ }
150
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,UAAU,CAAC;AAclB,MAAM,OAAO,GAAG,OAAO,CAAC;AACxB,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,SAAS,WAAW,CAAC,GAA4B;IAC/C,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACrE,MAAM,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IAC3B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,eAAe,CAAC,IAA6B;IACpD,OAAO;QACL,EAAE,EAAG,IAAI,CAAC,EAAa,IAAK,IAAI,CAAC,aAAwB,IAAI,EAAE;QAC/D,MAAM,EAAG,IAAI,CAAC,MAA+B,IAAI,SAAS;QAC1D,SAAS,EAAE,IAAI,CAAC,UA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,KAAK,CAAC;QAExC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,IAAY,EAAE,IAAc;QAChE,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;gBACrD,MAAM;gBACN,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;oBACtC,cAAc,EAAE,kBAAkB;oBAClC,YAAY,EAAE,eAAe,OAAO,EAAE;iBACvC;gBACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;gBAC7C,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B,CAAC,CAAC;YACH,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ export declare class PixelAPIError extends Error {
2
+ status?: number;
3
+ body?: Record<string, unknown>;
4
+ constructor(message: string, status?: number, body?: Record<string, unknown>);
5
+ }
6
+ export declare class AuthenticationError extends PixelAPIError {
7
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
8
+ }
9
+ export declare class RateLimitError extends PixelAPIError {
10
+ retryAfter?: number;
11
+ constructor(message?: string, status?: number, body?: Record<string, unknown>, retryAfter?: number);
12
+ }
13
+ export declare class InsufficientCreditsError extends PixelAPIError {
14
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
15
+ }
16
+ export declare class NotFoundError extends PixelAPIError {
17
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
18
+ }
19
+ export declare class ValidationError extends PixelAPIError {
20
+ constructor(message?: string, status?: number, body?: Record<string, unknown>);
21
+ }
22
+ export declare class TimeoutError extends PixelAPIError {
23
+ constructor(message: string);
24
+ }
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEnB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAM7E;AAED,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,SAA+B,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIjG;AAED,qBAAa,cAAe,SAAQ,aAAa;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;gBAER,OAAO,SAAwB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM;CAK/G;AAED,qBAAa,wBAAyB,SAAQ,aAAa;gBAC7C,OAAO,SAAyB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI3F;AAED,qBAAa,aAAc,SAAQ,aAAa;gBAClC,OAAO,SAAuB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIzF;AAED,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,SAAqB,EAAE,MAAM,SAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIvF;AAED,qBAAa,YAAa,SAAQ,aAAa;gBACjC,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,46 @@
1
+ export class PixelAPIError extends Error {
2
+ constructor(message, status, body) {
3
+ super(message);
4
+ this.name = "PixelAPIError";
5
+ this.status = status;
6
+ this.body = body;
7
+ }
8
+ }
9
+ export class AuthenticationError extends PixelAPIError {
10
+ constructor(message = "Invalid or missing API key", status = 401, body) {
11
+ super(message, status, body);
12
+ this.name = "AuthenticationError";
13
+ }
14
+ }
15
+ export class RateLimitError extends PixelAPIError {
16
+ constructor(message = "Rate limit exceeded", status = 429, body, retryAfter) {
17
+ super(message, status, body);
18
+ this.name = "RateLimitError";
19
+ this.retryAfter = retryAfter;
20
+ }
21
+ }
22
+ export class InsufficientCreditsError extends PixelAPIError {
23
+ constructor(message = "Insufficient credits", status = 402, body) {
24
+ super(message, status, body);
25
+ this.name = "InsufficientCreditsError";
26
+ }
27
+ }
28
+ export class NotFoundError extends PixelAPIError {
29
+ constructor(message = "Resource not found", status = 404, body) {
30
+ super(message, status, body);
31
+ this.name = "NotFoundError";
32
+ }
33
+ }
34
+ export class ValidationError extends PixelAPIError {
35
+ constructor(message = "Validation error", status = 422, body) {
36
+ super(message, status, body);
37
+ this.name = "ValidationError";
38
+ }
39
+ }
40
+ export class TimeoutError extends PixelAPIError {
41
+ constructor(message) {
42
+ super(message);
43
+ this.name = "TimeoutError";
44
+ }
45
+ }
46
+ //# s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CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,aAAa;IAChD,YAAY,OAAO,GAAG,kBAAkB,EAAE,MAAM,GAAG,GAAG,EAAE,IAA8B;QACpF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export { PixelAPI } from "./client";
2
+ export type { Generation, GenerationStatus, GenerateImageOptions, RemoveBackgroundOptions, UpscaleOptions, RestoreFaceOptions, RemoveObjectOptions, ReplaceBackgroundOptions, GenerateAudioOptions, WaitOptions, PixelAPIOptions, } from "./types";
3
+ export { PixelAPIError, AuthenticationError, RateLimitError, InsufficientCreditsError, NotFoundError, ValidationError, TimeoutError, } from "./errors";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { PixelAPI } from "./client";
2
+ export { PixelAPIError, AuthenticationError, RateLimitError, InsufficientCreditsError, NotFoundError, ValidationError, TimeoutError, } from "./errors";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAcpC,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,UAAU,CAAC"}
@@ -0,0 +1,56 @@
1
+ export type GenerationStatus = "pending" | "processing" | "completed" | "failed";
2
+ export interface Generation {
3
+ id: string;
4
+ status: GenerationStatus;
5
+ outputUrl?: string;
6
+ model?: string;
7
+ creditsUsed?: number;
8
+ error?: string;
9
+ createdAt?: string;
10
+ completedAt?: string;
11
+ [key: string]: unknown;
12
+ }
13
+ export interface GenerateImageOptions {
14
+ prompt: string;
15
+ model?: string;
16
+ width?: number;
17
+ height?: number;
18
+ negativePrompt?: string;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface RemoveBackgroundOptions {
22
+ imageUrl: string;
23
+ [key: string]: unknown;
24
+ }
25
+ export interface UpscaleOptions {
26
+ imageUrl: string;
27
+ [key: string]: unknown;
28
+ }
29
+ export interface RestoreFaceOptions {
30
+ imageUrl: string;
31
+ [key: string]: unknown;
32
+ }
33
+ export interface RemoveObjectOptions {
34
+ imageUrl: string;
35
+ maskUrl: string;
36
+ [key: string]: unknown;
37
+ }
38
+ export interface ReplaceBackgroundOptions {
39
+ imageUrl: string;
40
+ prompt: string;
41
+ [key: string]: unknown;
42
+ }
43
+ export interface GenerateAudioOptions {
44
+ prompt: string;
45
+ duration?: number;
46
+ [key: string]: unknown;
47
+ }
48
+ export interface WaitOptions {
49
+ timeout?: number;
50
+ pollInterval?: number;
51
+ }
52
+ export interface PixelAPIOptions {
53
+ baseUrl?: string;
54
+ timeout?: number;
55
+ }
56
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEjF,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export { PixelAPI } from "./client";
2
+ export type { Generation, GenerationStatus, GenerateImageOptions, RemoveBackgroundOptions, UpscaleOptions, RestoreFaceOptions, RemoveObjectOptions, ReplaceBackgroundOptions, GenerateAudioOptions, WaitOptions, PixelAPIOptions, } from "./types";
3
+ export { PixelAPIError, AuthenticationError, RateLimitError, InsufficientCreditsError, NotFoundError, ValidationError, TimeoutError, } from "./errors";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeoutError = exports.ValidationError = exports.NotFoundError = exports.InsufficientCreditsError = exports.RateLimitError = exports.AuthenticationError = exports.PixelAPIError = exports.PixelAPI = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "PixelAPI", { enumerable: true, get: function () { return client_1.PixelAPI; } });
6
+ var errors_1 = require("./errors");
7
+ Object.defineProperty(exports, "PixelAPIError", { enumerable: true, get: function () { return errors_1.PixelAPIError; } });
8
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
9
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
10
+ Object.defineProperty(exports, "InsufficientCreditsError", { enumerable: true, get: function () { return errors_1.InsufficientCreditsError; } });
11
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_1.NotFoundError; } });
12
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
13
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAA3B,kGAAA,QAAQ,OAAA;AAcjB,mCAQkB;AAPhB,uGAAA,aAAa,OAAA;AACb,6GAAA,mBAAmB,OAAA;AACnB,wGAAA,cAAc,OAAA;AACd,kHAAA,wBAAwB,OAAA;AACxB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,sGAAA,YAAY,OAAA"}
@@ -0,0 +1,56 @@
1
+ export type GenerationStatus = "pending" | "processing" | "completed" | "failed";
2
+ export interface Generation {
3
+ id: string;
4
+ status: GenerationStatus;
5
+ outputUrl?: string;
6
+ model?: string;
7
+ creditsUsed?: number;
8
+ error?: string;
9
+ createdAt?: string;
10
+ completedAt?: string;
11
+ [key: string]: unknown;
12
+ }
13
+ export interface GenerateImageOptions {
14
+ prompt: string;
15
+ model?: string;
16
+ width?: number;
17
+ height?: number;
18
+ negativePrompt?: string;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface RemoveBackgroundOptions {
22
+ imageUrl: string;
23
+ [key: string]: unknown;
24
+ }
25
+ export interface UpscaleOptions {
26
+ imageUrl: string;
27
+ [key: string]: unknown;
28
+ }
29
+ export interface RestoreFaceOptions {
30
+ imageUrl: string;
31
+ [key: string]: unknown;
32
+ }
33
+ export interface RemoveObjectOptions {
34
+ imageUrl: string;
35
+ maskUrl: string;
36
+ [key: string]: unknown;
37
+ }
38
+ export interface ReplaceBackgroundOptions {
39
+ imageUrl: string;
40
+ prompt: string;
41
+ [key: string]: unknown;
42
+ }
43
+ export interface GenerateAudioOptions {
44
+ prompt: string;
45
+ duration?: number;
46
+ [key: string]: unknown;
47
+ }
48
+ export interface WaitOptions {
49
+ timeout?: number;
50
+ pollInterval?: number;
51
+ }
52
+ export interface PixelAPIOptions {
53
+ baseUrl?: string;
54
+ timeout?: number;
55
+ }
56
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEjF,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,gBAAgB,CAAC;IACzB,S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EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "pixelapi",
3
+ "version": "0.1.0",
4
+ "description": "Official JavaScript/TypeScript SDK for PixelAPI — AI image generation, background removal, upscaling, and audio generation API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": ["dist", "README.md", "LICENSE"],
16
+ "scripts": {
17
+ "build": "tsc && tsc --module esnext --outDir dist/esm",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "keywords": [
21
+ "pixelapi", "ai", "image-generation", "background-removal",
22
+ "upscaling", "face-restoration", "audio-generation", "api",
23
+ "sdk", "text-to-image", "typescript"
24
+ ],
25
+ "author": "PixelAPI <support@pixelapi.dev>",
26
+ "license": "MIT",
27
+ "homepage": "https://pixelapi.dev",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/pixelapi/pixelapi-js"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/pixelapi/pixelapi-js/issues"
34
+ },
35
+ "engines": {
36
+ "node": ">=18.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "typescript": "^5.3.0"
40
+ }
41
+ }