OpenAI-compatible
Image generation (Images)
Generate images in the OpenAI Images format — URL, parameters, response and samples — and which endpoint Gemini image models use.
Compatible with OpenAI’s Create image.
POST https://noviahub.com/v1/images/generationsFor models whose endpoint labels include Image, such as gpt-image-2 (check on Models & Pricing).
Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization |
Yes | Bearer <your API key> |
Content-Type |
Yes | application/json |
Request parameters
Section titled “Request parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | Model ID, such as gpt-image-2. Without it the gateway assumes dall-e, which NoviaHub doesn’t have, so the call returns 503. |
prompt |
string | Yes | Description of the image. The gateway doesn’t check it, but the model needs it. |
n |
integer | No | Number of images, 1 to 128. Missing or 0 means 1; above 128 returns an error. |
size |
string | No | Size, such as 1024x1024. Use the letter x, not the multiplication sign ×, or you get an error. |
quality |
string | No | Quality; values depend on the model. |
response_format |
string | No | How the image is returned, such as b64_json or url, if the model supports it. |
background, output_format, output_compression, moderation, style, partial_images, input_fidelity |
— | No | Forwarded as defined by OpenAI; support depends on the model. |
stream |
boolean | No | Stream the result (if the model supports it). |
user |
— | No | User identifier, forwarded as is. |
Fields not in the table are not forwarded upstream.
Sample code
Section titled “Sample code”curl https://noviahub.com/v1/images/generations \ -H "Authorization: Bearer $NOVIAHUB_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-image-2", "prompt": "An orange cat sunbathing on a windowsill, watercolour style", "size": "1024x1024", "n": 1 }'import base64import os
from openai import OpenAI
client = OpenAI( base_url="https://noviahub.com/v1", api_key=os.environ["NOVIAHUB_API_KEY"],)
result = client.images.generate( model="gpt-image-2", prompt="An orange cat sunbathing on a windowsill, watercolour style", size="1024x1024", n=1,)
image = result.data[0]if image.b64_json: with open("cat.png", "wb") as f: f.write(base64.b64decode(image.b64_json))else: print(image.url)import { writeFile } from 'node:fs/promises'
import OpenAI from 'openai'
const client = new OpenAI({ baseURL: 'https://noviahub.com/v1', apiKey: process.env.NOVIAHUB_API_KEY,})
const result = await client.images.generate({ model: 'gpt-image-2', prompt: 'An orange cat sunbathing on a windowsill, watercolour style', size: '1024x1024', n: 1,})
const image = result.data?.[0]if (image?.b64_json) { await writeFile('cat.png', Buffer.from(image.b64_json, 'base64'))} else { console.log(image?.url)}Response
Section titled “Response”| Field | Description |
|---|---|
created |
Creation time (Unix seconds). |
data[] |
One entry per image. The image is in b64_json (Base64) or url, depending on the model. |
usage |
Usage, when the model reports it. |
{ "created": 1790609867, "data": [{ "b64_json": "iVBORw0KGgo=" }], "usage": { "input_tokens": 10, "output_tokens": 1056, "total_tokens": 1066 }}b64_json is the image file encoded in Base64; decode it and save it, as the samples do.
Whether a model is billed by tokens or per image, and at what price, is shown on its Models & Pricing page.
Gemini image models
Section titled “Gemini image models”Gemini image models such as gemini-3.1-flash-image can be called in two ways:
- Native Gemini endpoint (recommended):
POST /v1beta/models/gemini-3.1-flash-image:generateContent; see generateContent. The generated image is incandidates[].content.parts[].inlineData(mimeTypeplus Base64data). - Chat Completions:
POST /v1/chat/completionswith this image model asmodel; the gateway asks the model for both text and image output. Images come back insidechoices[0].message.contentas Markdown images:.- Set aspect ratio and size with
extra_body.google.image_config, using the keysaspect_ratioandimage_size(snake_case only; camelCase keys are rejected).
- Set aspect ratio and size with
Common errors
Section titled “Common errors”| HTTP status | Cause |
|---|---|
| 400 | n above 128 (n must be an integer between 1 and 128), the sign × in size, or the body isn’t valid JSON. |
| 401 | The key is invalid, disabled, expired or out of quota. |
| 403 | The key isn’t allowed to use this model, the IP isn’t on the allow list, or the account balance is too low. |
| 500 | A Gemini image model was called on this endpoint (convert_request_failed). |
| 503 | Wrong or missing model ID, or no channel is currently available for the model. |
See Errors and troubleshooting for details.