SuperAPI AI Directory

image-gen

Design & creation

View repository

Updated 10-15 19:49

About this skill

Image Gen

Generate images from text prompts using the OpenAI Images API (DALL-E 3) via curl. Requires an OPENAI_API_KEY environment variable.

Prerequisites

No CLI install needed — uses curl and jq (pre-installed on macOS/Linux).

Set up your API key:

export OPENAI_API_KEY="sk-..."
# Or add to ~/.zshrc / ~/.bashrc for persistence

Get a key: https://platform.openai.com/api-keys

Commands

Generate a single image (returns URL):

curl -s https://api.openai.com/v1/images/generations \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dall-e-3",
    "prompt": "A serene mountain lake at sunset, photorealistic",
    "n": 1,
    "size": "1024x1024",
    "quality": "standard"
  }' | jq -r '.data[0].url'

Generate HD image:

curl -s https://api.openai.com/v1/images/generations \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"dall-e-3","prompt":"<prompt>","n":1,"size":"1024x1024","quality":"hd"}' \
  | jq -r '.data[0].url'

Download generated image to file:

URL=$(curl -s https://api.openai.com/v1/images/generations \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"dall-e-3","prompt":"<prompt>","n":1,"size":"1024x1024","quality":"standard"}' \
  | jq -r '.data[0].url')
curl -s "$URL" -o workspace/image-output.png

Batch generate (loop):

PROMPTS=("prompt one" "prompt two" "prompt three")
for i in "${!PROMPTS[@]}"; do
  URL=$(curl -s https://api.openai.com/v1/images/generations \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d "{\"model\":\"dall-e-3\",\"prompt\":\"${PROMPTS[$i]}\",\"n\":1,\"size\":\"1024x1024\",\"quality\":\"standard\"}" \
    | jq -r '.data[0].url')
  curl -s "$URL" -o "workspace/image-$i.png"
  echo "Saved workspace/image-$i.png"
done

Size Options

Size Use Case
1024x1024 Square (default, social media)
1792x1024 Landscape (banners, thumbnails)
1024x1792 Portrait (stories, posters)

Usage Examples

Generate a social media card image:

# Prompt + download to workspace
URL=$(curl -s https://api.openai.com/v1/images/generations \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"dall-e-3","prompt":"Minimalist tech blog cover, dark background, glowing circuit pattern, 1080x1080","n":1,"size":"1024x1024","quality":"hd"}' \
  | jq -r '.data[0].url')
curl -s "$URL" -o workspace/social-card.png

Rules

  • Always check that OPENAI_API_KEY is set: [[ -z "$OPENAI_API_KEY" ]] && echo "OPENAI_API_KEY not set"
  • Never print the API key value in output
  • Default to dall-e-3, size 1024x1024, quality standard unless specified
  • Always download images to workspace/ directory; never just return raw URLs
  • Name output files descriptively: workspace/image-<slug>.png
  • For batch jobs, generate one at a time sequentially to avoid rate limits
  • Check API response for errors: jq '.error' before using the URL
  • Confirm completion with: "Generated image(s) → workspace/"
  • DALL-E 3 limit is n=1 per request; for multiple images, loop the request