Tutorial: Text-to-Image Generation
Generate an image from a text prompt through the Primex gateway. Unlike some platforms, Primex image generation is synchronous. You send one request and get the image back, no job ID to poll.
Overview
You'll send a prompt to POST /v1/images/generations, pick a model and size, and
receive the generated image. Billing is per output image (or per megapixel),
charged only on success. See Images.
Prerequisites
- A Primex account and a
prx-key (Getting Started). - Enough credits for one image (shown in the app's AI section).
- The OpenAI SDK if you're using Python or Node (
pip install openai/npm i openai).
Generate an image
cURL
curl https://gateway.primexos.com/v1/images/generations \
-H "Authorization: Bearer prx-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_LIVE_IMAGE_MODEL",
"prompt": "A neon violet fox in a misty forest, studio lighting, ultra detailed",
"size": "1024x1024"
}'
Python
from openai import OpenAI
client = OpenAI(
base_url="https://gateway.primexos.com/v1",
api_key="prx-YOUR_KEY",
)
result = client.images.generate(
model="YOUR_LIVE_IMAGE_MODEL",
prompt="A neon violet fox in a misty forest, studio lighting, ultra detailed",
size="1024x1024",
)
print(result.data[0].url or result.data[0].b64_json[:32])
Node
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://gateway.primexos.com/v1",
apiKey: "prx-YOUR_KEY",
});
const result = await client.images.generate({
model: "YOUR_LIVE_IMAGE_MODEL",
prompt: "A neon violet fox in a misty forest, studio lighting, ultra detailed",
size: "1024x1024",
});
console.log(result.data[0].url ?? result.data[0].b64_json.slice(0, 32));
Tips
- Be specific about style, composition, lighting, colours and mood. Detailed prompts produce more predictable results.
- Match model to need. Compare editing support, quality controls, output formats, and billing units in the live catalogue.
- Editing: models that advertise editing support use
POST /v1/images/edits(multipart: input image + prompt).