Build an AI Image App with a Free API: Complete Tutorial
You can build a fully functional AI image generation app in 30 minutes using a free API and zero backend infrastructure. No GPU servers, no model hosting, no DevOps. Just HTML, JavaScript, and one API endpoint. This tutorial shows you exactly how, from a minimal working prototype to a polished React application.
What You Will Build
By the end of this tutorial, you will have a working web app where users type a text prompt and receive AI-generated images. The app will include a prompt input, a generate button, a loading state, image display, and a download button. It will work on desktop and mobile, and it costs nothing to host on any static hosting service.
Step 1: The Minimal Version (5 Minutes)
Create a single HTML file with a text input, a button, and a container for the result. Wire up the button to call the ZSky AI free image generation API using fetch, convert the response to a blob URL, and create an img element to display it. That is the entire app: one input, one fetch call, one image element.
Step 2: The API Call
Here is the core function that calls the API and displays the generated image:
async function generate() {
const prompt = document.getElementById("prompt").value;
if (!prompt.trim()) return;
const result = document.getElementById("result");
result.textContent = "Generating...";
const response = await fetch("https://zsky.ai/api/v1/image/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt, width: 1024, height: 1024 })
});
const blob = await response.blob();
const url = URL.createObjectURL(blob);
// Clear container and display image
result.textContent = "";
const img = document.createElement("img");
img.src = url;
img.alt = "AI generated image";
result.appendChild(img);
}
Open that file in your browser. Type a prompt. Click generate. You now have a working AI image app. Everything else in this tutorial is polish.
Step 3: Adding Loading States and Error Handling
A production app needs visual feedback during generation and graceful error handling:
async function generate() {
const prompt = document.getElementById("prompt").value;
if (!prompt.trim()) return;
const btn = document.querySelector("button");
const result = document.getElementById("result");
btn.disabled = true;
btn.textContent = "Generating...";
result.textContent = "Please wait...";
try {
const response = await fetch("https://zsky.ai/api/v1/image/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt, width: 1024, height: 1024 })
});
if (!response.ok) throw new Error("Generation failed");
const blob = await response.blob();
const url = URL.createObjectURL(blob);
result.textContent = "";
const img = document.createElement("img");
img.src = url;
result.appendChild(img);
const link = document.createElement("a");
link.href = url;
link.download = "generated.png";
link.textContent = "Download";
result.appendChild(link);
} catch (err) {
result.textContent = "Something went wrong. Try again.";
} finally {
btn.disabled = false;
btn.textContent = "Generate";
}
}
Step 4: React Component Version
For React apps, here is a complete component that integrates the free AI image API:
import { useState } from "react";
export function AIImageGenerator() {
const [prompt, setPrompt] = useState("");
const [imageUrl, setImageUrl] = useState(null);
const [loading, setLoading] = useState(false);
const generate = async () => {
if (!prompt.trim() || loading) return;
setLoading(true);
setImageUrl(null);
try {
const res = await fetch("https://zsky.ai/api/v1/image/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt, width: 1024, height: 1024 }),
});
const blob = await res.blob();
setImageUrl(URL.createObjectURL(blob));
} catch {
alert("Generation failed. Please try again.");
} finally {
setLoading(false);
}
};
return (
<div>
<input
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
placeholder="Describe your image..."
onKeyDown={(e) => e.key === "Enter" && generate()}
/>
<button onClick={generate} disabled={loading}>
{loading ? "Generating..." : "Generate"}
</button>
{imageUrl && <img src={imageUrl} alt="AI generated" />}
</div>
);
}
Try the API Behind This Tutorial
Generate images, edit photos, and create videos. Free API, free signup, no credit card.
Start Building Free →Step 5: Adding Image Editing
Once users can generate images, they will want to edit them. Add the image editing API to let users refine their results with text instructions, background removal, and style transfer. The editing endpoints accept the generated image as input and return the modified version.
Step 6: Deploying for Free
Since your app is entirely client-side, you can deploy it for free on any static hosting platform:
- Vercel — Push to GitHub and deploy automatically
- Netlify — Drag and drop your folder to deploy
- GitHub Pages — Enable Pages in your repository settings
- Cloudflare Pages — Connect your repo for instant deploys
All of these options are free for static sites. Your AI image app will have zero hosting costs and zero API costs on the free tier.
Monetization Ideas
Once your app has users, there are several ways to monetize it:
- Premium prompts — Sell curated prompt packs for specific use cases
- Higher resolution — Offer upgraded resolution through paid tiers
- Batch generation — Charge for generating multiple images at once
- White-label — Offer your app as a service for other businesses
For a deeper look at costs, read our AI API pricing comparison to understand how costs scale as your user base grows.
Frequently Asked Questions
Do I need a backend to build an AI image app?
No. With the ZSky AI free API, you can call the image generation endpoint directly from client-side JavaScript. The API handles CORS and returns images directly, so a static HTML page is all you need to get started.
How long does it take to build an AI image generation app?
Using the ZSky AI free API, you can have a working AI image generator running in under 30 minutes. The minimal version requires only an HTML file with a text input, a button, and a fetch call to the API endpoint.
Can I monetize an app built with the free AI image API?
Yes. The free API tier allows commercial use. Many developers build apps on the free tier for validation, then upgrade to paid tiers as their user base grows.
What frameworks work best with the AI image API?
The API works with any framework since it is a standard REST API. React, Next.js, Vue, Svelte, plain HTML, mobile apps, and server-side languages all work equally well.
Your AI Image App Starts Here
Free API. Zero infrastructure. Ship your first AI-powered app today.
Get Started Free →