Why you can't just use what the API returns
The Images API gives you two ways to receive a generation, and neither is something you can paste into a webpage and forget:
- A temporary URL. Convenient in the moment, but it's short-lived — link to it from a blog post or an app and it goes dead. OpenAI's docs are explicit that these URLs expire and you should download the image promptly.
- Base64 (
b64_json). The bytes are yours, which is why the docs recommend it — but a giant base64 string isn't a URL. You still have to put those bytes somewhere that serves them at a stable address before an<img>tag or an OG tag can use them.
So the real task after generating with GPT Image 2 is always the same: get the bytes onto a permanent URL. Dumping the base64 straight into your HTML technically renders, but it bloats the page, breaks in email, and can't be resized or cached like a real asset. You want a proper hosted image.
The two-step pattern: generate, then host
Ask gpt-image-2 for b64_json, decode it, and upload it once. PixelVault gives you back a permanent, immutable CDN URL — zero egress, global edge — that you can drop into a page, an email, a README, or hand to your coding agent.
import OpenAI from "openai";
const openai = new OpenAI();
const gen = await openai.images.generate({
model: "gpt-image-2",
prompt: "a minimalist blog hero, indigo gradient, flat vector",
});
const b64 = gen.data[0].b64_json; // raw PNG bytes, base64-encoded
Both steps run server-side — your OPENAI_API_KEY and PIXELVAULT_API_KEY are secrets and must never ship to a browser. The upload is one HTTP call, and the URL it returns is stable and immutable — host once, embed anywhere, no expiring signature to babysit. Need a specific size for a thumbnail or an OG card? Ask for it on the fly with transform params (?w=1200&h=630&fmt=auto) instead of re-generating.
Where this fits
GPT Image 2 is one of several models with the same catch — the expiring-link problem isn't unique to OpenAI. If you're comparing options or using more than one, the broader guide covers the whole cluster: how to host AI-generated images (DALL·E, GPT Image, Midjourney, Flux). And if you generate with Google's model instead, there's a dedicated walkthrough for hosting Nano Banana images. This post is the GPT-Image-2-specific version of that same one-call loop.
Straight from your coding agent
If an agent is generating the image — Claude Code, Cursor, Codex building a page or an OG card — it hits the exact wall above: a base64 blob with nowhere to live. Point it at PixelVault's MCP server and hosting becomes a native tool call, or hand it the open-source upload skill so the generate-then-host loop is one command.
Free to start
PixelVault's free tier includes 200 MB storage, 500 uploads/month, and 1 GB bandwidth — no credit card, zero egress. Plenty to host a project's worth of generated art before you pay anything, and paid plans start at $9/month. Start from the API quickstart →