Credentials. Your API key is billed per request; keep it in the setup guide or a secret manager, never in a script you commit.
Who it is forA developer or designer who needs a few generated images for a mockup and does not want to open a web app.
The problemGenerating an image through the API usually means writing a script just to save the file.
The outcomeImages generated from a prompt and saved to a folder, with their paths printed.
What you need first
- An OpenAI API key (OPENAI_API_KEY); admin endpoints need OPENAI_ADMIN_KEY
- Homebrew, Go 1.26 or later, or a prebuilt binary from GitHub Releases
- Optional: jq for parsing JSON output
Steps
- Install with
brew install openai/tools/openai - Run
openai help setupto enter your API key safely - Run
openai images generate --prompt "A tiny orange robot watering a houseplant"with your own prompt - Find the files in ~/Downloads/gpt-images/, or pass
--output-diror--nameto choose where they go - Run
openai images generate --helpfor editing and model selection options
Prompt for your agent
Install openai/openai-cli with Homebrew, run `openai help setup`, then generate <n> images for <prompt> into <folder> with `openai images generate --prompt ... --output-dir <folder>` and list the saved paths.
Caveat.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for openai/openai-cli and "Generate and save images from your terminal with the OpenAI CLI"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer