Skip to content
gaspardglacosPublic

About

Generate images with the Reve API

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Reve API — Python Quickstart

Reve API Python 3.10+ License: MIT

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).

What it does

Given a text prompt, the script:

  1. Reads your Reve API key from a local .env file
  2. Sends a POST request to the Reve image-creation endpoint
  3. Decodes the base64-encoded image from the JSON response
  4. Saves it as mountain.png in the project folder

That's it. No frameworks, no UI, no magic.

Prerequisites

  • 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)

Setup

# 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 .env

Then edit .env and replace your-reve-api-key-here with your real key from the Reve console:

REVE_API_KEY=papi.your-token-here

Usage

python reve.py

Expected 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.

Changing the prompt

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.

Saving with a different filename

Change the OUTPUT_PATH near the top:

OUTPUT_PATH = Path("my_image.png")

How it works

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": "..." }

Optional Reve features

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"}
    ],
}

Other endpoints

Reve also offers two endpoints that this script doesn't use:

  • POST /v1/image/edit — modify an existing image with a text instruction
  • POST /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.

Troubleshooting

Status: 402 — PARTNER_API_BUDGET_EXHAUSTED

Your Reve API budget has run out. Top it up in the Reve console's API Budget panel, then rerun.

Status: 401 — Unauthorized

Your API key is missing or wrong. Check that:

  • .env exists 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

Status: 429 — Rate limit exceeded

You sent too many requests in a short window. Wait a few seconds and try again, or batch your prompts.

Error: REVE_API_KEY not found

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 cmd

The file must be in the same folder as reve.py.

No image in response

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.

Project structure

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

Security notes

  • Never commit .env. The included .gitignore already 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.

Links

About

Generate images with the Reve API

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages