@runapi.ai/gpt-4o-image 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,32 +1,34 @@
1
- # GPT-4o Image API JavaScript SDK for RunAPI
1
+ # GPT-4o Image JavaScript SDK for RunAPI
2
2
 
3
- The gpt-4o image api JavaScript SDK is the language-specific package for GPT-4o Image on RunAPI. Use this gpt-4o image api package for text-to-image, image editing, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in JavaScript.
3
+ The GPT-4o Image JavaScript SDK is the language-specific package for GPT-4o Image on RunAPI. Use this package for image generation, image editing, and creative production workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in JavaScript.
4
4
 
5
- This gpt-4o image api README is the JavaScript package guide inside the public `gpt4o-image-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/gpt-4o-image; for API reference, use https://runapi.ai/docs#gpt-4o-image; for SDK docs, use https://runapi.ai/docs#sdk-gpt-4o-image.
5
+ This README is the JavaScript package guide inside the public `gpt-4o-image-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/gpt-4o-image; for API reference, use https://runapi.ai/docs#gpt-4o-image; for SDK docs, use https://runapi.ai/docs#sdk-gpt-4o-image.
6
6
 
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- npm install @runapi.ai/gpt4o-image
10
+ npm install @runapi.ai/gpt-4o-image
11
11
  ```
12
12
 
13
13
  ## Quick start
14
14
 
15
15
  ```typescript
16
- import { Gpt4oImageClient } from '@runapi.ai/gpt4o-image';
16
+ import { Gpt4oImageClient } from '@runapi.ai/gpt-4o-image';
17
17
 
18
18
  const client = new Gpt4oImageClient();
19
- const task = await client.generations.create({
19
+ const task = await client.textToImage.create({
20
20
  // Pass the GPT-4o Image JSON request body from https://runapi.ai/docs#gpt-4o-image.
21
21
  });
22
- const status = await client.generations.get(task.id);
22
+ const status = await client.textToImage.get(task.id);
23
23
  ```
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
- 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.
31
+ Use the TypeScript types in `src/types.ts` and the resource classes under `src/resources` when building image applications. The available resources are `textToImage`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
30
32
 
31
33
  ## Links
32
34
 
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 text-to-image API client.
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://cdn.runapi.ai/public/samples/image.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 text-to-image API client.
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://cdn.runapi.ai/public/samples/image.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
@@ -41,12 +41,49 @@ var import_core2 = require("@runapi.ai/core");
41
41
  // src/resources/text-to-image.ts
42
42
  var import_core = require("@runapi.ai/core");
43
43
  var import_internal = require("@runapi.ai/core/internal");
44
+
45
+ // src/contract_gen.ts
46
+ var contract = {
47
+ "text-to-image": {
48
+ "models": [
49
+ "gpt-4o-image"
50
+ ],
51
+ "fields_by_model": {
52
+ "gpt-4o-image": {
53
+ "aspect_ratio": {
54
+ "enum": [
55
+ "1:1",
56
+ "3:2",
57
+ "2:3"
58
+ ],
59
+ "required": true
60
+ },
61
+ "output_count": {
62
+ "enum": [
63
+ 1,
64
+ 2,
65
+ 4
66
+ ],
67
+ "type": "integer"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ };
73
+
74
+ // src/resources/text-to-image.ts
44
75
  var ENDPOINT = "/api/v1/gpt_4o_image/text_to_image";
45
76
  var TextToImage = class {
46
77
  constructor(http) {
47
78
  this.http = http;
48
79
  }
49
80
  http;
81
+ /**
82
+ * Generate an image and wait until complete.
83
+ * @param params Text-to-image parameters.
84
+ * @param options Per-request and polling overrides.
85
+ * @returns The completed text-to-image result.
86
+ */
50
87
  async run(params, options) {
51
88
  const { id } = await this.create(params, options);
52
89
  return (0, import_internal.pollUntilComplete)(() => this.get(id, options), {
@@ -54,12 +91,26 @@ var TextToImage = class {
54
91
  pollIntervalMs: options?.pollIntervalMs
55
92
  });
56
93
  }
94
+ /**
95
+ * Create a text-to-image task; returns immediately with a task id.
96
+ * @param params Text-to-image parameters.
97
+ * @param options Per-request overrides.
98
+ * @returns The task creation result with id.
99
+ */
57
100
  async create(params, options) {
101
+ const body = (0, import_core.compactParams)(params);
102
+ (0, import_core.validateParams)(contract["text-to-image"], body);
58
103
  return this.http.request("POST", ENDPOINT, {
59
- body: (0, import_core.compactParams)(params),
104
+ body,
60
105
  ...options
61
106
  });
62
107
  }
108
+ /**
109
+ * Fetch the current status of a text-to-image task.
110
+ * @param id The task id.
111
+ * @param options Per-request overrides.
112
+ * @returns The current text-to-image status.
113
+ */
63
114
  async get(id, options) {
64
115
  return this.http.request("GET", `${ENDPOINT}/${id}`, {
65
116
  ...options
@@ -68,11 +119,12 @@ var TextToImage = class {
68
119
  };
69
120
 
70
121
  // src/client.ts
71
- var Gpt4oImageClient = class {
122
+ var Gpt4oImageClient = class extends import_core2.BaseClient {
123
+ /** Image generation, editing, and inpainting operations. */
72
124
  textToImage;
73
125
  constructor(options = {}) {
74
- const http = (0, import_core2.createHttpClient)(options);
75
- this.textToImage = new TextToImage(http);
126
+ super(options);
127
+ this.textToImage = new TextToImage(this.http);
76
128
  }
77
129
  };
78
130
 
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 { createHttpClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\n\n/**\n * GPT-4o Image text-to-image API client.\n */\nexport class Gpt4oImageClient {\n public readonly textToImage: TextToImage;\n\n constructor(options: ClientOptions = {}) {\n const http = createHttpClient(options);\n this.textToImage = new TextToImage(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\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\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 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 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,eAAqD;;;ACCrD,kBAA8B;AAC9B,sBAAkC;AAGlC,IAAM,WAAW;AAEV,IAAM,cAAN,MAAkB;AAAA,EACvB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA,EAE7B,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,EAEA,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,EAEA,MAAM,IAAI,IAAY,SAAwD;AAC5E,WAAO,KAAK,KAAK,QAA6B,OAAO,GAAG,QAAQ,IAAI,EAAE,IAAI;AAAA,MACxE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;ADxBO,IAAM,mBAAN,MAAuB;AAAA,EACZ;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,WAAO,+BAAiB,OAAO;AACrC,SAAK,cAAc,IAAI,YAAY,IAAI;AAAA,EACzC;AACF;;;ADTA,IAAAC,eAYO;","names":["import_core","import_core"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/resources/text-to-image.ts","../src/contract_gen.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://cdn.runapi.ai/public/samples/image.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, ActionSchema } from '@runapi.ai/core';\nimport { compactParams, validateParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport { contract } from '../contract_gen';\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 const body = compactParams(params);\n validateParams(contract['text-to-image'] as ActionSchema, body as Record<string, unknown>);\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body,\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 const contract = {\n \"text-to-image\": {\n \"models\": [\n \"gpt-4o-image\"\n ],\n \"fields_by_model\": {\n \"gpt-4o-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"3:2\",\n \"2:3\"\n ],\n \"required\": true\n },\n \"output_count\": {\n \"enum\": [\n 1,\n 2,\n 4\n ],\n \"type\": \"integer\"\n }\n }\n }\n }\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAA+C;;;ACC/C,kBAA8C;AAC9C,sBAAkC;;;ACF3B,IAAM,WAAW;AAAA,EACtB,iBAAiB;AAAA,IACf,UAAU;AAAA,MACR;AAAA,IACF;AAAA,IACA,mBAAmB;AAAA,MACjB,gBAAgB;AAAA,QACd,gBAAgB;AAAA,UACd,QAAQ;AAAA,YACN;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UACA,YAAY;AAAA,QACd;AA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client.ts
2
- import { createHttpClient } from "@runapi.ai/core";
2
+ import { BaseClient } from "@runapi.ai/core";
3
3
 
4
4
  // src/resources/text-to-image.ts
5
- import { compactParams } from "@runapi.ai/core";
5
+ import { compactParams, validateParams } from "@runapi.ai/core";
6
6
  import { pollUntilComplete } from "@runapi.ai/core/internal";
7
+
8
+ // src/contract_gen.ts
9
+ var contract = {
10
+ "text-to-image": {
11
+ "models": [
12
+ "gpt-4o-image"
13
+ ],
14
+ "fields_by_model": {
15
+ "gpt-4o-image": {
16
+ "aspect_ratio": {
17
+ "enum": [
18
+ "1:1",
19
+ "3:2",
20
+ "2:3"
21
+ ],
22
+ "required": true
23
+ },
24
+ "output_count": {
25
+ "enum": [
26
+ 1,
27
+ 2,
28
+ 4
29
+ ],
30
+ "type": "integer"
31
+ }
32
+ }
33
+ }
34
+ }
35
+ };
36
+
37
+ // src/resources/text-to-image.ts
7
38
  var ENDPOINT = "/api/v1/gpt_4o_image/text_to_image";
8
39
  var TextToImage = class {
9
40
  constructor(http) {
10
41
  this.http = http;
11
42
  }
12
43
  http;
44
+ /**
45
+ * Generate an image and wait until complete.
46
+ * @param params Text-to-image parameters.
47
+ * @param options Per-request and polling overrides.
48
+ * @returns The completed text-to-image result.
49
+ */
13
50
  async run(params, options) {
14
51
  const { id } = await this.create(params, options);
15
52
  return pollUntilComplete(() => this.get(id, options), {
@@ -17,12 +54,26 @@ var TextToImage = class {
17
54
  pollIntervalMs: options?.pollIntervalMs
18
55
  });
19
56
  }
57
+ /**
58
+ * Create a text-to-image task; returns immediately with a task id.
59
+ * @param params Text-to-image parameters.
60
+ * @param options Per-request overrides.
61
+ * @returns The task creation result with id.
62
+ */
20
63
  async create(params, options) {
64
+ const body = compactParams(params);
65
+ validateParams(contract["text-to-image"], body);
21
66
  return this.http.request("POST", ENDPOINT, {
22
- body: compactParams(params),
67
+ body,
23
68
  ...options
24
69
  });
25
70
  }
71
+ /**
72
+ * Fetch the current status of a text-to-image task.
73
+ * @param id The task id.
74
+ * @param options Per-request overrides.
75
+ * @returns The current text-to-image status.
76
+ */
26
77
  async get(id, options) {
27
78
  return this.http.request("GET", `${ENDPOINT}/${id}`, {
28
79
  ...options
@@ -31,11 +82,12 @@ var TextToImage = class {
31
82
  };
32
83
 
33
84
  // src/client.ts
34
- var Gpt4oImageClient = class {
85
+ var Gpt4oImageClient = class extends BaseClient {
86
+ /** Image generation, editing, and inpainting operations. */
35
87
  textToImage;
36
88
  constructor(options = {}) {
37
- const http = createHttpClient(options);
38
- this.textToImage = new TextToImage(http);
89
+ super(options);
90
+ this.textToImage = new TextToImage(this.http);
39
91
  }
40
92
  };
41
93
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/resources/text-to-image.ts","../src/index.ts"],"sourcesContent":["import { createHttpClient, type ClientOptions } from '@runapi.ai/core';\nimport { TextToImage } from './resources/text-to-image';\n\n/**\n * GPT-4o Image text-to-image API client.\n */\nexport class Gpt4oImageClient {\n public readonly textToImage: TextToImage;\n\n constructor(options: ClientOptions = {}) {\n const http = createHttpClient(options);\n this.textToImage = new TextToImage(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\nexport class TextToImage {\n constructor(private readonly http: HttpClient) {}\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 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 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,wBAA4C;;;ACCrD,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAGlC,IAAM,WAAW;AAEV,IAAM,cAAN,MAAkB;AAAA,EACvB,YAA6B,MAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA,EAE7B,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,EAEA,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,EAEA,MAAM,IAAI,IAAY,SAAwD;AAC5E,WAAO,KAAK,KAAK,QAA6B,OAAO,GAAG,QAAQ,IAAI,EAAE,IAAI;AAAA,MACxE,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;;;ADxBO,IAAM,mBAAN,MAAuB;AAAA,EACZ;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,OAAO,iBAAiB,OAAO;AACrC,SAAK,cAAc,IAAI,YAAY,IAAI;AAAA,EACzC;AACF;;;AETA;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":[]}
1
+ {"version":3,"sources":["../src/client.ts","../src/resources/text-to-image.ts","../src/contract_gen.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://cdn.runapi.ai/public/samples/image.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, ActionSchema } from '@runapi.ai/core';\nimport { compactParams, validateParams } from '@runapi.ai/core';\nimport { pollUntilComplete } from '@runapi.ai/core/internal';\nimport { contract } from '../contract_gen';\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 const body = compactParams(params);\n validateParams(contract['text-to-image'] as ActionSchema, body as Record<string, unknown>);\n return this.http.request<TaskCreateResponse>('POST', ENDPOINT, {\n body,\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 const contract = {\n \"text-to-image\": {\n \"models\": [\n \"gpt-4o-image\"\n ],\n \"fields_by_model\": {\n \"gpt-4o-image\": {\n \"aspect_ratio\": {\n \"enum\": [\n \"1:1\",\n \"3:2\",\n \"2:3\"\n ],\n \"required\": true\n },\n \"output_count\": {\n \"enum\": [\n 1,\n 2,\n 4\n ],\n \"type\": \"integer\"\n }\n }\n }\n }\n} as const;\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,eAAe,sBAAsB;AAC9C,SAAS,yBAAyB;;;ACF3B,IAAM,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,EAE/B;AAAA,EAEhB,YAAY,UAAyB,CAAC,GAAG;AACvC,UAAM,OAAO;AACb,SAAK,cAAc,IAAI,YAAY,KAAK,IAAI;AAAA,EAC9C;AACF;;;AGlCA;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,7 +1,10 @@
1
1
  {
2
2
  "name": "@runapi.ai/gpt-4o-image",
3
- "version": "0.2.5",
4
- "description": "RunAPI GPT-4o Image SDK for JavaScript, Ruby, and Go",
3
+ "runapi": {
4
+ "slug": "gpt-4o-image"
5
+ },
6
+ "version": "0.2.7",
7
+ "description": "RunAPI GPT-4o Image SDK for text-to-image generation workflows in JavaScript, Python, Ruby, Go, and Java",
5
8
  "main": "./dist/index.js",
6
9
  "module": "./dist/index.mjs",
7
10
  "types": "./dist/index.d.ts",
@@ -27,7 +30,7 @@
27
30
  "clean": "rm -rf dist"
28
31
  },
29
32
  "dependencies": {
30
- "@runapi.ai/core": "^0.2.5"
33
+ "@runapi.ai/core": "^0.2.7"
31
34
  },
32
35
  "devDependencies": {
33
36
  "@types/node": "^20.0.0",
@@ -46,8 +49,16 @@
46
49
  "api",
47
50
  "sdk",
48
51
  "typescript",
52
+ "python",
49
53
  "ruby",
50
- "golang"
54
+ "golang",
55
+ "java",
56
+ "maven",
57
+ "gradle",
58
+ "image-generation",
59
+ "text-to-image",
60
+ "image-api",
61
+ "gpt-4o-image-api"
51
62
  ],
52
63
  "author": "RunAPI",
53
64
  "license": "Apache-2.0",
@@ -55,5 +66,8 @@
55
66
  "repository": {
56
67
  "type": "git",
57
68
  "url": "git+https://github.com/runapi-ai/gpt-4o-image-sdk.git"
69
+ },
70
+ "bugs": {
71
+ "url": "https://github.com/runapi-ai/gpt-4o-image-sdk/issues"
58
72
  }
59
73
  }