EUrouter

Image generation

Generate images with the OpenAI SDK through EUrouter. Find model-specific options, image pricing, base64 delivery and safe error handling in one guide.

OpenAPI JSON

Generate images with the normal OpenAI Images SDK using an EUrouter inference key, the public base URL and an image model from the live catalog.

Generate an image

Set EUROUTER_IMAGE_MODEL to a live catalog model ID that supports image output and images.generations. Keep your API key on the server. These examples hold the returned image in memory; they do not write an image file.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.EUROUTER_API_KEY,
  baseURL: "https://api.eurouter.ai/api/v1",
  maxRetries: 0,
});

const model = process.env.EUROUTER_IMAGE_MODEL;
if (!model) throw new Error("Set EUROUTER_IMAGE_MODEL to a live image model ID");

const result = await client.images.generate({
  model,
  prompt: "A blue ceramic cup on a wooden table in natural light.",
});

const encoded = result.data?.[0]?.b64_json;
if (!encoded) throw new Error("No image was returned");
const imageBytes = Buffer.from(encoded, "base64");
const imageBlob = new Blob([new Uint8Array(imageBytes)]);
import base64
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["EUROUTER_API_KEY"],
    base_url="https://api.eurouter.ai/api/v1",
    max_retries=0,
)

result = client.images.generate(
    model=os.environ["EUROUTER_IMAGE_MODEL"],
    prompt="A blue ceramic cup on a wooden table in natural light.",
)

encoded = result.data[0].b64_json
if not encoded:
    raise ValueError("No image was returned")
image_bytes = base64.b64decode(encoded, validate=True)

The response is JSON containing data[].b64_json, rather than a raw binary HTTP body. Base64 represents the encoded image bytes as text. Your application can convert those bytes into a Blob for display or download. A download or file save in your application is separate from EUrouter's handling.

Omitted options use the selected endpoint's catalog defaults. Do not copy a size, quality setting or image count from another model without checking its options.

Find a model's supported options

Open a model page for the provider-specific option and price tables. The public endpoint catalog exposes the same facts at GET /api/v1/models/<author>/<slug>/endpoints.

Each endpoint's image_capabilities["images.generations"] defines its supported parameters, allowed values, defaults, prompt-length units, dimensions, count and aggregate pixel limit. Its pricing defines the billable units. These records also drive validation, so an unsupported option produces an error instead of being silently removed.

The model-level supported_parameters list is a summary across endpoints. It does not promise that every provider supports every option. Image input for vision is also different from image output for generation.

Options such as size, quality, background, moderation, output_format, output_compression, safety_identifier and legacy user are model-dependent. A prompt limit can be measured in Unicode code points or UTF-8 bytes. It is not necessarily a token context window.

Provider-specific options

Use normal SDK arguments for OpenAI fields. An advertised scalar provider option, such as a seed, can be sent as an extra field in JavaScript or through Python's extra_body. Send it only when the selected endpoint advertises it.

Set the resolution with size, for example size: "1024x1024" alongside model and prompt. The available sizes depend on the provider endpoint. A size beside a published price identifies the size that rate applies to.

EUrouter returns base64 JSON. Supported image formats and image counts depend on the endpoint. Image edits, hosted output URLs, streaming and image output through Chat or Responses are not supported. See the API reference for common request limits and response fields.

Pricing and activity

Image models can charge per image, per megapixel or per output token. Prices can vary by provider, resolution and quality; model pages show the unit and settings for each rate.

Some megapixel prices have a starting rate and a lower rate for additional megapixels. For example, €0.013 for the first megapixel plus €0.001 for each additional megapixel makes a four-megapixel image cost €0.016. When the endpoint rounds up per image, that rounding applies separately to every image in a batch. The price information shows how many pixels that endpoint counts as one megapixel.

Image requests use the same purchased credits as other models. Your plan's markup applies when buying credits. EUrouter does not apply a second image markup during inference. Balance checks may use a conservative estimate per requested image; this is not a minimum charge. Model pages show the provider's native currency and applicable discount; account spending is settled in EUR.

usage.cost, usage.cost_eur and usage.cost_currency report the request charge. Per-image and per-pixel charges follow successfully completed images returned to you. If only part of a batch completes, the response can contain fewer images than n. Token-priced endpoints require complete usable results and use the provider-reported token usage; missing token counts are not invented. The balance-check estimate is separate from this final charge.

Activity records contain image counts, dimensions and costs, with no generated image history. Usage recording can take a short time to appear. Check your activity or the generation lookup using the response's x-request-id.

Fix errors without repeating paid work

Image option errors use the usual OpenAI-compatible error envelope:

FieldMeaning
error.paramThe parameter to change
error.details.reason: "unsupported_parameter"Remove the option or select an endpoint that supports it
error.details.reason: "invalid_parameter"Use the safe constraint in error.details.constraint to fix its value
error.details.reason: "output_limit_exceeded"Reduce image count or dimensions

For example, if error.param is quality and the reason is unsupported_parameter, remove quality and use that endpoint's default. Do not retry the same unsupported option. Errors explain safe limits without echoing your prompt or supplied value.

The gateway does not automatically retry ambiguous paid generation failures. Such responses set x-should-retry: false, which the OpenAI SDK honors. Do not wrap image generation in a generic retry loop: a lost connection before response headers can leave upstream completion unknown. Retrying may create another paid image. See error handling for general status codes.

Privacy and processing locations

EUrouter passes image bytes through memory and returns them to your application. It does not store your prompts or generated images, create hosted image URLs or keep an image history. Responses use Cache-Control: no-store. Billing history contains usage and cost information.

Provider-side retention is a separate fact. Check the selected endpoint's processing_countries and data_retention facts in the public endpoint catalog described above for the provider's processing locations and retention policy. EU hosting and zero retention are separate properties.

Was this page helpful?

Still stuck? Contact support

On this page