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 the cloud provider's Serverless Inference API to build applications like this.

Key-takeaways

After reading this article, you will learn how:

  • Serverless inferencing works
  • How you can make use of image models with the help of the cloud provider’s Serverless Inference API to build text-to-image applications.

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 the cloud provider supports Serverless Inference:

the cloud provider'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.

Building the Halloween costume generator

image illustration for: Building the Halloween costume generator

The costume generator is a simple application. If I had to break down the application flow in steps, here’s how it works:

  • We have a frontend (I took inspiration from Figma template) where users input the vibe of the costume they want.
  • The Generate Costume Idea button hits the serverless inference API
  • The API then converts the prompt (text) to costume ideas (image) using the openai-gpt-image-1 model.

Step 1: Getting the API key

Go to the the cloud provider 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:

				
					cloud-provider_MODEL_ACCESS_KEY=your_cloud-provider_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:

Step 2 - Processing the costume generation

When you click the "Generate Costume Idea" button:

  • The request hits the Next.js API route at /api/generate-costume
  • The endpoint extracts the user's prompt and style preferences
  • It enhances the prompt with style modifiers and composition details
  • Loads the openai-gpt-image-1 model via the cloud provider's Serverless Inference API
  • Generates a high-quality 1024×1024 image
  • Returns the result as JSON with base64 image data and a URL

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 the cloud provider'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:

  • image: Base64-encoded image data (b64_json) that can be directly embedded in the frontend
  • url: Direct URL to the generated image for immediate display

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.

Step 3 - Testing the API directly

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_the cloud provider_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 the cloud provider’s Serverless Inference API.

Wrapping up

The Halloween costume generator application is an example of how you can quickly build AI applications with the cloud provider'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:

  • Try it yourself: Grab your API key from the the cloud provider Control Panel and start experimenting.
  • Get creative: This isn't just for Halloween costumes. You can adapt this same approach to generate product designs, visualize room decor ideas, or create character illustrations for your game.
  • Mix and match models: The API key gives you access to multiple models (GPT, Claude, Llama, Fal).

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! 🎃