If you've done the Hugging Face image lesson, this one is almost the same — we're just swapping vendors. NVIDIA hosts the same FLUX.1-schnell image model, but their API wraps the picture in a tiny JSON envelope instead of sending it as raw bytes. One extra line to decode it, and that's the whole difference. 🌱
Both examples below read your key from an environment variable called NVIDIA_API_KEY. Get a free key at build.nvidia.com (top-right "Get API Key"), then set it once and forget it.
NVIDIA returns a JSON object that looks like {"artifacts":[{"base64":"..."}]} instead of raw image bytes — so we pipe the response through a one-liner Python decoder that pulls out the picture and writes it to robot.jpg.
Same idea, all in one Python file: send the request, decode the base64 from the JSON, save the file. The requests library handles the network call; the base64 module (built in) does the decode.
First time? Install the helper once: pip install requests. Then run with python robot.py.
Same model, same prompt — the differences are all in the API contract:
| What | Hugging Face | NVIDIA |
|---|---|---|
| Address | router.huggingface.co/hf-inference/... |
ai.api.nvidia.com/v1/genai/... |
| Request body | {"inputs": "..."} — one short field |
{"prompt": "...", "cfg_scale": 0, "steps": 4, ...} — a few required knobs |
| Response shape | Raw JPEG bytes — save straight to a file. | JSON with the image as a base64 string — one extra decode step. |
| Env var name | HF_TOKEN |
NVIDIA_API_KEY |
The vendor chooses the contract; the model — FLUX.1-schnell — is identical underneath. Run both scripts side by side with the same prompt and the pictures look like siblings. 🎨
Type a picture idea below and watch the JSON body change in real time. This is the exact body the two scripts above send. Nothing gets sent anywhere — it's just to play with! 👇