Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Generate one-sentence alt text for any image URL using Salesforce BLIP on Replicate with a Next.js API route.
Alt Image Generator is a Next.js boilerplate from Vercel's official examples that generates a one-sentence alt text description for any image URL using the Salesforce BLIP machine learning model running on Replicate.
The Alt Image Generator is a reference template that exposes a Next.js API route at /api/generate which takes an imageUrl query parameter and returns a one-sentence description of that image. It is part of the Vercel examples repository, a curated collection of examples and solutions. The template uses Salesforce's BLIP model through Replicate, meaning you get an AI image captioning service without managing your own ML infrastructure. The output is plain text suitable for use as an HTML alt attribute.
/api/generate that accepts an image URL via the imageUrl query parameter and returns a description. You can call it from the browser or with curl.REPLICATE_API_TOKEN in a .env.local file.REPLICATE_API_TOKEN environment variable.create-next-app with the pnpm package manager, then run pnpm dev to start the development server on http://localhost:3000.curl http://localhost:3000/api/generate?imageUrl=https://dub.sh/confpic.alt text for every uploaded image, improving accessibility compliance without manual work.imageUrl parameter.First, clone the template with pnpm create next-app --example https://github.com/vercel/examples/tree/main/solutions/alt-tag-generator. Then create a Replicate account and put your API key in .env.local. Run pnpm dev to start the server, then hit the API route with a curl command or by pasting the URL into a browser. The route sends the image URL to the BLIP model on Replicate and returns the generated sentence in the response.
It uses Salesforce's BLIP (Bootstrapping Language-Image Pre-training) model, which is a machine learning model built for image captioning. The model is accessed through Replicate's hosted API, so you do not need to install or run the model yourself.
Yes. The template relies on Replicate to run the BLIP model. After creating an account, you must place your API token in a .env.local file as REPLICATE_API_TOKEN before the API route can respond to requests.
After running pnpm dev, open your browser at http://localhost:3000/api/generate?imageUrl=https://dub.sh/confpic or run the curl command from the README. You can replace https://dub.sh/confpic with any direct image URL to see a different caption.
Yes. The README includes a one-click deploy button that creates a new Vercel project from the template, asks you to provide the REPLICATE_API_TOKEN environment variable, and spins up a live version of the API route.
The template itself is open source and free to clone. The Replicate API is a paid service beyond its free tier, so you will need to cover the cost of model inference based on Replicate's pricing.
