images
Create image
Section titled “Create image”Generate images from text prompts
Request
Section titled “Request”POST /images/generationsRequest Body
Section titled “Request Body”| Field | Type | Required | Description |
|---|---|---|---|
| prompt | string | Yes | A text description of the desired image(s). - Maximum length is 32000 characters for the GPT image models - Maximum length is 1000 characters for dall-e-2 - Maximum length is 4000 characters for dall-e-3 |
| background | object | No | Allows to set transparency for the background of the generated image(s). This parameter is only supported for the GPT image models. Must be one of transparent, opaque or auto (default value). When auto is used, the model will automatically determine the best background for the image. If transparent, the output format needs to support transparency, so it should be set to either png (default value) or webp. |
| model | string | No | The model to use for image generation. One of dall-e-2, dall-e-3, or a GPT image model (gpt-image-1, gpt-image-1-mini, gpt-image-1.5). Defaults to dall-e-2 unless a parameter specific to the GPT image models is used. |
| moderation | object | No | Control the content-moderation level for images generated by the GPT image models. Must be either low for less restrictive filtering or auto (default value). |
| n | object | No | The number of images to generate. Must be between 1 and 10. For dall-e-3, only n=1 is supported. |
| output_compression | object | No | The compression level (0-100%) for the generated images. This parameter is only supported for the GPT image models with the webp or jpeg output formats, and defaults to 100. |
| output_format | object | No | The format in which the generated images are returned. This parameter is only supported for the GPT image models. Must be one of png, jpeg, or webp. |
| partial_images | integer | No | The number of partial images to generate. This parameter is used for streaming responses that return partial images. Value must be between 0 and 3. When set to 0, the response will be a single image sent in one streaming event. Note that the final image may be sent before the full number of partial images are generated if the full image is generated more quickly. |
| quality | object | No | The quality of the image that will be generated. - auto (default value) will automatically select the best quality for the given model. - high, medium and low are supported for the GPT image models. - hd and standard are supported for dall-e-3. - standard is the only option for dall-e-2. |
| response_format | object | No | The format in which generated images with dall-e-2 and dall-e-3 are returned. Must be one of url or b64_json. URLs are only valid for 60 minutes after the image has been generated. This parameter isn’t supported for the GPT image models, which always return base64-encoded images. |
| size | object | No | The size of the generated images. Must be one of 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or auto (default value) for the GPT image models, one of 256x256, 512x512, or 1024x1024 for dall-e-2, and one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3. |
| stream | object | No | Generate the image in streaming mode. Defaults to false. See the Image generation guide for more information. This parameter is only supported for the GPT image models. |
| style | object | No | The style of the generated images. This parameter is only supported for dall-e-3. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. |
| user | string | No | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
Request Examples
Section titled “Request Examples”Simple image generation
Section titled “Simple image generation”{ "model": "gpt-4o-mini", "prompt": "A cute cat sitting on a windowsill", "n": 1, "size": "1024x1024"}Image generation with detailed parameters
Section titled “Image generation with detailed parameters”{ "model": "gpt-4o-mini", "prompt": "A futuristic city with flying cars at sunset", "n": 1, "quality": "hd", "size": "1792x1024", "style": "vivid"}Base64 output
Section titled “Base64 output”{ "model": "gpt-4o-mini", "prompt": "Minimalist logo of a cloud with a lightning bolt", "n": 1, "response_format": "b64_json", "size": "512x512"}Successful response
Response Schema
Section titled “Response Schema”| Field | Type | Required | Description |
|---|---|---|---|
| created | integer | Yes | - |
| data | Array<ImageObject> | Yes | - |
| usage | object | No | Usage information for image generation (provider-dependent) |
Response Example
Section titled “Response Example”{ "created": 1677652288, "data": [ { "url": "https://example.com/image.png", "revised_prompt": "A cute orange tabby cat sitting on a white windowsill, looking outside" } ]}Code Examples
Section titled “Code Examples”JavaScript (Fetch)
Section titled “JavaScript (Fetch)”const response = await fetch('https://api.r9s.ai/v1/images/generations', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ "model": "gpt-4o-mini", "prompt": "A cute cat sitting on a windowsill", "n": 1, "size": "1024x1024"})});
const data = await response.json();console.log(data);Python (requests)
Section titled “Python (requests)”import requests
url = "https://api.r9s.ai/v1/images/generations"headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}
response = requests.post(url, json={ "model": "gpt-4o-mini", "prompt": "A cute cat sitting on a windowsill", "n": 1, "size": "1024x1024"}, headers=headers)data = response.json()print(data)curl -X POST "https://api.r9s.ai/v1/images/generations" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o-mini","prompt":"A cute cat sitting on a windowsill","n":1,"size":"1024x1024"}'Edit image
Section titled “Edit image”Create an edited or extended image given an original and prompt
Request
Section titled “Request”POST /images/editsRequest Body
Section titled “Request Body”| Field | Type | Required | Description |
|---|---|---|---|
| image | string | Yes | The image(s) to edit. Must be a supported image file or an array of images. For the GPT image models (gpt-image-1, gpt-image-1-mini, and gpt-image-1.5): - Each image should be a png, webp, or jpg file less than 50MB - You can provide up to 16 images For dall-e-2: - You can only provide one image - It should be a square png file less than 4MB |
| prompt | string | Yes | A text description of the desired image(s). - Maximum length is 32000 characters for GPT image models - Maximum length is 1000 characters for dall-e-2 - Maximum length is 4000 characters for dall-e-3 |
| mask | string | No | An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. If there are multiple images provided, the mask will be applied on the first image. Must be a valid PNG file, less than 4MB, and have the same dimensions as image. |
| background | object | No | Allows to set transparency for the background of the generated image(s). This parameter is only supported for the GPT image models. Must be one of transparent, opaque or auto (default value). When auto is used, the model will automatically determine the best background for the image. If transparent, the output format needs to support transparency, so it should be set to either png (default value) or webp. |
| input_fidelity | string (high, low) | No | Control how much effort the model will exert to match the style and features, especially facial features, of input images. This parameter is only supported for gpt-image-1. Unsupported for gpt-image-1-mini. Supports high and low. Defaults to low. |
| model | string | No | The model to use for image generation. One of dall-e-2, dall-e-3, or a GPT image model (gpt-image-1, gpt-image-1-mini, gpt-image-1.5). Defaults to dall-e-2 unless a parameter specific to the GPT image models is used. |
| moderation | object | No | Control the content-moderation level for images generated by the GPT image models. Must be either low for less restrictive filtering or auto (default value). |
| n | object | No | The number of images to generate. Must be between 1 and 10. For dall-e-3, only n=1 is supported. |
| output_compression | object | No | The compression level (0-100%) for the generated images. This parameter is only supported for the GPT image models with the webp or jpeg output formats, and defaults to 100. |
| output_format | object | No | The format in which the generated images are returned. This parameter is only supported for the GPT image models. Must be one of png, jpeg, or webp. |
| partial_images | integer | No | The number of partial images to generate. This parameter is used for streaming responses that return partial images. Value must be between 0 and 3. When set to 0, the response will be a single image sent in one streaming event. Note that the final image may be sent before the full number of partial images are generated if the full image is generated more quickly. |
| quality | object | No | The quality of the image that will be generated. - auto (default value) will automatically select the best quality for the given model. - high, medium and low are supported for the GPT image models. - hd and standard are supported for dall-e-3. - standard is the only option for dall-e-2. |
| response_format | object | No | The format in which generated images with dall-e-2 and dall-e-3 are returned. Must be one of url or b64_json. URLs are only valid for 60 minutes after the image has been generated. This parameter isn’t supported for the GPT image models, which always return base64-encoded images. |
| size | object | No | The size of the generated images. Must be one of 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or auto (default value) for the GPT image models, one of 256x256, 512x512, or 1024x1024 for dall-e-2, and one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3. |
| stream | object | No | Generate the image in streaming mode. Defaults to false. See the Image generation guide for more information. This parameter is only supported for the GPT image models. |
| style | object | No | The style of the generated images. This parameter is only supported for dall-e-3. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. |
| user | string | No | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
Request Examples
Section titled “Request Examples”Simple edit with dall-e-2
Section titled “Simple edit with dall-e-2”{ "image": "data:image/png;base64,<BASE64_IMAGE>", "prompt": "Add a red bow tie to the cat", "model": "dall-e-2", "n": 1, "size": "1024x1024", "response_format": "url"}Edit using a mask (dall-e-2)
Section titled “Edit using a mask (dall-e-2)”{ "image": "data:image/png;base64,<BASE64_IMAGE>", "mask": "data:image/png;base64,<BASE64_MASK>", "prompt": "Replace the sky with a sunset", "model": "dall-e-2", "size": "512x512"}Edit with GPT image model
Section titled “Edit with GPT image model”{ "image": "data:image/png;base64,<BASE64_IMAGE>", "prompt": "Make the background transparent and add autumn colors", "model": "gpt-image-1", "background": "transparent", "output_format": "png", "quality": "high", "input_fidelity": "high", "n": 2}Streaming edit with GPT image model
Section titled “Streaming edit with GPT image model”{ "image": "data:image/png;base64,<BASE64_IMAGE>", "prompt": "Convert to watercolor painting style", "model": "gpt-image-1.5", "stream": true, "partial_images": 2, "output_format": "webp", "output_compression": 85}Edit multiple images (GPT image models)
Section titled “Edit multiple images (GPT image models)”{ "image": [ "data:image/png;base64,<BASE64_IMAGE1>", "data:image/png;base64,<BASE64_IMAGE2>" ], "prompt": "Apply vintage filter to all images", "model": "gpt-image-1", "n": 1, "size": "1536x1024"}Successful response
Response Schema
Section titled “Response Schema”| Field | Type | Required | Description |
|---|---|---|---|
| created | integer | Yes | - |
| data | Array<ImageObject> | Yes | - |
| usage | object | No | Usage information for image generation (provider-dependent) |
Response Example
Section titled “Response Example”{ "created": 1677652288, "data": [ { "url": "https://example.com/edited-image.png" } ]}Code Examples
Section titled “Code Examples”JavaScript (Fetch)
Section titled “JavaScript (Fetch)”const response = await fetch('https://api.r9s.ai/v1/images/edits', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({})});
const data = await response.json();console.log(data);Python (requests)
Section titled “Python (requests)”import requests
url = "https://api.r9s.ai/v1/images/edits"headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"}
response = requests.post(url, json={}, headers=headers)data = response.json()print(data)curl -X POST "https://api.r9s.ai/v1/images/edits" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{}'Schema Reference
Section titled “Schema Reference”ImageGenerationRequest
Section titled “ImageGenerationRequest”| Field | Type | Required | Description |
|---|---|---|---|
| prompt | string | Yes | A text description of the desired image(s). - Maximum length is 32000 characters for the GPT image models - Maximum length is 1000 characters for dall-e-2 - Maximum length is 4000 characters for dall-e-3 |
| background | object | No | Allows to set transparency for the background of the generated image(s). This parameter is only supported for the GPT image models. Must be one of transparent, opaque or auto (default value). When auto is used, the model will automatically determine the best background for the image. If transparent, the output format needs to support transparency, so it should be set to either png (default value) or webp. |
| model | string | No | The model to use for image generation. One of dall-e-2, dall-e-3, or a GPT image model (gpt-image-1, gpt-image-1-mini, gpt-image-1.5). Defaults to dall-e-2 unless a parameter specific to the GPT image models is used. |
| moderation | object | No | Control the content-moderation level for images generated by the GPT image models. Must be either low for less restrictive filtering or auto (default value). |
| n | object | No | The number of images to generate. Must be between 1 and 10. For dall-e-3, only n=1 is supported. |
| output_compression | object | No | The compression level (0-100%) for the generated images. This parameter is only supported for the GPT image models with the webp or jpeg output formats, and defaults to 100. |
| output_format | object | No | The format in which the generated images are returned. This parameter is only supported for the GPT image models. Must be one of png, jpeg, or webp. |
| partial_images | integer | No | The number of partial images to generate. This parameter is used for streaming responses that return partial images. Value must be between 0 and 3. When set to 0, the response will be a single image sent in one streaming event. Note that the final image may be sent before the full number of partial images are generated if the full image is generated more quickly. |
| quality | object | No | The quality of the image that will be generated. - auto (default value) will automatically select the best quality for the given model. - high, medium and low are supported for the GPT image models. - hd and standard are supported for dall-e-3. - standard is the only option for dall-e-2. |
| response_format | object | No | The format in which generated images with dall-e-2 and dall-e-3 are returned. Must be one of url or b64_json. URLs are only valid for 60 minutes after the image has been generated. This parameter isn’t supported for the GPT image models, which always return base64-encoded images. |
| size | object | No | The size of the generated images. Must be one of 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or auto (default value) for the GPT image models, one of 256x256, 512x512, or 1024x1024 for dall-e-2, and one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3. |
| stream | object | No | Generate the image in streaming mode. Defaults to false. See the Image generation guide for more information. This parameter is only supported for the GPT image models. |
| style | object | No | The style of the generated images. This parameter is only supported for dall-e-3. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. |
| user | string | No | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
ImageGenerationResponse
Section titled “ImageGenerationResponse”| Field | Type | Required | Description |
|---|---|---|---|
| created | integer | Yes | - |
| data | Array<ImageObject> | Yes | - |
| usage | object | No | Usage information for image generation (provider-dependent) |
ImageObject
Section titled “ImageObject”| Field | Type | Required | Description |
|---|---|---|---|
| url | string | No | Image URL |
| b64_json | string | No | Base64-encoded JSON |
| revised_prompt | string | No | Revised prompt |
ImageUsage
Section titled “ImageUsage”| Field | Type | Required | Description |
|---|---|---|---|
| prompt_tokens | integer | No | Token count for the prompt |
| image_tokens | integer | No | Token count for the generated image (GPT-Image-1/1.5) |
| input_text_tokens | integer | No | Input text token count (Qwen) |
| output_image_tokens | integer | No | Output image token count (Qwen) |
| width | integer | No | Generated image width (Qwen) |
| height | integer | No | Generated image height (Qwen) |
| image_count | integer | No | Number of images generated (Qwen) |
Related APIs
Section titled “Related APIs”- API Overview - Learn about authentication and basic information
- models - View models related APIs
- chat - View chat related APIs
- responses - View responses related APIs
- messages - View messages related APIs
- completions - View completions related APIs
- edits - View edits related APIs
- embeddings - View embeddings related APIs
- engine-embeddings - View engine-embeddings related APIs
- moderations - View moderations related APIs
- audio - View audio related APIs
- search - View search related APIs
- proxy - View proxy related APIs