Skip to main content

Image Generation

Available Models

The full list of models can be viewed on the Models page or retrieved dynamically via API endpoints: https://openai.bothub.chat/v1/images/models and https://bothub.chat/api/v2/replicate/v1/models

BotHub uses a unified ecosystem of gateways for image generation. You can work both with models via a OpenAI compatible gateway and through our custom Replicate gateway.

Integration is performed via three different endpoints, depending on the task and the chosen model:


Integration Options​

  • OpenAI Generate Images API (/v1/images/generations) — used for generating images based on a prompt and input parameters
  • OpenAI Edit Images API (/v1/images/edits) — used for generating images based on other images (for models that support image input)
  • Custom Replicate API Gateway (/replicate/v1/images/generations) — a dedicated BotHub gateway for working with Replicate models. All custom parameters are passed in the input object unchanged.

1. OpenAI Generation Images API​

Used for generating images based on a prompt and input parameters. The prompt is passed in the prompt property of the request body, and the model is specified in the model property.

Some models support or require an input image. Support for image input and whether it is required can be checked using the supports_image_input and requires_image_input properties in the model information returned by the https://openai.bothub.chat/v1/images/models API endpoint.

The response format (b64_json or url) is determined by the response_format field. The default value is b64_json.

A list of model-specific input parameters is available through the params property of the model object when requesting model information via the https://openai.bothub.chat/v1/images/models API endpoint.

Example Request​

import OpenAI from 'openai';

const openai = new OpenAI({
apiKey: 'YOUR_BOTHUB_API_KEY',
baseURL: 'https://openai.bothub.chat/v1'
});

async function main() {
const response = await openai.images.generate({
model: "gemini-2.5-flash-image",
prompt: "Draw a cute ginger cat",
response_format: "url",
});

console.log(response);
}

main();

Example Response:​

{
"created": 1781041942,
"data": [
{
"url": "https://32b76580-04bc-45a6-83c4-37b3a03f1877.selstorage.ru/production-timeweb/images/ba990baf-eaeb-4ea0-885e-21bc00950af2.png"
}
],
usage: {
input_tokens: 17,
input_tokens_details: { text_tokens: 17, image_tokens: 0 },
output_tokens: 1302,
output_tokens_details: { text_tokens: 12, image_tokens: 1290 },
total_tokens: 1319
}
}

2. OpenAI Edits Images API​

Used for generation based on input images. Supported only for models that accept images as an input parameter. Support for image input can be checked using the supports_image_input and requires_image_input properties in the model information returned by the https://openai.bothub.chat/v1/images/models API endpoint.

The endpoint expects the request body to be sent as multipart/form-data. Input images are passed in the image field in binary format.

The response format (b64_json or url) is determined by the response_format field. The default value is b64_json.

A list of model-specific input parameters is available via the params property of the model object when requesting model information through the https://openai.bothub.chat/v1/images/models API endpoint.

Example Request​

import OpenAI, {toFile} from 'openai';

const openai = new OpenAI({
apiKey: 'YOUR_BOTHUB_API_KEY',
baseURL: 'https://openai.bothub.chat/v1'
});

async function main() {
const image = await toFile(fs.createReadStream("input.png"), "input.png", {
type: "image/png",
});

const response = await openai.images.edit({
model: "gemini-2.5-flash-image",
prompt: "Change the cat's color to black",
image,
response_format: "url",
});

console.log(response);
}

main();

Example Response:​

{
created: 1785408240,
data: [
{
url: 'https://32b76580-04bc-45a6-83c4-37b3a03f1877.selstorage.ru/production-timeweb/images/b16b5ae4-8b4a-4d4b-af43-a02472ac449d.png'
}
],
usage: {
input_tokens: 265,
input_tokens_details: { text_tokens: 265, image_tokens: 0 },
output_tokens: 1308,
output_tokens_details: { text_tokens: 18, image_tokens: 1290 },
total_tokens: 1573
}
}

3. Custom Replicate API Gateway​

Because the Replicate architecture is fundamentally different from OpenAI, a direct HTTP gateway also exists for these models (e.g., flux-2-max) at the address https://bothub.chat/api/v2/replicate/v1/images/generations.

All parameters specific to a particular model are passed within the input object unchanged. The official Replicate or OpenAI SDKs cannot be used for this endpoint. We also proxy the response link so that you have access to the content without a VPN.

Bothub Parameters for Output Control

In the request body, you can pass an optional bothub object to configure the proxy:

  • include_usage (boolean) — returns an usage object with information about the platform's consumed "caps".
  • return_base64 (boolean) — if true, the gateway will return the image as a Base64 string instead of a link.

Supported parameters should be verified for each specific model.

Example Request​

async function main() {
const response = await fetch(
'https://bothub.chat/api/v2/replicate/v1/images/generations',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer YOUR_BOTHUB_API_KEY',
},
body: JSON.stringify({
model: 'flux-2-max',
input: {
prompt: 'Retro car in the desert, 80s style, photorealism',
aspect_ratio: '16:9',
output_format: 'png',
output_quality: 90,
},
bothub: {
include_usage: true,
return_base64: false,
},
}),
},
);

const result = await response.json();
const url = result.url;
console.log(url);
}

main();

Example Response:​

{
"url": "https://32b76580-04bc-45a6-83c4-37b3a03f1877.selstorage.ru/production-timeweb/images/b7e1ecee-0d89-44eb-b801-7a43e50dbfa0.png",
"usage": {
"bothub": {
"caps": 71199.648
}
}
}

Recommendations​

Official OpenAI Documentation

You can read more about the Image Generation API in the official OpenAI documentation:

https://developers.openai.com/api/docs/guides/image-generation