@runapi.ai/gpt-4o-image 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.d.mts +68 -3
- package/dist/index.d.ts +68 -3
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ const status = await client.generations.get(task.id);
|
|
|
24
24
|
|
|
25
25
|
Use `create` when you want to submit a task and return quickly, `get` when you need the latest task state, and `run` when a script should create and poll until completion. In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
|
|
26
26
|
|
|
27
|
+
RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
|
|
28
|
+
|
|
27
29
|
## Language notes
|
|
28
30
|
|
|
29
31
|
Use the TypeScript types in `src/types.ts` and the resource classes under `src/resources` when building image applications. The available resources include generations. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
import { AsyncTaskStatus, HttpClient, RequestOptions, PollingOptions, ClientOptions } from '@runapi.ai/core';
|
|
1
|
+
import { AsyncTaskStatus, HttpClient, RequestOptions, PollingOptions, BaseClient, ClientOptions } from '@runapi.ai/core';
|
|
2
2
|
export { AuthenticationError, InsufficientCreditsError, NetworkError, NotFoundError, RateLimitError, RunApiError, ServiceUnavailableError, TaskFailedError, TaskTimeoutError, TimeoutError, ValidationError } from '@runapi.ai/core';
|
|
3
3
|
|
|
4
4
|
type Gpt4oImageModel = 'gpt-4o-image';
|
|
5
|
+
/** Required output aspect ratio. */
|
|
5
6
|
type AspectRatio = '1:1' | '3:2' | '2:3';
|
|
7
|
+
/** Batch output size: 1, 2, or 4 images per request. */
|
|
6
8
|
type OutputCount = 1 | 2 | 4;
|
|
9
|
+
/**
|
|
10
|
+
* Parameters for GPT-4o image generation and editing.
|
|
11
|
+
*
|
|
12
|
+
* - For pure generation, provide `prompt` (required) and `aspect_ratio`.
|
|
13
|
+
* - For editing, provide `source_image_urls` (up to 5); `prompt` becomes
|
|
14
|
+
* optional since the model can generate variants without one.
|
|
15
|
+
* - For inpainting, also provide `mask_url` to indicate which regions of
|
|
16
|
+
* the source image to regenerate.
|
|
17
|
+
*/
|
|
7
18
|
interface TextToImageParams {
|
|
8
19
|
model: Gpt4oImageModel;
|
|
20
|
+
/** Text prompt; required when source_image_urls is not provided. */
|
|
9
21
|
prompt?: string;
|
|
10
22
|
aspect_ratio: AspectRatio;
|
|
23
|
+
/** Up to 5 source image URLs for edits or variants. */
|
|
11
24
|
source_image_urls?: string[];
|
|
25
|
+
/** Mask image URL marking regions to regenerate (inpainting); only meaningful with source_image_urls. */
|
|
12
26
|
mask_url?: string;
|
|
13
27
|
output_count?: OutputCount;
|
|
14
28
|
callback_url?: string;
|
|
29
|
+
/** Let the model expand short prompts with additional detail. */
|
|
15
30
|
enable_prompt_expansion?: boolean;
|
|
16
31
|
}
|
|
17
32
|
interface TaskCreateResponse {
|
|
18
33
|
id: string;
|
|
19
34
|
status: string;
|
|
20
35
|
}
|
|
36
|
+
/** A generated image with its CDN URL. */
|
|
21
37
|
interface Image {
|
|
22
38
|
url: string;
|
|
23
39
|
}
|
|
@@ -25,23 +41,72 @@ interface TextToImageResponse {
|
|
|
25
41
|
id: string;
|
|
26
42
|
status: AsyncTaskStatus;
|
|
27
43
|
images?: Image[];
|
|
44
|
+
/** Intermediate status string while the task is running. */
|
|
28
45
|
progress?: string;
|
|
29
46
|
error?: string;
|
|
30
47
|
[key: string]: unknown;
|
|
31
48
|
}
|
|
32
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Generates images from a text prompt, optionally guided by source images and a mask.
|
|
52
|
+
* For pure generation, provide a prompt. For editing, provide source_image_urls
|
|
53
|
+
* (and optionally mask_url) to modify specific regions of the source.
|
|
54
|
+
*/
|
|
33
55
|
declare class TextToImage {
|
|
34
56
|
private readonly http;
|
|
35
57
|
constructor(http: HttpClient);
|
|
58
|
+
/**
|
|
59
|
+
* Generate an image and wait until complete.
|
|
60
|
+
* @param params Text-to-image parameters.
|
|
61
|
+
* @param options Per-request and polling overrides.
|
|
62
|
+
* @returns The completed text-to-image result.
|
|
63
|
+
*/
|
|
36
64
|
run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<TextToImageResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Create a text-to-image task; returns immediately with a task id.
|
|
67
|
+
* @param params Text-to-image parameters.
|
|
68
|
+
* @param options Per-request overrides.
|
|
69
|
+
* @returns The task creation result with id.
|
|
70
|
+
*/
|
|
37
71
|
create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Fetch the current status of a text-to-image task.
|
|
74
|
+
* @param id The task id.
|
|
75
|
+
* @param options Per-request overrides.
|
|
76
|
+
* @returns The current text-to-image status.
|
|
77
|
+
*/
|
|
38
78
|
get(id: string, options?: RequestOptions): Promise<TextToImageResponse>;
|
|
39
79
|
}
|
|
40
80
|
|
|
41
81
|
/**
|
|
42
|
-
* GPT-4o Image
|
|
82
|
+
* GPT-4o Image generation and editing API client.
|
|
83
|
+
*
|
|
84
|
+
* Supports pure text-to-image generation, image editing with source images,
|
|
85
|
+
* and inpainting with an optional mask. At least one of `prompt` or
|
|
86
|
+
* `source_image_urls` must be provided.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const client = new Gpt4oImageClient({ apiKey: 'your-api-key' });
|
|
91
|
+
*
|
|
92
|
+
* // Pure generation
|
|
93
|
+
* const result = await client.textToImage.run({
|
|
94
|
+
* model: 'gpt-4o-image',
|
|
95
|
+
* prompt: 'A watercolor painting of a sunset',
|
|
96
|
+
* aspect_ratio: '3:2',
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Edit with source images
|
|
100
|
+
* const edited = await client.textToImage.run({
|
|
101
|
+
* model: 'gpt-4o-image',
|
|
102
|
+
* prompt: 'Add a rainbow',
|
|
103
|
+
* aspect_ratio: '3:2',
|
|
104
|
+
* source_image_urls: ['https://example.com/photo.jpg'],
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
43
107
|
*/
|
|
44
|
-
declare class Gpt4oImageClient {
|
|
108
|
+
declare class Gpt4oImageClient extends BaseClient {
|
|
109
|
+
/** Image generation, editing, and inpainting operations. */
|
|
45
110
|
readonly textToImage: TextToImage;
|
|
46
111
|
constructor(options?: ClientOptions);
|
|
47
112
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
import { AsyncTaskStatus, HttpClient, RequestOptions, PollingOptions, ClientOptions } from '@runapi.ai/core';
|
|
1
|
+
import { AsyncTaskStatus, HttpClient, RequestOptions, PollingOptions, BaseClient, ClientOptions } from '@runapi.ai/core';
|
|
2
2
|
export { AuthenticationError, InsufficientCreditsError, NetworkError, NotFoundError, RateLimitError, RunApiError, ServiceUnavailableError, TaskFailedError, TaskTimeoutError, TimeoutError, ValidationError } from '@runapi.ai/core';
|
|
3
3
|
|
|
4
4
|
type Gpt4oImageModel = 'gpt-4o-image';
|
|
5
|
+
/** Required output aspect ratio. */
|
|
5
6
|
type AspectRatio = '1:1' | '3:2' | '2:3';
|
|
7
|
+
/** Batch output size: 1, 2, or 4 images per request. */
|
|
6
8
|
type OutputCount = 1 | 2 | 4;
|
|
9
|
+
/**
|
|
10
|
+
* Parameters for GPT-4o image generation and editing.
|
|
11
|
+
*
|
|
12
|
+
* - For pure generation, provide `prompt` (required) and `aspect_ratio`.
|
|
13
|
+
* - For editing, provide `source_image_urls` (up to 5); `prompt` becomes
|
|
14
|
+
* optional since the model can generate variants without one.
|
|
15
|
+
* - For inpainting, also provide `mask_url` to indicate which regions of
|
|
16
|
+
* the source image to regenerate.
|
|
17
|
+
*/
|
|
7
18
|
interface TextToImageParams {
|
|
8
19
|
model: Gpt4oImageModel;
|
|
20
|
+
/** Text prompt; required when source_image_urls is not provided. */
|
|
9
21
|
prompt?: string;
|
|
10
22
|
aspect_ratio: AspectRatio;
|
|
23
|
+
/** Up to 5 source image URLs for edits or variants. */
|
|
11
24
|
source_image_urls?: string[];
|
|
25
|
+
/** Mask image URL marking regions to regenerate (inpainting); only meaningful with source_image_urls. */
|
|
12
26
|
mask_url?: string;
|
|
13
27
|
output_count?: OutputCount;
|
|
14
28
|
callback_url?: string;
|
|
29
|
+
/** Let the model expand short prompts with additional detail. */
|
|
15
30
|
enable_prompt_expansion?: boolean;
|
|
16
31
|
}
|
|
17
32
|
interface TaskCreateResponse {
|
|
18
33
|
id: string;
|
|
19
34
|
status: string;
|
|
20
35
|
}
|
|
36
|
+
/** A generated image with its CDN URL. */
|
|
21
37
|
interface Image {
|
|
22
38
|
url: string;
|
|
23
39
|
}
|
|
@@ -25,23 +41,72 @@ interface TextToImageResponse {
|
|
|
25
41
|
id: string;
|
|
26
42
|
status: AsyncTaskStatus;
|
|
27
43
|
images?: Image[];
|
|
44
|
+
/** Intermediate status string while the task is running. */
|
|
28
45
|
progress?: string;
|
|
29
46
|
error?: string;
|
|
30
47
|
[key: string]: unknown;
|
|
31
48
|
}
|
|
32
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Generates images from a text prompt, optionally guided by source images and a mask.
|
|
52
|
+
* For pure generation, provide a prompt. For editing, provide source_image_urls
|
|
53
|
+
* (and optionally mask_url) to modify specific regions of the source.
|
|
54
|
+
*/
|
|
33
55
|
declare class TextToImage {
|
|
34
56
|
private readonly http;
|
|
35
57
|
constructor(http: HttpClient);
|
|
58
|
+
/**
|
|
59
|
+
* Generate an image and wait until complete.
|
|
60
|
+
* @param params Text-to-image parameters.
|
|
61
|
+
* @param options Per-request and polling overrides.
|
|
62
|
+
* @returns The completed text-to-image result.
|
|
63
|
+
*/
|
|
36
64
|
run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<TextToImageResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Create a text-to-image task; returns immediately with a task id.
|
|
67
|
+
* @param params Text-to-image parameters.
|
|
68
|
+
* @param options Per-request overrides.
|
|
69
|
+
* @returns The task creation result with id.
|
|
70
|
+
*/
|
|
37
71
|
create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Fetch the current status of a text-to-image task.
|
|
74
|
+
* @param id The task id.
|
|
75
|
+
* @param options Per-request overrides.
|
|
76
|
+
* @returns The current text-to-image status.
|
|
77
|
+
*/
|
|
38
78
|
get(id: string, options?: RequestOptions): Promise<TextToImageResponse>;
|
|
39
79
|
}
|
|
40
80
|
|
|
41
81
|
/**
|
|
42
|
-
* GPT-4o Image
|
|
82
|
+
* GPT-4o Image generation and editing API client.
|
|
83
|
+
*
|
|
84
|
+
* Supports pure text-to-image generation, image editing with source images,
|
|
85
|
+
* and inpainting with an optional mask. At least one of `prompt` or
|
|
86
|
+
* `source_image_urls` must be provided.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const client = new Gpt4oImageClient({ apiKey: 'your-api-key' });
|
|
91
|
+
*
|
|
92
|
+
* // Pure generation
|
|
93
|
+
* const result = await client.textToImage.run({
|
|
94
|
+
* model: 'gpt-4o-image',
|
|
95
|
+
* prompt: 'A watercolor painting of a sunset',
|
|
96
|
+
* aspect_ratio: '3:2',
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Edit with source images
|
|
100
|
+
* const edited = await client.textToImage.run({
|
|
101
|
+
* model: 'gpt-4o-image',
|
|
102
|
+
* prompt: 'Add a rainbow',
|
|
103
|
+
* aspect_ratio: '3:2',
|
|
104
|
+
* source_image_urls: ['https://example.com/photo.jpg'],
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
43
107
|
*/
|
|
44
|
-
declare class Gpt4oImageClient {
|
|
108
|
+
declare class Gpt4oImageClient extends BaseClient {
|
|
109
|
+
/** Image generation, editing, and inpainting operations. */
|
|
45
110
|
readonly textToImage: TextToImage;
|
|
46
111
|
constructor(options?: ClientOptions);
|
|
47
112
|
}
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,12 @@ var TextToImage = class {
|
|
|
47
47
|
this.http = http;
|
|
48
48
|
}
|
|
49
49
|
http;
|
|
50
|
+
/**
|
|
51
|
+
* Generate an image and wait until complete.
|
|
52
|
+
* @param params Text-to-image parameters.
|
|
53
|
+
* @param options Per-request and polling overrides.
|
|
54
|
+
* @returns The completed text-to-image result.
|
|
55
|
+
*/
|
|
50
56
|
async run(params, options) {
|
|
51
57
|
const { id } = await this.create(params, options);
|
|
52
58
|
return (0, import_internal.pollUntilComplete)(() => this.get(id, options), {
|
|
@@ -54,12 +60,24 @@ var TextToImage = class {
|
|
|
54
60
|
pollIntervalMs: options?.pollIntervalMs
|
|
55
61
|
});
|
|
56
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a text-to-image task; returns immediately with a task id.
|
|
65
|
+
* @param params Text-to-image parameters.
|
|
66
|
+
* @param options Per-request overrides.
|
|
67
|
+
* @returns The task creation result with id.
|
|
68
|
+
*/
|
|
57
69
|
async create(params, options) {
|
|
58
70
|
return this.http.request("POST", ENDPOINT, {
|
|
59
71
|
body: (0, import_core.compactParams)(params),
|
|
60
72
|
...options
|
|
61
73
|
});
|
|
62
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Fetch the current status of a text-to-image task.
|
|
77
|
+
* @param id The task id.
|
|
78
|
+
* @param options Per-request overrides.
|
|
79
|
+
* @returns The current text-to-image status.
|
|
80
|
+
*/
|
|
63
81
|
async get(id, options) {
|
|
64
82
|
return this.http.request("GET", `${ENDPOINT}/${id}`, {
|
|
65
83
|
...options
|
|
@@ -68,11 +86,12 @@ var TextToImage = class {
|
|
|
68
86
|
};
|
|
69
87
|
|
|
70
88
|
// src/client.ts
|
|
71
|
-
var Gpt4oImageClient = class {
|
|
89
|
+
var Gpt4oImageClient = class extends import_core2.BaseClient {
|
|
90
|
+
/** Image generation, editing, and inpainting operations. */
|
|
72
91
|
textToImage;
|
|
73
92
|
constructor(options = {}) {
|
|
74
|
-
|
|
75
|
-
this.textToImage = new TextToImage(http);
|
|
93
|
+
super(options);
|
|
94
|
+
this.textToImage = new TextToImage(this.http);
|
|
76
95
|
}
|
|
77
96
|
};
|
|
78
97
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/resources/text-to-image.ts"],"sourcesContent":["export { Gpt4oImageClient } from './client';\nexport * from './types';\n\n// Re-export core errors for convenience\nexport {\n RunApiError,\n AuthenticationError,\n InsufficientCreditsError,\n NotFoundError,\n ValidationError,\n RateLimitError,\n ServiceUnavailableError,\n NetworkError,\n TimeoutError,\n TaskTimeoutError,\n TaskFailedError,\n} from '@runapi.ai/core';\n","import {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/resources/text-to-image.ts"],"sourcesContent":["export { Gpt4oImageClient } from './client';\nexport * from './types';\n\n// Re-export core errors for convenience\nexport {\n RunApiError,\n AuthenticationError,\n InsufficientCreditsError,\n NotFoundError,\n ValidationError,\n RateLimitError,\n ServiceUnavailableError,\n NetworkError,\n TimeoutError,\n TaskTimeoutError,\n TaskFailedError,\n} from '@runapi.ai/core';\n","import { BaseClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\n\n/**\n * GPT-4o Image generation and editing API client.\n *\n * Supports pure text-to-image generation, image editing with source images,\n * and inpainting with an optional mask. At least one of `prompt` or\n * `source_image_urls` must be provided.\n *\n * @example\n * ```typescript\n * const client = new Gpt4oImageClient({ apiKey: 'your-api-key' });\n *\n * // Pure generation\n * const result = await client.textToImage.run({\n * model: 'gpt-4o-image',\n * prompt: 'A watercolor painting of a sunset',\n * aspect_ratio: '3:2',\n * });\n *\n * // Edit with source images\n * const edited = await client.textToImage.run({\n * model: 'gpt-4o-image',\n * prompt: 'Add a rainbow',\n * aspect_ratio: '3:2',\n * source_image_urls: ['https://example.com/photo.jpg'],\n * });\n * ```\n */\nexport class Gpt4oImageClient extends BaseClient {\n /** Image generation, editing, and inpainting operations. */\n public readonly textToImage: TextToImage;\n\n constructor(options: ClientOptions = {}) {\n super(options);\n this.textToImage = new TextToImage(this.http);\n }\n}\n","import type { HttpClient, PollingOptions, RequestOptions } from '@runapi.ai/core';\nimport { compactParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport type { TextToImageParams, TextToImageResponse, TaskCreateResponse } from '../types';\n\nconst ENDPOINT = '/api/v1/gpt_4o_image/text_to_image';\n\n/**\n * Generates images from a text prompt, optionally guided by source images and a mask.\n * For pure generation, provide a prompt. For editing, provide source_image_urls\n * (and optionally mask_url) to modify specific regions of the source.\n */\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate an image and wait until complete.\n * @param params Text-to-image parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed text-to-image result.\n */\n async run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<TextToImageResponse> {\n const { id } = await this.create(params, options);\n return pollUntilComplete<TextToImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n }\n\n /**\n * Create a text-to-image task; returns immediately with a task id.\n * @param params Text-to-image parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body: compactParams(params),\n ...options,\n });\n }\n\n /**\n * Fetch the current status of a text-to-image task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current text-to-image status.\n */\n async get(id: string, options?: RequestOptions): Promise<TextToImageResponse> {\n return this.http.request<TextToImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAA+C;;;ACC/C,kBAA8B;AAC9B,sBAAkC;AAGlC,IAAM,WAAW;AAOV,IAAM,cAAN,MAAkB;AAAA,EACvB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,MAAM,IAAI,QAA2B,SAAyE;AAC5G,UAAM,EAAE,GAAG,IAAI,MAAM,KAAK,OAAO,QAAQ,OAAO;AAChD,eAAO,mCAAuC,MAAM,KAAK,IAAI,IAAI,OAAO,GAAG;AAAA,MACzE,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,IAC3B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,OAAO,QAA2B,SAAuD;AAC7F,WAAO,KAAK,KAAK,QAA4B,QAAQ,UAAU;AAAA,MAC7D,UAAM,2BAAc,MAAM;AAAA,MAC1B,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,IAAY,SAAwD;AAC5E,WAAO,KAAK,KAAK,QAA6B,OAAO,GAAG,QAAQ,IAAI,EAAE,IAAI;AAAA,MACxE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;ADvBO,IAAM,mBAAN,cAA+B,wBAAW;AAAA;AAAA,EAE/B;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,OAAO;AACb,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAAA,EAC9C;AACF;;;ADlCA,IAAAC,eAYO;","names":["import_core","import_core"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
-
import {
|
|
2
|
+
import { BaseClient } from "@runapi.ai/core";
|
|
3
3
|
|
|
4
4
|
// src/resources/text-to-image.ts
|
|
5
5
|
import { compactParams } from "@runapi.ai/core";
|
|
@@ -10,6 +10,12 @@ var TextToImage = class {
|
|
|
10
10
|
this.http = http;
|
|
11
11
|
}
|
|
12
12
|
http;
|
|
13
|
+
/**
|
|
14
|
+
* Generate an image and wait until complete.
|
|
15
|
+
* @param params Text-to-image parameters.
|
|
16
|
+
* @param options Per-request and polling overrides.
|
|
17
|
+
* @returns The completed text-to-image result.
|
|
18
|
+
*/
|
|
13
19
|
async run(params, options) {
|
|
14
20
|
const { id } = await this.create(params, options);
|
|
15
21
|
return pollUntilComplete(() => this.get(id, options), {
|
|
@@ -17,12 +23,24 @@ var TextToImage = class {
|
|
|
17
23
|
pollIntervalMs: options?.pollIntervalMs
|
|
18
24
|
});
|
|
19
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a text-to-image task; returns immediately with a task id.
|
|
28
|
+
* @param params Text-to-image parameters.
|
|
29
|
+
* @param options Per-request overrides.
|
|
30
|
+
* @returns The task creation result with id.
|
|
31
|
+
*/
|
|
20
32
|
async create(params, options) {
|
|
21
33
|
return this.http.request("POST", ENDPOINT, {
|
|
22
34
|
body: compactParams(params),
|
|
23
35
|
...options
|
|
24
36
|
});
|
|
25
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Fetch the current status of a text-to-image task.
|
|
40
|
+
* @param id The task id.
|
|
41
|
+
* @param options Per-request overrides.
|
|
42
|
+
* @returns The current text-to-image status.
|
|
43
|
+
*/
|
|
26
44
|
async get(id, options) {
|
|
27
45
|
return this.http.request("GET", `${ENDPOINT}/${id}`, {
|
|
28
46
|
...options
|
|
@@ -31,11 +49,12 @@ var TextToImage = class {
|
|
|
31
49
|
};
|
|
32
50
|
|
|
33
51
|
// src/client.ts
|
|
34
|
-
var Gpt4oImageClient = class {
|
|
52
|
+
var Gpt4oImageClient = class extends BaseClient {
|
|
53
|
+
/** Image generation, editing, and inpainting operations. */
|
|
35
54
|
textToImage;
|
|
36
55
|
constructor(options = {}) {
|
|
37
|
-
|
|
38
|
-
this.textToImage = new TextToImage(http);
|
|
56
|
+
super(options);
|
|
57
|
+
this.textToImage = new TextToImage(this.http);
|
|
39
58
|
}
|
|
40
59
|
};
|
|
41
60
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/resources/text-to-image.ts","../src/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/resources/text-to-image.ts","../src/index.ts"],"sourcesContent":["import { BaseClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\n\n/**\n * GPT-4o Image generation and editing API client.\n *\n * Supports pure text-to-image generation, image editing with source images,\n * and inpainting with an optional mask. At least one of `prompt` or\n * `source_image_urls` must be provided.\n *\n * @example\n * ```typescript\n * const client = new Gpt4oImageClient({ apiKey: 'your-api-key' });\n *\n * // Pure generation\n * const result = await client.textToImage.run({\n * model: 'gpt-4o-image',\n * prompt: 'A watercolor painting of a sunset',\n * aspect_ratio: '3:2',\n * });\n *\n * // Edit with source images\n * const edited = await client.textToImage.run({\n * model: 'gpt-4o-image',\n * prompt: 'Add a rainbow',\n * aspect_ratio: '3:2',\n * source_image_urls: ['https://example.com/photo.jpg'],\n * });\n * ```\n */\nexport class Gpt4oImageClient extends BaseClient {\n /** Image generation, editing, and inpainting operations. */\n public readonly textToImage: TextToImage;\n\n constructor(options: ClientOptions = {}) {\n super(options);\n this.textToImage = new TextToImage(this.http);\n }\n}\n","import type { HttpClient, PollingOptions, RequestOptions } from '@runapi.ai/core';\nimport { compactParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport type { TextToImageParams, TextToImageResponse, TaskCreateResponse } from '../types';\n\nconst ENDPOINT = '/api/v1/gpt_4o_image/text_to_image';\n\n/**\n * Generates images from a text prompt, optionally guided by source images and a mask.\n * For pure generation, provide a prompt. For editing, provide source_image_urls\n * (and optionally mask_url) to modify specific regions of the source.\n */\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate an image and wait until complete.\n * @param params Text-to-image parameters.\n * @param options Per-request and polling overrides.\n * @returns The completed text-to-image result.\n */\n async run(params: TextToImageParams, options?: RequestOptions & PollingOptions): Promise<TextToImageResponse> {\n const { id } = await this.create(params, options);\n return pollUntilComplete<TextToImageResponse>(() => this.get(id, options), {\n maxWaitMs: options?.maxWaitMs,\n pollIntervalMs: options?.pollIntervalMs,\n });\n }\n\n /**\n * Create a text-to-image task; returns immediately with a task id.\n * @param params Text-to-image parameters.\n * @param options Per-request overrides.\n * @returns The task creation result with id.\n */\n async create(params: TextToImageParams, options?: RequestOptions): Promise<TaskCreateResponse> {\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body: compactParams(params),\n ...options,\n });\n }\n\n /**\n * Fetch the current status of a text-to-image task.\n * @param id The task id.\n * @param options Per-request overrides.\n * @returns The current text-to-image status.\n */\n async get(id: string, options?: RequestOptions): Promise<TextToImageResponse> {\n return this.http.request<TextToImageResponse>('GET', `${ENDPOINT}/${id}`, {\n ...options,\n });\n }\n}\n","export { Gpt4oImageClient } from './client';\nexport * from './types';\n\n// Re-export core errors for convenience\nexport {\n RunApiError,\n AuthenticationError,\n InsufficientCreditsError,\n NotFoundError,\n ValidationError,\n RateLimitError,\n ServiceUnavailableError,\n NetworkError,\n TimeoutError,\n TaskTimeoutError,\n TaskFailedError,\n} from '@runapi.ai/core';\n"],"mappings":";AAAA,SAAS,kBAAsC;;;ACC/C,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAGlC,IAAM,WAAW;AAOV,IAAM,cAAN,MAAkB;AAAA,EACvB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,MAAM,IAAI,QAA2B,SAAyE;AAC5G,UAAM,EAAE,GAAG,IAAI,MAAM,KAAK,OAAO,QAAQ,OAAO;AAChD,WAAO,kBAAuC,MAAM,KAAK,IAAI,IAAI,OAAO,GAAG;AAAA,MACzE,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,IAC3B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,OAAO,QAA2B,SAAuD;AAC7F,WAAO,KAAK,KAAK,QAA4B,QAAQ,UAAU;AAAA,MAC7D,MAAM,cAAc,MAAM;AAAA,MAC1B,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,IAAI,IAAY,SAAwD;AAC5E,WAAO,KAAK,KAAK,QAA6B,OAAO,GAAG,QAAQ,IAAI,EAAE,IAAI;AAAA,MACxE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;ADvBO,IAAM,mBAAN,cAA+B,WAAW;AAAA;AAAA,EAE/B;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,OAAO;AACb,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAAA,EAC9C;AACF;;;AElCA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runapi.ai/gpt-4o-image",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "RunAPI GPT-4o Image SDK for JavaScript, Ruby, and Go",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"clean": "rm -rf dist"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@runapi.ai/core": "^0.2.
|
|
30
|
+
"@runapi.ai/core": "^0.2.6"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^20.0.0",
|