Engineer & Writer

Halloween is fun, and this is that time of the year when you can bring out your creative juices—be it for decorating your house or dressing yourself for the occasion. But it’s 2025, and we have a little friend that can help us come up with ideas when we are out of them (if you haven’t guessed it already, yes, I am talking about AI).
I built a fun app where you can describe your vibe, and it will visualize an outfit for you.

In this article, we will see how you can use OpenAI’s gpt-image-1 model with the help of DigitalOcean’s Serverless Inference API to build applications like this.
After reading this article, you will learn how:
In case you missed it, the Gradient AI Platform has a lot of fresh additions including text-to-image model support from OpenAI, image and audio models from fal and a lot more. For all these recent additions, we will be using the Serverless Inference API.
So what is Serverless Inference?
Serverless inferencing is a way to deploy and serve machine learning models without having to worry about the infrastructure. Using Serverless inferencing you don’t have to worry about provisioning, scaling, or maintaining servers and you can focus on the AI application logic and model performance. If you would like to read more about serverless inferencing, how it differs from server-based inferencing and the benefits, read our serverless inferencing tutorial.
How DigitalOcean supports Serverless Inference:
DigitalOcean’s Gradient™ AI Platform Serverless inference gives developers low-level access to powerful AI models from OpenAI, Anthropic Claude, and Llama through a simple API with zero infrastructure management. It offers a stateless and flexible approach that makes it easy to integrate with your application logic without having to create any agent and control the AI-integration with prompt engineering.

The costume generator is a simple application. If I had to break down the application flow in steps, here’s how it works:
Generate Costume Idea button hits the serverless inference API.png)
Go to the DigitalOcean Control Panel, then from the left pane go to Agent Platform → Serverless Inference → Create Model Access Key → Give it a name and then click on Create. Copy this key and save it on your .env file as shown below:
DIGITAL_OCEAN_MODEL_ACCESS_KEY=your_digital_ocean_api_key_here
This API key will now give you access to all of the below models, that you can call and integrate on your application:

When you click the “Generate Costume Idea” button:
The code below handles the prompt enhancement and API call:
const { prompt, style, variation } = await request.json();
// Build the prompt with style-specific modifiers
const stylePrompts: Record<string, string> = {
  cartoon: 'cartoon style, colorful, playful, kid-friendly illustration',
  realistic: 'photorealistic, detailed, professional photography, natural lighting',
  'spooky-glam': 'high fashion, glamorous, elegant with dark themes, dramatic lighting, editorial style',
};
const stylePrompt = stylePrompts[style || 'cartoon'] || stylePrompts.cartoon;
// Add variations for "try again" - randomize pose and background
const poses = ['standing', 'in action pose', 'striking a dramatic pose', 'in a dynamic position', 'posing confidently'];
const backgrounds = ['studio background', 'dark moody background', 'gradient background', 'minimal background', 'theatrical background'];
const colors = ['vibrant colors', 'muted tones', 'bold colors', 'rich colors', 'striking colors'];
const randomPose = poses[Math.floor(Math.random() * poses.length)];
const randomBackground = variation ? backgrounds[Math.floor(Math.random() * backgrounds.length)] : 'studio background';
const randomColor = variation ? colors[Math.floor(Math.random() * colors.length)] : '';
const fullPrompt = A person wearing a complete Halloween costume as a "${prompt}", ${randomPose}. The costume should be the main focus and fully wearable. Professional photography on ${randomBackground}. ${stylePrompt}. Full body visible, showcasing the complete costume design. ${randomColor}. High quality, detailed.;
const response = await fetch('https://inference.do-ai.run/v1/images/generations', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${apiKey}`,
  },
  body: JSON.stringify({
    model: 'openai-gpt-image-1',
    prompt: fullPrompt,
    size: '1024x1024',
    n: 1,
  }),
});
const data = await response.json();
return NextResponse.json({
  image: data.data[0].b64_json,
  url: data.data[0].url,
});
How it works:
The endpoint starts with the user’s input (like “mysterious vampire”) and builds a structured prompt. It applies style modifiers based on the selected style (cartoon, realistic, or spooky-glam). When the user requests a variation (clicking “Try Again”), it randomizes poses, backgrounds, and color schemes to generate different results.
The enhanced prompt is sent to DigitalOcean’s Serverless Inference API endpoint at inference.do-ai.run/v1/images/generations with the openai-gpt-image-1 model.
Here’s how the response structure looks like: The endpoint returns a JSON response with:
Here’s an example JSON:
{
  "image": "iVBORw0KGgoAAAANSUhEUgAA...",
  "url": "https://cdn.do-ai.run/images/abc123xyz.png"
}
The b64_json field contains the complete image as a base64 string, which you can decode and display directly using an <img> tag with src=“data:image/png;base64,{b64_json}”, or you can use the url field for faster loading. This structured response is then passed to the frontend to display the generated costume image to the user.
You can find the complete code in the generate-costume/route.ts file.
You can also test the Serverless Inference API endpoint directly using curl to verify your API key and payload format before integrating with the frontend:
curl https://inference.do-ai.run/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_DIGITAL_OCEAN_MODEL_ACCESS_KEY" \
  -d '{
    "model": "openai-gpt-image-1",
    "prompt": "A person wearing a complete Halloween costume as a mysterious vampire, standing. Professional photography on studio background. High quality, detailed.",
    "n": 1,
    "size": "1024x1024"
  }'
You can use this to validate authentication and confirm the API is responding correctly before wiring it into your application.
And that’s how you can very easily build a text-to-image AI-powered application using DigitalOcean’s Serverless Inference API.
The Halloween costume generator application is an example of how you can quickly build AI applications with DigitalOcean’s Gradient AI Platform. In just two main steps: getting your API key, and processing the generation logic, you have a fully functional text-to-image application without having to manage any infrastructure.
Here’s what you can do next:
What if you combined text generation with image generation? Maybe an app that writes costume descriptions AND visualizes them? The cool part about serverless inference is that you don’t have to worry about the infrastructure scaling during traffic spikes or maintaining servers.
You can focus on making your app better and adding features that users actually care about.
You can find the complete code for this project on GitHub. Feel free to fork it, break it, improve it, whatever helps you learn!
If you build something cool with this or have questions, I’d love to hear about it.
Happy building, and Happy Halloween! 🎃
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
A Developer Advocate by profession. I like to build with Cloud, GenAI and can build beautiful websites using JavaScript.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.