A minimal, dependency-light Python script that calls the Reve API to generate an image from a text prompt and saves it as a .png file.
This repo is meant as a starter template for anyone integrating the Reve API into a Python project — it handles the parts the official docs skip (env management, error reporting, decoding the image, saving it to disk).
Given a text prompt, the script:
- Reads your Reve API key from a local
.envfile - Sends a
POSTrequest to the Reve image-creation endpoint - Decodes the base64-encoded image from the JSON response
- Saves it as
mountain.pngin the project folder
That's it. No frameworks, no UI, no magic.
- Python 3.10+ (the project was developed against 3.14, but any modern 3.x works)
- A Reve account with an API key — get one at https://api.reve.com/console
- Credits in your Reve API budget — the endpoint returns HTTP 402 if your budget is empty (see Troubleshooting below)
# 1. Clone the repo
git clone https://github.com/YOUR_USERNAME/reve-api.git
cd reve-api
# 2. Create a virtual environment
python -m venv .venv
# 3. Activate it
# Windows (PowerShell):
.venv\Scripts\Activate.ps1
# Windows (cmd):
.venv\Scripts\activate.bat
# macOS / Linux:
source .venv/bin/activate
# 4. Install dependencies
pip install -r requirements.txt
# 5. Configure your API key
cp .env.example .env # macOS / Linux
# or on Windows (PowerShell):
copy .env.example .envThen edit .env and replace your-reve-api-key-here with your real key from the Reve console:
REVE_API_KEY=papi.your-token-here
python reve.pyExpected output on success:
Status: 200
Request ID: rsid-xxxxxxxx
Credits used: 150
Credits remaining: 9850
Saved image to C:\path\to\reve api\mountain.png
You'll find mountain.png in the project folder.
Edit the payload block near the bottom of reve.py:
payload = {"instruction": "A beautiful sunset over mountains"}Replace the string with any prompt you like.
Change the OUTPUT_PATH near the top:
OUTPUT_PATH = Path("my_image.png")The Reve image-creation endpoint accepts a JSON body and returns either:
Accept header |
Response |
|---|---|
application/json |
{ "image": "<base64-png>", ... } (default) |
image/png |
Raw PNG bytes |
image/jpeg |
Raw JPEG bytes |
image/webp |
Raw WebP bytes |
This script uses application/json so it can read the request ID and credit-usage headers that Reve attaches to every response, then decodes the base64 image and writes it to disk.
The full request flow:
reve.py
└─ requests.post()
└─ https://api.reve.com/v2/image/create
├─ Authorization: Bearer <REVE_API_KEY>
├─ Content-Type: application/json
├─ Accept: application/json
└─ body: { "instruction": "..." }
These are not enabled in the script but you can add them to the payload dict. See the Reve docs for full details.
| Feature | Payload snippet | Effect |
|---|---|---|
| Higher quality | "test_time_scaling": 3 |
Spends more compute for a better image (1–15) |
| Upscale | "postprocessing": [{"process": "upscale", "upscale_factor": 2}] |
Scales the image 1–4× |
| Remove background | "postprocessing": [{"process": "remove_background"}] |
Strips the background |
| Fit to dimensions | "postprocessing": [{"process": "fit_image", "max_dim": 512}] |
Resizes while preserving aspect ratio |
| Track requests | Append ?breadcrumb=my-step-name to the URL |
Easier to find in the Reve Usage page |
Example with multiple features combined:
payload = {
"instruction": "A watercolor fox in a snowy forest",
"test_time_scaling": 2,
"postprocessing": [
{"process": "upscale", "upscale_factor": 2},
{"process": "remove_background"}
],
}Reve also offers two endpoints that this script doesn't use:
POST /v1/image/edit— modify an existing image with a text instructionPOST /v1/image/remix— blend a reference image with a text prompt
To use them, change API_URL in reve.py. Both accept the same Authorization header and JSON body shape.
Your Reve API budget has run out. Top it up in the Reve console's API Budget panel, then rerun.
Your API key is missing or wrong. Check that:
.envexists in the project folder (not a parent folder)- The line is
REVE_API_KEY=...with no spaces around the= - The key starts with
papi.and matches what's shown in the Reve console
You sent too many requests in a short window. Wait a few seconds and try again, or batch your prompts.
You didn't copy .env.example to .env, or the file is in the wrong folder. From the project root:
ls .env # macOS / Linux / Git Bash
dir .env # Windows cmdThe file must be in the same folder as reve.py.
The API returned a 200 but the JSON didn't contain an image field. This usually means the prompt was rejected by the content policy. Check the X-Reve-Content-Violation response header — true means the prompt violated policy.
reve api/
├── .env # your API key (gitignored, never commit this)
├── .env.example # template for collaborators
├── .gitignore # keeps .env, .venv/, and generated images out of git
├── README.md # this file
├── requirements.txt # python-dotenv + requests
└── reve.py # the script
- Never commit
.env. The included.gitignorealready excludes it — keep it that way. - Treat your API key like a password. Anyone with it can spend your budget.
- Rotate the key in the Reve console if you ever accidentally commit it, paste it in a chat, or push it to a public repo.