<!-- Markdown twin of https://pixelvault.dev/blog/host-gpt-image-2-images -->

[← Back to blog](/blog)

By [PixelVault](/about) August 6, 2026

# How to host GPT Image 2 images so they don't disappear

GPT Image 2 (OpenAI's `gpt-image-2`, shipped April 2026) makes gorgeous images — and then hands you something you can't directly embed: a base64 blob, or a URL that expires. OpenAI's own guidance is to store the bytes in your own CDN. This is the one-call way to do exactly that: take a gpt-image-2 result and turn it into a permanent, embeddable URL.

![A freshly generated GPT Image 2 picture with base64 bytes and an expiring link on the left, re-hosted into a stable PixelVault URL through a vault aperture on the right](https://img.pixelvault.dev/proj_mkoboesmx25d/img_sgg7tbosae6r.jpg?w=1400&fmt=auto&q=auto)

Fittingly, this hero was generated by an AI image model and then hosted on PixelVault itself — a stable `img.pixelvault.dev` URL, the exact generate-then-host loop this post describes.

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

1\. Generate 2\. Host it

// GPT Image 2 hands you bytes, not a lasting URL. Ask for base64…  
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](/blog/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](/blog/nano-banana-image-hosting). 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](/blog/mcp-image-hosting) and hosting becomes a native tool call, or hand it the open-source [upload skill](/blog/host-images-with-your-coding-agent) 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](/pricing). Start from the [API quickstart →](/docs)
