Prompt
How do I automate AI image generation for marketing assets using an API?
Latest observation
To automate AI image generation for marketing assets with an API, you typically build a workflow like this:
-
Create a text prompt from your marketing input
- Product name
- Audience
- Platform (Instagram, banner, email header, etc.)
- Brand style rules
- Required dimensions
-
Send the prompt to an image generation API
- The API returns one or more generated images, usually as URLs or base64 data.
-
Post-process the result
- Resize/crop to platform specs
- Add logo, headline, CTA, or legal text
- Run brand and safety checks
- Save to your DAM/CMS or cloud storage
-
Automate distribution
- Publish to ad tools, social schedulers, email systems, or internal review queues.
Basic API flow
Example request
If your image API accepts prompts, a typical request might look like:
curl -X POST https://api.your-image-provider.com/v1/images/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A modern, premium skincare ad for a hydrating serum, soft natural lighting, elegant minimal layout, pastel brand colors, product-centered composition, space for headline",
"size": "1024x1024",
"n": 1
}'
Example response
{
"created": 1710000000,
"data": [
{
"url": "https://cdn.example.com/generated/image123.png"
}
]
}
Then your app downloads the image and continues the workflow.
Recommended automation architecture
1. Prompt builder
Use a template system so marketing users can provide structured inputs instead of writing free-form prompts.
Example:
- Campaign: Summer Sale
- Product: Running shoes
- Audience: fitness enthusiasts
- Tone: energetic, premium
- Format: LinkedIn ad 1200x627
Prompt template:
Create a high-conversion LinkedIn ad image for {product} targeting {audience}. Style: {tone}. Include brand colors {colors}. Leave negative space for headline. No text in the image.
This makes outputs more consistent.
2. Asset generation service
A backend service handles:
- authentication
- prompt submission
- polling for completion if async
- error handling and retries
- storing outputs
If the image API is async, your service may:
- submit a job
- receive a job ID
- poll job status
- fetch final image URLs
3. Brand controls
For marketing assets, you’ll want guardrails:
- approved color palettes
- prompt constraints
- banned terms or themes
- human review for new campaigns
- automatic watermarking or metadata tags
- multiple variants for A/B testing
4. Post-processing pipeline
After generation, automate:
- crop/resize for each channel
- add CTA button and brand logo
- overlay text in design software or image libraries
- convert formats (PNG, JPG, WebP)
- compress for web
Tools often used:
- Pillow or Sharp for image manipulation
- FFmpeg if you later add motion assets
- Canva/Figma APIs if you want templated layouts
Example in Python
import requests
API_KEY = "YOUR_API_KEY"
url = "https://api.your-image-provider.com/v1/images/generate"
payload = {
"prompt": "A clean, high-end banner for a new productivity app, blue and white brand colors, modern workspace, minimal style, space for headline",
"size": "1200x628",
"n": 1
}
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
image_url = data["data"][0]["url"]
print("Generated image:", image_url)
Example in Node.js
const fetch = require('node-fetch');
async function generateImage() {
const res = await fetch('https://api.your-image-provider.com/v1/images/generate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'A premium e-commerce ad for wireless earbuds, clean studio lighting, dark background, product hero shot, space for text',
size: '1024x1024',
n: 1
})
});
if (!res.ok) throw new Error(`HTTP error ${res.status}`);
const json = await res.json();
console.log(json.data[0].url);
}
generateImage();
Practical marketing workflow
You can automate this end-to-end:
- Trigger: new campaign row added in Airtable/Notion/CRM
- Generate: call image API with campaign metadata
- Review: send to Slack/Teams for approval
- Publish: push approved image to social scheduler or ad platform
- Track: log asset IDs and performance metrics back into your system
Best practices
- Generate multiple variations per campaign
- Keep prompts structured and reusable
- Use aspect ratios per channel
- Store prompt + seed + model version for reproducibility
- Add human review before publishing externally
- Test for brand consistency and policy compliance
If you want to build this quickly
A simple stack could be:
- Backend: Python FastAPI or Node.js Express
- Queue: Celery, BullMQ, or AWS SQS
- Storage: S3 / GCS
- DB: Postgres
- Review UI: lightweight internal dashboard
- Automation: Zapier / Make / n8n for triggers
If you want, I can also help you with one of these:
- a full working Python or Node.js example
- an architecture diagram for the automation pipeline
- a prompt template system for marketing teams
- integration with a specific API like OpenAI, Stability, or Replicate