Image caption generator template
- React
- Vite
Upload an image and get a one-sentence description, for alt text, tagging or search.
A React app that describes images. Drop in a JPG, PNG or GIF and get a one-sentence caption of what’s in it, then copy it. Recent captions stay on screen for comparison. Use it to write alt text for a site, tag a photo library, or make uploaded images searchable.

What it does
- Drag, drop, caption
- Drop an image or browse for one, preview it, and generate a caption in one click.
- Ready for alt text
- Captions are short plain sentences, and a Copy button puts them on your clipboard.
- Checks uploads first
- The function only accepts JPG, PNG or GIF images of 4 MB or less, within Vercel’s request limit.
- Keeps your key private
- The page calls a Vercel function in api/, which holds the key, checks the input and limits each visitor to 10 captions a minute.
- Runs locally in one command
- npm run dev serves the page and runs the api/ functions together, the same way Vercel does, with no CLI to install.
How it works
The Vercel function: it checks the upload and sends it to Image Caption.
import { guard, callApi, respond, fail } from '../lib/apiverve.js';
// Vercel caps a function's request body at 4.5 MB, so uploads stop at 4 MB.
const MAX_BYTES = 4 * 1024 * 1024;
const TYPES = ['image/jpeg', 'image/png', 'image/gif'];
/** POST /api/caption (multipart, field "image"): a one-sentence description of the image. */
export async function POST(request) {
const blocked = guard(request);
if (blocked) return blocked;
const form = await request.formData().catch(() => null);
const image = form?.get('image');
if (!image || typeof image === 'string') return fail('Choose an image to caption');
if (!TYPES.includes(image.type)) return fail('Use a JPG, PNG or GIF image');
if (image.size > MAX_BYTES) return fail('Images must be 4 MB or smaller');
const upload = new FormData();
upload.append('image', image, image.name || 'image');
return respond(() => callApi('imagecaption', { form: upload }));
}Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - Open your app
Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.
Try the Image Caption API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"caption": "A golden retriever running through a grassy field on a sunny day"
}
}