Image Generation
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 theinputobject 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
- JS
- Python
- Go
- cURL
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();
from openai import OpenAI
client = OpenAI(
api_key='YOUR_BOTHUB_API_KEY',
base_url='https://openai.bothub.chat/v1'
)
response = client.images.generate(
model='gemini-2.5-flash-image',
prompt="Draw a cute ginger cat",
response_format="url",
)
print(response)
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("YOUR_BOTHUB_API_KEY"),
option.WithBaseURL("https://openai.bothub.chat/v1"),
)
response, err := client.Images.Generate(context.Background(), openai.ImageGenerateParams{
Model: openai.ImageModel("gemini-2.5-flash-image"),
Prompt: "Draw a cute ginger cat",
ResponseFormat: openai.ImageGenerateParamsResponseFormatURL,
})
if err != nil {
panic(err)
}
b, err := json.MarshalIndent(response, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
curl https://openai.bothub.chat/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_BOTHUB_API_KEY" \
-d '{
"model": "gemini-2.5-flash-image",
"prompt": "Draw a cute ginger cat",
"response_format": "url"
}'
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
- JS
- Python
- Go
- cURL
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();
from openai import OpenAI
client = OpenAI(
api_key='YOUR_BOTHUB_API_KEY',
base_url='https://openai.bothub.chat/v1'
)
with open("input.png", "rb") as image:
response = client.images.edit(
model="gemini-2.5-flash-image",
prompt="Change the cat's color to black",
image=("input.png", image, "image/png"),
response_format="url",
)
print(response)
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("YOUR_BOTHUB_API_KEY"),
option.WithBaseURL("https://openai.bothub.chat/v1"),
)
file, err := os.Open("input.png")
if err != nil {
panic(err)
}
defer file.Close()
response, err := client.Images.Edit(context.Background(), openai.ImageEditParams{
Model: openai.ImageModel("gemini-2.5-flash-image"),
Prompt: "Change the cat's color to black",
Image: openai.File(file, "input.png", "image/png"),
ResponseFormat: openai.ImageEditParamsResponseFormatURL,
})
if err != nil {
panic(err)
}
b, err := json.MarshalIndent(response, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
curl https://openai.bothub.chat/v1/images/edits \
-H "Authorization: Bearer YOUR_BOTHUB_API_KEY" \
-F 'model=gemini-2.5-flash-image' \
-F 'prompt=Change the cat's color to black' \
-F 'response_format=url' \
-F 'image=@image.png;type=image/png'
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.
In the request body, you can pass an optional bothub object to configure the proxy:
include_usage(boolean) — returns anusageobject with information about the platform's consumed "caps".return_base64(boolean) — iftrue, 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
- JS
- Python
- Go
- cURL
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();
import requests
url = "https://bothub.chat/api/v2/replicate/v1/images/generations"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_BOTHUB_API_KEY"
}
data = {
"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
}
}
response = requests.post(url, json=data, headers=headers)
result = response.json()
url = result.get('url')
print(url)
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := map[string]any{
"model": "flux-2-max",
"input": map[string]any{
"prompt": "Retro car in the desert, 80s style, photorealism",
"aspect_ratio": "16:9",
"output_format": "png",
"output_quality": 90,
},
"bothub": map[string]any{
"include_usage": true,
"return_base64": false,
},
}
body, err := json.Marshal(payload)
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", "https://bothub.chat/api/v2/replicate/v1/images/generations", bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_BOTHUB_API_KEY")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var result map[string]any
if err := json.Unmarshal(data, &result); err != nil {
panic(err)
}
fmt.Println(result["url"])
}
curl https://bothub.chat/api/v2/replicate/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_BOTHUB_API_KEY" \
-d '{
"model": "flux-2-max",
"input": {
"prompt": "Retro car in the desert, 80s style, photorealism",
"aspect_ratio": "16:9",
"output_format": "png"
},
"bothub": {
"include_usage": true,
"return_base64": false
}
}'
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
}
}
}