images.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import { APIResource } from "../resource.js";
  2. import * as Core from "../core.js";
  3. export declare class Images extends APIResource {
  4. /**
  5. * Creates a variation of a given image. This endpoint only supports `dall-e-2`.
  6. *
  7. * @example
  8. * ```ts
  9. * const imagesResponse = await client.images.createVariation({
  10. * image: fs.createReadStream('otter.png'),
  11. * });
  12. * ```
  13. */
  14. createVariation(body: ImageCreateVariationParams, options?: Core.RequestOptions): Core.APIPromise<ImagesResponse>;
  15. /**
  16. * Creates an edited or extended image given one or more source images and a
  17. * prompt. This endpoint only supports `gpt-image-1` and `dall-e-2`.
  18. *
  19. * @example
  20. * ```ts
  21. * const imagesResponse = await client.images.edit({
  22. * image: fs.createReadStream('path/to/file'),
  23. * prompt: 'A cute baby sea otter wearing a beret',
  24. * });
  25. * ```
  26. */
  27. edit(body: ImageEditParams, options?: Core.RequestOptions): Core.APIPromise<ImagesResponse>;
  28. /**
  29. * Creates an image given a prompt.
  30. * [Learn more](https://platform.openai.com/docs/guides/images).
  31. *
  32. * @example
  33. * ```ts
  34. * const imagesResponse = await client.images.generate({
  35. * prompt: 'A cute baby sea otter',
  36. * });
  37. * ```
  38. */
  39. generate(body: ImageGenerateParams, options?: Core.RequestOptions): Core.APIPromise<ImagesResponse>;
  40. }
  41. /**
  42. * Represents the content or the URL of an image generated by the OpenAI API.
  43. */
  44. export interface Image {
  45. /**
  46. * The base64-encoded JSON of the generated image. Default value for `gpt-image-1`,
  47. * and only present if `response_format` is set to `b64_json` for `dall-e-2` and
  48. * `dall-e-3`.
  49. */
  50. b64_json?: string;
  51. /**
  52. * For `dall-e-3` only, the revised prompt that was used to generate the image.
  53. */
  54. revised_prompt?: string;
  55. /**
  56. * When using `dall-e-2` or `dall-e-3`, the URL of the generated image if
  57. * `response_format` is set to `url` (default value). Unsupported for
  58. * `gpt-image-1`.
  59. */
  60. url?: string;
  61. }
  62. export type ImageModel = 'dall-e-2' | 'dall-e-3' | 'gpt-image-1';
  63. /**
  64. * The response from the image generation endpoint.
  65. */
  66. export interface ImagesResponse {
  67. /**
  68. * The Unix timestamp (in seconds) of when the image was created.
  69. */
  70. created: number;
  71. /**
  72. * The list of generated images.
  73. */
  74. data?: Array<Image>;
  75. /**
  76. * For `gpt-image-1` only, the token usage information for the image generation.
  77. */
  78. usage?: ImagesResponse.Usage;
  79. }
  80. export declare namespace ImagesResponse {
  81. /**
  82. * For `gpt-image-1` only, the token usage information for the image generation.
  83. */
  84. interface Usage {
  85. /**
  86. * The number of tokens (images and text) in the input prompt.
  87. */
  88. input_tokens: number;
  89. /**
  90. * The input tokens detailed information for the image generation.
  91. */
  92. input_tokens_details: Usage.InputTokensDetails;
  93. /**
  94. * The number of image tokens in the output image.
  95. */
  96. output_tokens: number;
  97. /**
  98. * The total number of tokens (images and text) used for the image generation.
  99. */
  100. total_tokens: number;
  101. }
  102. namespace Usage {
  103. /**
  104. * The input tokens detailed information for the image generation.
  105. */
  106. interface InputTokensDetails {
  107. /**
  108. * The number of image tokens in the input prompt.
  109. */
  110. image_tokens: number;
  111. /**
  112. * The number of text tokens in the input prompt.
  113. */
  114. text_tokens: number;
  115. }
  116. }
  117. }
  118. export interface ImageCreateVariationParams {
  119. /**
  120. * The image to use as the basis for the variation(s). Must be a valid PNG file,
  121. * less than 4MB, and square.
  122. */
  123. image: Core.Uploadable;
  124. /**
  125. * The model to use for image generation. Only `dall-e-2` is supported at this
  126. * time.
  127. */
  128. model?: (string & {}) | ImageModel | null;
  129. /**
  130. * The number of images to generate. Must be between 1 and 10.
  131. */
  132. n?: number | null;
  133. /**
  134. * The format in which the generated images are returned. Must be one of `url` or
  135. * `b64_json`. URLs are only valid for 60 minutes after the image has been
  136. * generated.
  137. */
  138. response_format?: 'url' | 'b64_json' | null;
  139. /**
  140. * The size of the generated images. Must be one of `256x256`, `512x512`, or
  141. * `1024x1024`.
  142. */
  143. size?: '256x256' | '512x512' | '1024x1024' | null;
  144. /**
  145. * A unique identifier representing your end-user, which can help OpenAI to monitor
  146. * and detect abuse.
  147. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
  148. */
  149. user?: string;
  150. }
  151. export interface ImageEditParams {
  152. /**
  153. * The image(s) to edit. Must be a supported image file or an array of images.
  154. *
  155. * For `gpt-image-1`, each image should be a `png`, `webp`, or `jpg` file less than
  156. * 25MB. You can provide up to 16 images.
  157. *
  158. * For `dall-e-2`, you can only provide one image, and it should be a square `png`
  159. * file less than 4MB.
  160. */
  161. image: Core.Uploadable | Array<Core.Uploadable>;
  162. /**
  163. * A text description of the desired image(s). The maximum length is 1000
  164. * characters for `dall-e-2`, and 32000 characters for `gpt-image-1`.
  165. */
  166. prompt: string;
  167. /**
  168. * Allows to set transparency for the background of the generated image(s). This
  169. * parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
  170. * `opaque` or `auto` (default value). When `auto` is used, the model will
  171. * automatically determine the best background for the image.
  172. *
  173. * If `transparent`, the output format needs to support transparency, so it should
  174. * be set to either `png` (default value) or `webp`.
  175. */
  176. background?: 'transparent' | 'opaque' | 'auto' | null;
  177. /**
  178. * An additional image whose fully transparent areas (e.g. where alpha is zero)
  179. * indicate where `image` should be edited. If there are multiple images provided,
  180. * the mask will be applied on the first image. Must be a valid PNG file, less than
  181. * 4MB, and have the same dimensions as `image`.
  182. */
  183. mask?: Core.Uploadable;
  184. /**
  185. * The model to use for image generation. Only `dall-e-2` and `gpt-image-1` are
  186. * supported. Defaults to `dall-e-2` unless a parameter specific to `gpt-image-1`
  187. * is used.
  188. */
  189. model?: (string & {}) | ImageModel | null;
  190. /**
  191. * The number of images to generate. Must be between 1 and 10.
  192. */
  193. n?: number | null;
  194. /**
  195. * The quality of the image that will be generated. `high`, `medium` and `low` are
  196. * only supported for `gpt-image-1`. `dall-e-2` only supports `standard` quality.
  197. * Defaults to `auto`.
  198. */
  199. quality?: 'standard' | 'low' | 'medium' | 'high' | 'auto' | null;
  200. /**
  201. * The format in which the generated images are returned. Must be one of `url` or
  202. * `b64_json`. URLs are only valid for 60 minutes after the image has been
  203. * generated. This parameter is only supported for `dall-e-2`, as `gpt-image-1`
  204. * will always return base64-encoded images.
  205. */
  206. response_format?: 'url' | 'b64_json' | null;
  207. /**
  208. * The size of the generated images. Must be one of `1024x1024`, `1536x1024`
  209. * (landscape), `1024x1536` (portrait), or `auto` (default value) for
  210. * `gpt-image-1`, and one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`.
  211. */
  212. size?: '256x256' | '512x512' | '1024x1024' | '1536x1024' | '1024x1536' | 'auto' | null;
  213. /**
  214. * A unique identifier representing your end-user, which can help OpenAI to monitor
  215. * and detect abuse.
  216. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
  217. */
  218. user?: string;
  219. }
  220. export interface ImageGenerateParams {
  221. /**
  222. * A text description of the desired image(s). The maximum length is 32000
  223. * characters for `gpt-image-1`, 1000 characters for `dall-e-2` and 4000 characters
  224. * for `dall-e-3`.
  225. */
  226. prompt: string;
  227. /**
  228. * Allows to set transparency for the background of the generated image(s). This
  229. * parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
  230. * `opaque` or `auto` (default value). When `auto` is used, the model will
  231. * automatically determine the best background for the image.
  232. *
  233. * If `transparent`, the output format needs to support transparency, so it should
  234. * be set to either `png` (default value) or `webp`.
  235. */
  236. background?: 'transparent' | 'opaque' | 'auto' | null;
  237. /**
  238. * The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or
  239. * `gpt-image-1`. Defaults to `dall-e-2` unless a parameter specific to
  240. * `gpt-image-1` is used.
  241. */
  242. model?: (string & {}) | ImageModel | null;
  243. /**
  244. * Control the content-moderation level for images generated by `gpt-image-1`. Must
  245. * be either `low` for less restrictive filtering or `auto` (default value).
  246. */
  247. moderation?: 'low' | 'auto' | null;
  248. /**
  249. * The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only
  250. * `n=1` is supported.
  251. */
  252. n?: number | null;
  253. /**
  254. * The compression level (0-100%) for the generated images. This parameter is only
  255. * supported for `gpt-image-1` with the `webp` or `jpeg` output formats, and
  256. * defaults to 100.
  257. */
  258. output_compression?: number | null;
  259. /**
  260. * The format in which the generated images are returned. This parameter is only
  261. * supported for `gpt-image-1`. Must be one of `png`, `jpeg`, or `webp`.
  262. */
  263. output_format?: 'png' | 'jpeg' | 'webp' | null;
  264. /**
  265. * The quality of the image that will be generated.
  266. *
  267. * - `auto` (default value) will automatically select the best quality for the
  268. * given model.
  269. * - `high`, `medium` and `low` are supported for `gpt-image-1`.
  270. * - `hd` and `standard` are supported for `dall-e-3`.
  271. * - `standard` is the only option for `dall-e-2`.
  272. */
  273. quality?: 'standard' | 'hd' | 'low' | 'medium' | 'high' | 'auto' | null;
  274. /**
  275. * The format in which generated images with `dall-e-2` and `dall-e-3` are
  276. * returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes
  277. * after the image has been generated. This parameter isn't supported for
  278. * `gpt-image-1` which will always return base64-encoded images.
  279. */
  280. response_format?: 'url' | 'b64_json' | null;
  281. /**
  282. * The size of the generated images. Must be one of `1024x1024`, `1536x1024`
  283. * (landscape), `1024x1536` (portrait), or `auto` (default value) for
  284. * `gpt-image-1`, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and
  285. * one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.
  286. */
  287. size?: 'auto' | '1024x1024' | '1536x1024' | '1024x1536' | '256x256' | '512x512' | '1792x1024' | '1024x1792' | null;
  288. /**
  289. * The style of the generated images. This parameter is only supported for
  290. * `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean
  291. * towards generating hyper-real and dramatic images. Natural causes the model to
  292. * produce more natural, less hyper-real looking images.
  293. */
  294. style?: 'vivid' | 'natural' | null;
  295. /**
  296. * A unique identifier representing your end-user, which can help OpenAI to monitor
  297. * and detect abuse.
  298. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
  299. */
  300. user?: string;
  301. }
  302. export declare namespace Images {
  303. export { type Image as Image, type ImageModel as ImageModel, type ImagesResponse as ImagesResponse, type ImageCreateVariationParams as ImageCreateVariationParams, type ImageEditParams as ImageEditParams, type ImageGenerateParams as ImageGenerateParams, };
  304. }
  305. //# sourceMappingURL=images.d.ts.map