Skip to main content

OpenAI CLI Cheatsheet

The OpenAI CLI is the most direct tool for interacting with the OpenAI API. Install the `openai` Python package, set your API key via `OPENAI_API_KEY`, and start using chat completions, image generation (DALL-E), audio transcription/synthesis (Whisper/TTS), embeddings, file management, and fine-tuning — all from the command line.

Updated: 2026-07-20·38 commands

Quick Start

``bash # Install pip install openai

# Set API Key export OPENAI_API_KEY=sk-proj-xxx

# List available models openai api models.list

# Basic chat openai api chat.completions.create -m gpt-4o -g user "Hello!"

# Stream a response openai api chat.completions.create -m gpt-4o -g user "Tell me a story" --stream

# Generate an image openai api images.generate -p "A cat astronaut on Mars" `

Authentication

The CLI authenticates via the OPENAI_API_KEY environment variable. You can also pass -k to override temporarily. For Azure OpenAI, use -t azure with Azure-specific flags.

Chat Completions

The core feature. Use openai api chat.completions.create with -m for model and -g for messages (can be specified multiple times for multi-turn). System prompt: use -g system 'instructions'. Streaming: add --stream.

Image Generation (DALL-E)

Use openai api images.generate with -p (prompt), -n (count, 1-10), and -s (size: 1024x1024, 1792x1024, etc.). Edit existing images with openai api images.edit.

Audio (Whisper & TTS)

Transcribe with openai api audio.transcriptions.create -f audio.mp3. Translate non-English to English with openai api audio.translations.create. Generate speech with openai api audio.speech.create --input "Hello" --voice alloy.

Embeddings

Create text embeddings for RAG and semantic search with openai api embeddings.create -m text-embedding-3-small -i "Your text".

Fine-tuning

Upload training data → create job → monitor status → use the fine-tuned model ID like any other model.

File Management

Files are used for fine-tuning and batch processing. Manage them with openai api files.list, files.create, files.retrieve, and files.delete`.

Startup & Modes(12)

CommandLevel
openai --help
Show help information
Basic
openai -k
Specify API key (overrides env var temporarily)
Basic
openai -b
Specify API base URL (compatible with third-party APIs)
Intermediate
openai -o
Specify organization ID
Intermediate
export OPENAI_API_KEY
Set API key environment variable
Basic
export OPENAI_BASE_URL
Set custom API endpoint (third-party compatible)
Intermediate
openai api models.list
List all available models
Basic
openai api models.retrieve
Retrieve detailed info about a specific model
Basic
openai api moderations.create
Check content policy compliance
Intermediate
openai api completions.create
Create text completion (legacy API)
Intermediate
curl -X POST https://api.openai.com/v1/chat/completions
Call Chat Completions API with curl
Intermediate
openai -V
Check openai CLI version
Basic

Chat Commands(8)

CommandLevel
openai api chat.completions.create
Create a chat completion (requires model and messages)
Basic
openai api chat.completions.create -m
Specify model for chat
Basic
openai api chat.completions.create -g
Add multi-turn messages (use multiple times)
Basic
openai api chat.completions.create -g system
Set system prompt (system message)
Intermediate
openai api chat.completions.create --stream
Stream chat completion output
Intermediate
openai api chat.completions.create -t
Set temperature (0-2, default 1)
Intermediate
openai api chat.completions.create -M
Set maximum output tokens
Intermediate
openai api chat.completions.create -n
Generate multiple responses to choose from
Intermediate

ai-image(4)

CommandLevel
openai api images.generate
Generate images from text (DALL-E)
Basic
openai api images.generate -p
Specify image prompt
Basic
openai api images.generate -s
Specify image size
Basic
openai api images.edit
Edit existing image (based on mask)
Expert

ai-audio(3)

CommandLevel
openai api audio.transcriptions.create
Transcribe audio to text (Whisper)
Basic
openai api audio.translations.create
Translate non-English audio to English
Basic
openai api audio.speech.create
Convert text to speech (TTS)
Basic

ai-embedding(1)

CommandLevel
openai api embeddings.create
Create text embeddings
Intermediate

File Management(4)

CommandLevel
openai api files.list
List uploaded files
Basic
openai api files.create
Upload a file (for fine-tuning or batch processing)
Intermediate
openai api files.retrieve
Retrieve file details
Basic
openai api files.delete
Delete an uploaded file
Basic

ai-training(6)

CommandLevel
openai api fine_tuning.jobs.create
Create a fine-tuning job
Expert
openai api fine_tuning.jobs.list
List all fine-tuning jobs
Intermediate
openai api fine_tuning.jobs.retrieve
Check fine-tuning job status
Intermediate
openai api fine_tuning.jobs.cancel
Cancel a running fine-tuning job
Intermediate
openai api fine_tuning.jobs.list_events
View fine-tuning job event logs
Intermediate
openai tools fine_tunes.prepare_data
Validate and prepare fine-tuning data file
Expert

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-20.