DEV Community

Cathy Lai
Cathy Lai

Posted on

Image Generation with OpenAI (Step‑by‑Step Tutorial)

This guide focuses only on generating images with OpenAI for your
PlanetFam quiz app. We'll build a Node.js CLI that: - Takes a
country (+ dishes/landmarks) as input\

  • Calls OpenAI's image API (defaults to dall-e-3)\
  • Outputs a 9:16 vertical WebP (~100 KB)\
  • Updates a small manifest.json for your app to read

Why dall-e-3? It's high‑quality and doesn't require org
verification. You can switch to gpt-image-1 later (requires
verification) by passing a flag/env var.


1) Project setup

mkdir planetfam-scripts && cd planetfam-scripts
npm init -y
npm install openai sharp fs-extra yargs
Enter fullscreen mode Exit fullscreen mode

Set your API key (macOS/Linux):

export OPENAI_API_KEY=sk-...yourkey...
Enter fullscreen mode Exit fullscreen mode

Windows (Powershell):

$env:OPENAI_API_KEY="sk-...yourkey..."
Enter fullscreen mode Exit fullscreen mode

Top comments (0)