OpenAI CLI
The official command-line tool for calling the OpenAI REST API from a terminal or shell scripts.
At a Glance
About OpenAI CLI
OpenAI CLI is the official command-line tool for the OpenAI REST API, published by OpenAI as an Apache-2.0 open-source Go project. It lets users generate images, upload files, submit batches, and inspect API results from a terminal or shell script without writing an application. Prebuilt binaries are available for macOS, Linux, and Windows.
What It Is
OpenAI CLI exposes the OpenAI API as terminal commands that follow API resources, using the pattern openai <resource> [subresource...] <command> [flags...]. It is aimed at calling a specific API or putting API operations in scripts. The README distinguishes it from Codex CLI, which is a coding agent that reads and edits code in a project.
Workflows and Outputs
Documented workflows include generating images and saving them locally with optional terminal preview, uploading, retrieving and downloading files, and submitting JSONL batches then waiting for and downloading results. Other guides cover audio and speech generation, local token inspection and counting, and webhook testing. Admin endpoints are supported with a separate admin API key.
Output is readable text by default. Users can choose JSON, JSONL, raw or YAML formats, extract fields with GJSON syntax via --transform, and send errors to stderr in readable or JSON form. Debug flags add HTTP timing and redacted body previews.
Setup Path
Install from a prebuilt release binary, Homebrew, or go install (Go 1.26 or later). Authenticate by running the setup guide or by supplying OPENAI_API_KEY in the environment. Shell completion and a command-insertion feature for searching examples are available. Self-managed release installs can update automatically, and environment variables disable auto-update or update checks.
Community Discussions
Be the first to start a conversation about OpenAI CLI
Share your experience with OpenAI CLI, ask questions, or help others learn from your insights.
Pricing
Open Source
OpenAI CLI is licensed under Apache License 2.0; the CLI itself is free to use, while API calls require an OpenAI API key and are billed separately by the API.
- Licensed under Apache License 2.0
- Prebuilt binaries, Homebrew and Go installation
- Requires an OPENAI_API_KEY for API calls (external API usage costs)
Capabilities
Key Features
- Commands mirror OpenAI API resources
- Image generation with local saving and terminal preview
- File upload, retrieval and download
- Batch creation, waiting and result download
- Audio and speech generation
- Local tokenizer utilities
- Webhook testing
- Text, JSON, JSONL, raw and YAML output formats
- GJSON-based field extraction with --transform
- HTTP debug and timing flags
- Shell completion and command insertion
- Admin endpoint support via admin API key
- Automatic update handling for self-managed installs
