How to generate images with an API

Create images from text prompts with OpenAI and Google image models through one endpoint.

Call the images endpoint

Send a prompt to the images endpoint with an image model ID. Image models are billed per image, and higher resolutions cost more.

Example

from openai import OpenAI

client = OpenAI(api_key="YOUR_TOKENREX_KEY", base_url="https://tokenrex.ai/api/public")
img = client.images.generate(model="gpt-image-2", prompt="A lighthouse at dawn")
print(img.data[0].url or img.data[0].b64_json[:40])
Get API keyCost calculatorDocs

Questions

Do I need a separate key for each provider?
No. One TokenRex API key works for every enabled model; change only the model ID.

Related