# AI use cases for OpenAI CLI (openai/openai-cli)

Repo: [openai/openai-cli](https://github.com/openai/openai-cli) | Use cases: 3 | Page: https://dedupedai.com/use-cases/openai-openai-cli/

OpenAI CLI is the official command-line tool for the OpenAI REST API. It calls the API from your terminal or shell scripts: generate images, upload and download files, submit batches, export API data as JSON or JSONL, and read organization usage with an admin key.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Generate and save images from your terminal with the OpenAI CLI: https://dedupedai.com/use-cases/openai-openai-cli/generate-images-from-the-terminal-with-openai-cli/
- Run a batch of OpenAI requests from a JSONL file: https://dedupedai.com/use-cases/openai-openai-cli/run-a-batch-of-openai-requests-from-a-jsonl-file/
- Export OpenAI models, files and usage as JSON for your scripts: https://dedupedai.com/use-cases/openai-openai-cli/export-openai-api-data-for-scripts/

## How to generate and save images from your terminal with the OpenAI CLI with OpenAI CLI

Repo: [openai/openai-cli](https://github.com/openai/openai-cli) | Difficulty: Beginner | Time: 10 minutes | Basis: From the README

Install the official OpenAI CLI and make images with one command, saved straight to disk.

**Who it is for:** A developer or designer who needs a few generated images for a mockup and does not want to open a web app.

**The problem:** Generating an image through the API usually means writing a script just to save the file.

**The outcome:** Images generated from a prompt and saved to a folder, with their paths printed.

### Steps

1. Install with `brew install openai/tools/openai`
2. Run `openai help setup` to enter your API key safely
3. Run `openai images generate --prompt "A tiny orange robot watering a houseplant"` with your own prompt
4. Find the files in ~/Downloads/gpt-images/, or pass `--output-dir` or `--name` to choose where they go
5. Run `openai images generate --help` for editing and model selection options

### Prompt to paste into your agent

```text
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



Risk, credentials: Your API key is billed per request; keep it in the setup guide or a secret manager, never in a script you commit.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/openai-openai-cli/generate-images-from-the-terminal-with-openai-cli/

## How to run a batch of OpenAI requests from a JSONL file with OpenAI CLI

Repo: [openai/openai-cli](https://github.com/openai/openai-cli) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Upload a JSONL file of requests, create a batch, wait for it and download the results.

**Who it is for:** A data engineer who needs to send thousands of prompts and can wait up to a day for cheaper batch processing.

**The problem:** Submitting and polling the Batch API by hand takes several scripts and careful ID tracking.

**The outcome:** A finished batch with its result files downloaded to a local folder.

### Steps

1. Prepare requests.jsonl (the batch guide includes a sample)
2. Run `openai files upload requests.jsonl --purpose batch` and note the returned file ID
3. Create the batch with `openai batches create --input-file-id` plus your file ID, `--endpoint /v1/responses --completion-window 24h`
4. Run `openai batches wait batch_example --output-dir ./results` with your batch ID
5. Check the result files and the failed requests section of the batch guide

### Prompt to paste into your agent

```text
Use openai/openai-cli to upload <requests.jsonl> with `--purpose batch`, create a batch on /v1/responses with a 24h window, wait for it with `openai batches wait`, and save results to ./results. Report how many requests failed.
```

### Caveat



Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/openai-openai-cli/run-a-batch-of-openai-requests-from-a-jsonl-file/

## How to export OpenAI models, files and usage as JSON for your scripts with OpenAI CLI

Repo: [openai/openai-cli](https://github.com/openai/openai-cli) | Difficulty: Intermediate | Time: 20 minutes | Basis: From the README

List models and files as JSON or JSONL, extract fields, and pull organization usage with an admin key.

**Who it is for:** A platform engineer who audits API usage and stored files across an organization.

**The problem:** The default readable output is not something a script can parse reliably.

**The outcome:** Clean JSON or JSONL exports you can feed into jq, a spreadsheet or a monitoring job.

### Steps

1. Run `openai models list --format jsonl | jq '.id'` to list model IDs
2. Run `openai files list --format json > files.json` to export your files
3. Use `--transform` with GJSON syntax to pull single fields, for example `openai files get file-example --transform filename --raw-output`
4. Set OPENAI_ADMIN_KEY and run `openai admin organization usage completions` with `--start-time`, `--end-time` and `--bucket-width 1d`
5. Check each command's exit status before trusting a redirected file

### Prompt to paste into your agent

```text
With openai/openai-cli, export my models and files as JSON, then pull completions usage for <date range> with the admin usage command and summarize it per day. Check exit codes before using any output file.
```

### Caveat



Risk, credentials: Admin keys see the whole organization; use them only in trusted scripts, and sanitize --debug logs before sharing.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/openai-openai-cli/export-openai-api-data-for-scripts/
