DEV Community

Om Prakash
Om Prakash

Posted on

How to Generate Real Pixel Art Sprites via API (With Transparent Backgrounds)

You're building a 2D game in Godot. You have 3 items, 2 enemies, and 4 UI buttons to design. The options? Commission an artist for $200+ and wait a week. Or use AI. But most AI image tools give you photorealistic renders — beautiful, completely useless for game dev.

Pixel art needs specific treatment: exact pixel placement, limited palette, transparent backgrounds. Today I'll show how PixelAPI's Game Assets endpoint handles all three automatically.

The Problem with Generic Image AI for Games

Most image generation APIs are trained on photography and digital art. Ask them for a "pixel art sword" and you get a sword with pixel art style — still a high-resolution rendering, anti-aliased edges, thousands of colors. Drop it in your game and it looks wrong immediately.

Real pixel art needs:

  • Hard pixel boundaries (no anti-aliasing)
  • Limited color palette (8-64 colors max)
  • Transparent background so it composites cleanly onto any scene
  • Consistent scale so sprites feel like they belong together

How PixelAPI Generates Real Pixel Art

The pixel-art and icon styles use a different pipeline from standard image generation:

  1. Specialized model: PublicPrompts/All-In-One-Pixel-Model (SD 1.5 fine-tune, trained on pixel art) with the pixelsprite trigger word
  2. Pixel quantization: Output is post-processed to 8px block size and quantized to 32 colors
  3. Automatic background removal: BiRefNet runs on the result, producing RGBA PNG with transparent background

No photorealistic render. No anti-aliasing. Just the sprite.

Quick Start

Generate a Knight Sprite

curl -X POST https://api.pixelapi.dev/v1/game-assets/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "knight warrior with sword",
    "style": "pixel-art"
  }'
Enter fullscreen mode Exit fullscreen mode

Batch-Generate an Entire Party

import requests, time

API = "https://api.pixelapi.dev"
KEY = "YOUR_API_KEY"

characters = [
    "knight warrior with sword and blue armor",
    "wizard with staff and purple robe",
    "rogue archer with bow",
    "healer cleric with golden mace",
]

jobs = []
for char in characters:
    r = requests.post(f"{API}/v1/game-assets/generate",
        headers={"Authorization": f"Bearer {KEY}"},
        json={"prompt": char, "style": "pixel-art"})
    jobs.append(r.json()["generation_id"])

results = {}
while len(results) < len(jobs):
    for job_id in jobs:
        if job_id in results:
            continue
        r = requests.get(f"{API}/v1/game-assets/{job_id}",
            headers={"Authorization": f"Bearer {KEY}"})
        data = r.json()
        if data["status"] == "completed":
            results[job_id] = data["output_url"]
            print(f"Done: {data['output_url']}")
    if len(results) < len(jobs):
        time.sleep(5)
Enter fullscreen mode Exit fullscreen mode

4 characters. $0.02 total. Transparent PNGs ready for Unity/Godot.

All 7 Art Styles

Style Use Case Output
pixel-art RPG/platformer characters, enemies Transparent RGBA PNG, 32 colors
icon Inventory items, skill icons, pickups Transparent RGBA PNG, 32 colors
isometric Strategy tiles, buildings, objects PNG
ui-kit Buttons, panels, progress bars, HUD PNG
fantasy-2d Fantasy characters, environments PNG
scifi-2d Sci-fi units, weapons, vehicles PNG
sprite-sheet Animation frames strip PNG

What the Output Actually Looks Like

Verified output from the knight sprite test:

  • Mode: RGBA (transparent PNG)
  • Colors: 32 (true limited palette)
  • Transparency: 79% of pixels fully transparent
  • Block size: 8px hard pixels, no anti-aliasing

Drop it straight into Godot as a Sprite2D. No masking, no cleanup required.

Pricing

5 credits per image = $0.005. Compare:

  • Scenario.com: $0.02+ per image (4x more expensive)
  • Midjourney: no API, manual workflow
  • Self-hosted SD: free but you need GPU + setup + post-processing pipeline

Get Started

  1. Sign up free at pixelapi.dev (100 free credits)
  2. Generate your first sprite with 5 credits
  3. Check the Game Assets docs for full API reference

PixelAPI is an AI image/video generation API built for developers. All processing runs on in-house GPU infrastructure.

Top comments (0)