Docs / Examples / Text-to-Image
Text-to-Image
Generate an image from a text prompt using POST /v1/images/generations. One call, image URL in the response.
#Python
text_to_image.pypython
import requests, os
response = requests.post(
"https://relayrouter.io/v1/images/generations",
headers={
"Authorization": f"Bearer {os.environ['RELAYROUTER_API_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "gpt-image-1",
"prompt": "a cinematic shot of an astronaut floating above Earth at sunrise, photorealistic",
"n": 1,
},
)
response.raise_for_status()
print(response.json()["data"][0]["url"])#Node.js / TypeScript
textToImage.tstypescript
const res = await fetch("https://relayrouter.io/v1/images/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.RELAYROUTER_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-image-1",
prompt: "a cinematic shot of an astronaut floating above Earth at sunrise, photorealistic",
n: 1,
}),
});
const { data } = await res.json();
console.log("Image URL:", data[0].url);#cURL
terminalbash
curl https://relayrouter.io/v1/images/generations \
-H "Authorization: Bearer $RELAYROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-1",
"prompt": "a cinematic shot of an astronaut floating above Earth at sunrise, photorealistic",
"n": 1
}'#Parameters
| Parameter | Type | Description |
|---|---|---|
model | string | Image model ID (required) |
prompt | string | Text description of the image (required) |
n | integer | Number of images to generate. Default: 1 |
size | string | Optional output size, model-dependent (e.g. "1024x1024") |
Find image model IDs via
GET /v1/models or the Models page. Full endpoint details are in the Generate Image reference.