DEV Community

PixelVault
PixelVault

Posted on Originally published at pixelvault.dev

Generate an image and get a hosted URL in one API call

Originally published on the PixelVault blog.

The usual flow is generate, download, upload, then paste the link. Most image-generation APIs hand you something awkward to keep: a URL that expires, or a blob of base64. To use the picture anywhere (a README, an email, a CMS, a pull request) you still have to download it and upload it somewhere stable. An agent doing that has three tools to call and two places to fail.

We added POST /v1/images/generate to collapse that. You send a prompt, a Cloudflare Workers AI model draws the image, and PixelVault stores it and returns the URL in the same response.

One call: prompt in, hosted image out

You need a PixelVault API key (a secret key and a verified email) and nothing else. No separate AI account or bucket.

curl -s -X POST https://api.pixelvault.dev/v1/images/generate \
  -H "Authorization: Bearer $PIXELVAULT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"Isometric flat illustration of a tidy desk with a laptop, a small potted plant and a coffee cup, soft pastel colors, no text"}' \
  | jq -r '.data.url'

# → https://img.pixelvault.dev/proj_…/img_….jpg
Enter fullscreen mode Exit fullscreen mode
const res = await fetch("https://api.pixelvault.dev/v1/images/generate", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.PIXELVAULT_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    prompt: "Minimal studio backdrop for product photos, terracotta pedestal, soft morning light, no text",
  }),
});
const { data } = await res.json();

console.log(data.url);        // the hosted image
console.log(data.generation); // { model, credits_charged, credits_remaining }
Enter fullscreen mode Exit fullscreen mode
import os, requests

res = requests.post(
    "https://api.pixelvault.dev/v1/images/generate",
    headers={"Authorization": f"Bearer {os.environ['PIXELVAULT_API_KEY']}"},
    json={"prompt": "Abstract gradient background in indigo and orange, soft glow, no text"},
)
data = res.json()["data"]

print(data["url"])         # the hosted image
print(data["generation"])  # model, credits_charged, credits_remaining
Enter fullscreen mode Exit fullscreen mode

The response is the same payload an upload returns, plus a generation block that tells you what it cost. This is a real one:

{
  "data": {
    "id": "img_rnvpd6170k5c",
    "url": "https://img.pixelvault.dev/proj_mkoboesmx25d/img_rnvpd6170k5c.jpg",
    "optimized_url": "…/img_rnvpd6170k5c.jpg?fmt=auto&q=85",
    "mime_type": "image/jpeg",
    "size": 160196,
    "width": 1024,
    "height": 1024,
    "generation": {
      "model": "flux-1-schnell",
      "credits_charged": 1,
      "credits_remaining": 7
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Calls took three to four seconds end to end in our production runs. The image comes back as a 1024×1024 file: 160 KB as a JPEG, and the optimized_url serves the same picture as WebP at 21.8 KB, which is the one to put in a page or an email.

What it produces

The default model, flux-1-schnell, is good at illustrations, backgrounds and abstract art. It does not follow every instruction literally: in our desk example the model drew two coffee cups, and the gradient came out warmer than "deep indigo and orange" suggests. Treat the first result as a draft, and rerun or reword the prompt when it matters.

Crop it for the platform without another tool

The result is a normal PixelVault image, so every URL transform works on it. A social background cropped to the 1200×630 Open Graph size is just a query string on the URL you already have:

…/img_xs7dx8d9uvy1.jpg?w=1200&h=630&fit=cover&fmt=auto
Enter fullscreen mode Exit fullscreen mode

Generate once, then resize per channel with a URL. Nothing is re-uploaded.

Use it from Claude or any MCP client

The same capability is a tool, generate_image, on the PixelVault MCP server and on the OAuth connector you add to Claude. Connect PixelVault to Claude, then ask:

Use PixelVault to generate a minimalist hero image of a mountain at sunrise, flat illustration, and give me the CDN URL and Markdown.

The tool returns the same fields as the API, including how many credits are left.

Models and credits

Generation draws from a monthly credit grant instead of counting images, because the models differ a lot in cost.

Model Credits per image Plans
flux-1-schnell (default) 1 All, including Free
sdxl-lightning, sdxl-base (beta) 1 Starter, Pro
lucid-origin, phoenix-1.0 (Leonardo) 20 Starter, Pro
  • Free: 10 credits a month, which is ten flux-1-schnell images.
  • Starter: 300 credits a month. Pro: 1,500.
  • Credits reset on the first of each month (UTC). Deleting an image does not give its credit back.
  • If a generation fails or the image can't be stored, the credit is refunded.

A generated image also counts toward your normal upload and storage limits.

Limits and what the errors mean

  • 402 generation_credits_exhausted: out of credits until the first, or upgrade. Don't retry.
  • 402 model_requires_paid_plan: the free plan can only use flux-1-schnell.
  • 429: 60 generations per hour per account, or the service is at daily capacity. Honor Retry-After.
  • 422 prompt_rejected: prompts that clearly ask for adult content are refused.
  • 502, 503, 504: the model failed or timed out. Your credit is refunded and it is safe to retry.

The full list is in the API guide.

Where it fits, and where it doesn't

These are open models served by Cloudflare Workers AI. They are not the largest models available, so for exact text in the image or photoreal faces, test your own prompt first. Each model carries its own license, so check Cloudflare's model catalog before commercial use.

If you already generate images with another tool, our guide to hosting AI-generated images covers turning expiring URLs and base64 blobs into stable ones. And if you only need a quick link for an existing picture, the free image to URL tool needs no account; the link lasts 24 hours unless you sign up.

Try it

The free plan includes 10 generation credits a month with no card. Create an account, grab your key, and run the curl example above. Keeping images beyond the free tier depends on your plan and PixelVault's retention policy, so check the pricing page for the current terms.

Top comments (0)