
Deploy Real-ESRGAN | (Just Updated) AI Image Upscaler API, 2x-4x Photo Enhancer, API Key Pre-Set
Real-ESRGAN AI image upscaler API: enlarge photos 4x, anime, CPU, no GPU
realesrgan
Just deployed
Deploy and Host Real-ESRGAN (AI Image Upscaler API) on Railway
An image upscaler API enlarges a photo, a screenshot or an illustration 2x, 3x or 4x and fills in plausible detail instead of the blur that plain resizing leaves. This template serves the Real-ESRGAN models (the xinntao/Real-ESRGAN project) on CPU behind one authenticated HTTP API. The weights are already inside the image, an API key is generated for you at deploy, and no GPU is needed.
About Hosting Real-ESRGAN
The service runs four Real-ESRGAN checkpoints with PyTorch 2.15.0 behind a small FastAPI server: realesr-general-x4v3 (default; small and fast, general photos and graphics, with an adjustable denoise strength), realesrgan-x4plus (the largest, best on photos), realesrgan-x4plus-anime (illustrations and anime) and realesrgan-x2plus (a native 2x model). POST /upscale takes one image, as a multipart file part or a raw image/* body, and returns the enlarged image as PNG, WebP or JPEG (format=). Query fields are scale (2, 3 or 4; default 4), model, denoise (0 to 1; realesr-general-x4v3 only) and format. A scale the model does not produce natively is made by resizing its native output, and transparency is kept for PNG and WebP. The reply headers X-Processing-Seconds, X-Input-Size, X-Output-Size and X-Model say what was done. GET /v1/models lists the models and the limits in force.
The weights are baked into the image and verified by sha256 at build time, so nothing downloads at boot and the models are ready about 1 second after the container starts. The service sizes its thread pool from the container's own CPU quota and runs one upscale at a time so memory stays bounded. Images are cut into 256 px tiles with a 10 px overlap, the way the upstream project does it for CPU. Up to 3 requests may run or wait; a fourth answers 429 with Retry-After: 30. A request that cannot finish within 240 seconds of arriving answers 504 before Railway's edge can cut the connection, which it does at about five minutes. An input over 1,000,000 pixels, an output over 16,000,000 pixels or a file over 10 MiB answers 413, and a file that is not a JPEG, PNG, WebP, GIF, BMP or TIFF answers 422. Images are held in memory for one request and are never logged or written to disk.
Measured on Railway, 8 vCPU (model time, from the X-Processing-Seconds header, on a synthetic photo-like JPEG; a whole request over the public URL added about 0.2 to 0.5 s of upload and transfer):
| Model | Input | Scale | Seconds |
|---|---|---|---|
realesr-general-x4v3 | 256x256 | 4x | 0.43 to 0.47 |
realesr-general-x4v3 | 512x512 | 2x | 1.64 |
realesr-general-x4v3 | 512x512 | 4x | 2.35 |
realesr-general-x4v3 | 1000x1000 | 4x (4000x4000 out) | 10.7 |
realesrgan-x4plus | 256x256 | 4x | 4.1 |
realesrgan-x4plus | 512x512 | 4x | 19.8 |
realesrgan-x4plus | 1000x1000 | 4x (4000x4000 out) | 83.4 |
realesrgan-x4plus-anime | 512x512 | 4x | 8.4 |
realesrgan-x2plus | 512x512 | 2x | 4.7 |
The default model is about 8 times faster than realesrgan-x4plus on the same image. The slowest allowed request, a 1,000,000 pixel image at 4x on realesrgan-x4plus, took 83 s. Five concurrent 512x512 realesrgan-x4plus requests gave two 429 answers and three results that finished 19, 42 and 63 s after they were sent, which is the serial queue at work. Resident memory was 483 MB after boot and peaked at 1,956 MB after the 1,000,000 pixel realesrgan-x4plus request. The four models loaded in 1.0 s.
What it does not do. Output quality was checked for size and fidelity, not for taste: against the same inputs the output was closer to the original than a bicubic resize, and a single image is processed in tiles, so on busy, noisy textures the seams between tiles can show faintly because the 10 px overlap is shorter than the network's reach (the same limit the upstream project has). Output is 8-bit, so 16-bit or HDR sources lose depth. The models invent detail: they make a picture look sharper, not more truthful, so do not use the result as evidence, for reading small print or for faces that must stay recognisable. Video, batches and face restoration (GFPGAN) are not included. There is no GPU, so a 1,000,000 pixel photo takes seconds on the default model and over a minute on realesrgan-x4plus.
Weights licence. The Real-ESRGAN repository is BSD-3-Clause, and the same checkpoint files are redistributed under license: bsd-3-clause on several Hugging Face model pages. The project states no separate licence for the weight files and no statement about the training data they were fitted on, and an upstream issue asking about commercial use of realesr-general-x4v3 was still open without an answer when this template was published (2026-11-23). The repository has had no commit since August 2024. Read the upstream licence and decide for your own use before you build a paid product on the output.
Agent contract
- Public URL:
https://RAILWAY_PUBLIC_DOMAIN(the generated domain of therealesrganservice) - Private URL:
http://realesrgan.railway.internal:8080 - Credentials: the
API_KEYvariable of therealesrganservice - Auth: send
Authorization: Bearer $API_KEYon every route exceptGET /health; a call without the key or with a wrong one answers401 - Health:
GET /healthreturns 200 once the models are loaded (503 while they load)
# needs: RAILWAY_PUBLIC_DOMAIN, API_KEY (a variable of the realesrgan service); also curl and base64.
# signup: none - the API has no user accounts, only the API_KEY bearer
R="https://$RAILWAY_PUBLIC_DOMAIN"
echo iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg== | base64 -d | tee /tmp/px.png | wc -c
n=0; until [ "$(curl -s -o /dev/null -w '%{http_code}' "$R/health")" = 200 ]; do n=$((n+1)); [ "$n" -le 60 ] || break; sleep 5; done
curl -s -o /dev/null -w "health: %{http_code}\n" "$R/health"
curl -s -o /dev/null -w "write without key: %{http_code}\n" -X POST "$R/upscale?scale=4" -F file=@/tmp/px.png
curl -s -o /dev/null -w "write wrong key: %{http_code}\n" -X POST "$R/upscale?scale=4" -H "Authorization: Bearer not-the-key" -F file=@/tmp/px.png
curl -s -D - -o /tmp/up.png -X POST "$R/upscale?scale=4" -H "Authorization: Bearer $API_KEY" -F file=@/tmp/px.png | grep -iE "^(HTTP|x-output-size|x-model)"
head -c 8 /tmp/up.png | od -An -c | head -1
A fresh deploy prints health: 200, write without key: 401, write wrong key: 401, HTTP/2 200 with x-output-size: 4x4 and x-model: realesr-general-x4v3, and the first bytes of a PNG (211 P N G). To upscale a real file, send it the same way and save the reply: curl -X POST "$R/upscale" --url-query scale=4 --url-query model=realesrgan-x4plus -H "Authorization: Bearer $API_KEY" -F file=@photo.jpg -o photo-4x.png. An unknown model, a scale other than 2, 3 or 4, or a file that is not an image answers 422; an image over a size limit answers 413; a content type that is neither multipart nor image/* answers 415. The API only reads the image you send and never fetches a URL, so it cannot be pointed at an address inside your network.
Why Deploy Real-ESRGAN on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Real-ESRGAN on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
- Your images stay in your container — upscaling runs in your own service, not in a hosted enhancer that sees every upload.
- No GPU bill and no per-image fee — you pay for the container, not for each enlarged image.
- Four models behind one parameter — pick the fast general model, the photo model, the anime model or a native 2x model per request.
- Nothing to configure — the weights are in the image and the API key is generated at deploy.
- A queue that refuses instead of hanging — a busy service answers
429, and a request that cannot finish in time answers504, both before Railway's five minute edge limit. - Private by default — a generated bearer key guards every route but the health check, and the container refuses to start without one.
Common Use Cases
- Product and listing photos — enlarge small supplier or marketplace images to the size a storefront needs.
- Old scans and screenshots — sharpen low-resolution archive material before it goes into a document or a slide.
- Pre-processing for other models — raise the resolution of an input before OCR, detection or an embedding model reads it.
Dependencies for Real-ESRGAN Hosting
- A service with at least 2 GB of RAM (resident memory measured at 483 MB after boot and 1,956 MB at peak) and 8 vCPU for the speeds above; fewer vCPU upscale proportionally slower.
- No volume: the service keeps no state and the models are in the image.
Deployment Dependencies
- xinntao/Real-ESRGAN — the models, BSD-3-Clause repository; weights from its release assets, verified by sha256 in the image build
- Real-ESRGAN paper — Wang et al., 2021
- BasicSR — Apache-2.0, origin of the RRDBNet network definition
- bon5co/realesrgan-railway — the Railway wrapper image this template deploys, Apache-2.0
- Licences: the repository licence texts ship in the image at
/licenses/, the notices at/app/NOTICE. PyTorch is BSD-3-Clause and Pillow is MIT-CMU.
Template Content
realesrgan
ghcr.io/bon5co/realesrgan-railway:1.0.0
