REST API
/api/v1/images/generations
Generate images from a text prompt. The request follows OpenAI's images.generate, so the OpenAI SDKs work with the Railwail base URL. Each image is its own run, billed at the model's price.
- URL
- https://railwail.com/api/v1/images/generations
- Key scope
- images
- Returns
- 200 with URLs · 202 if slow
- Default model
- flux-1-schnell
Request body
JSON. Unknown fields are rejected with 400 validation_failed; for example aspect_ratio and seed cannot be sent here. Only prompt (and model) work for every model; the rest is used where the model has that input.
modelflux-1-schnellpromptrequiredn1sizequalitystylenegative_promptresponse_formaturluserExamples
Key in RAILWAIL_API_KEY, with the images scope (not on by default).
curl https://railwail.com/api/v1/images/generations \
-H "Authorization: Bearer $RAILWAIL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "flux-1-schnell",
"prompt": "A beautiful sunset over Tokyo, cinematic"
}'import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["RAILWAIL_API_KEY"],
base_url="https://railwail.com/api/v1",
)
image = client.images.generate(
model="flux-1-schnell",
prompt="A beautiful sunset over Tokyo, cinematic",
)
print(image.data[0].url) # None if the run was still processing (HTTP 202)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.RAILWAIL_API_KEY,
baseURL: "https://railwail.com/api/v1",
});
const image = await client.images.generate({
model: "flux-1-schnell",
prompt: "A beautiful sunset over Tokyo, cinematic",
});
console.log(image.data[0].url); // null if the run was still processing (HTTP 202)import railwail from "railwail";
const rw = railwail(process.env.RAILWAIL_API_KEY);
const res = await rw.image("flux-1-schnell", "A beautiful sunset over Tokyo, cinematic");
console.log(res.data[0].url);Response
200: finished
Shape of the answer; values are placeholders.
{
"created": <unix seconds>,
"data": [
{
"url": "https://…/out-0.webp",
"revised_prompt": "<your prompt, unchanged>",
"job_id": "<uuid>",
"status": "completed"
}
]
}Download what you want to keep
202: still processing
Runs that take longer than about 85 seconds return HTTP 202 with status: "processing", url: null, a poll URL and a Location header. Fetch the result with GET /api/v1/jobs/{job_id}. The OpenAI SDKs do not raise on 202; they return url: null, so check for it.
Several images in one request
With n above 1, all images of the request are reserved and charged together: if the balance, the spend limit or the key's credit limit does not cover all of them, none runs and nothing is charged. If some images then fail at the provider, the answer is still 200 (or 202) with the delivered images in data and the failed ones in errors, each with its job_id and code generation_failed; failed images are refunded.
Models you can call here
Live from the catalog: image models that run through this endpoint with a text prompt, with the price as charged. Models that need an input image (editing, upscaling, background removal) run from their model pages.
- FLUX 1.1 Pro
flux-1-1-pro$0.048/image - Flux 1.1 Pro Ultra
flux-pro-ultra$0.072/image - Flux Dev
flux-dev$0.0384/image - Google Imagen 4
imagen-4-flagship$0.048/image - Icons (SDXL Flat Pop)
galleri5-icons-replicate≈ $0.0094/run - Ideogram v3 Quality
ideogram-v3-quality$0.108/image - Recraft 20B SVG
recraft-20b-svg-replicate$0.0528/image - Sticker Maker
sticker-maker-replicate≈ $0.0055/run - AuraFlow v0.3
auraflow-v0-3≈ $0.0648/run - Fibo
bria-fibo$0.048/image
Errors
| Status | Code | What to do |
|---|---|---|
| 400 | validation_failed | A field is unknown or out of range; details lists which. |
| 402 | insufficient_credits | Top up on the billing page. |
| 402 | monthly_limit_exceeded | Your monthly spending limit is reached. |
| 403 | insufficient_scope | The key lacks the images scope. |
| 404 | model_not_found | Check the slug in the list above. |
| 429 | api_key_limit_exceeded | The key's daily or monthly credit limit; nothing was charged. Retry after X-Key-Limit-Reset, not before (credit limits). |
| 429 | trial_limit | Trial rules (at most 2 credits per run until the first top-up). |
| 500 | internal_error | Unexpected server error; retry once. |
| 503 | model_unavailable | No verified price or the provider is not reachable; pick another model. |
All codes: Error codes. Rate-limit headers come with the 200 and error answers, not with a 202.