OpenAI CLI: Install It and Call the OpenAI API From Your Terminal
The OpenAI CLI is OpenAI's official command-line tool for the OpenAI REST API. You install one openai binary, set OPENAI_API_KEY , and call the API from your terminal or a shell script: openai responses create , openai files upload , openai batches create , openai images generate . It is not Codex

Posted on Oct 28 • Originally published at apidog.com
The OpenAI CLI is OpenAI's official command-line tool for the OpenAI REST API. You install one openai binary, set OPENAI_API_KEY, and call the API from your terminal or a shell script: openai responses create, openai files upload, openai batches create, openai images generate. It is not Codex CLI. Codex is a coding agent; openai sends one API request per command.
This guide covers install, auth, the first commands worth running, and how it compares with Codex CLI and the old openai command the Python SDK put on your PATH. Every command and output below comes from version 1.44.1, installed and run on October 28, 2026.
The OpenAI CLI is an open-source Go binary, published by OpenAI at github.com/openai/openai-cli under the Apache 2.0 license. Its commands mirror the API's resources ( responses, files, batches, images, audio, vector-stores, admin ), so anything you'd send with curl or an SDK becomes one terminal command with flags.
It isn't brand new. Version 1.0.0 shipped on May 5, 2026, and the project has cut 99 releases since; 1.44.1 landed on October 27, 2026. So treat it as a mature tool you may have missed, not a launch.
The help groups commands by job: generate content ( responses, chat, images, audio, videos ), data and retrieval ( files, uploads, vector-stores, embeddings ), models and jobs, administration, and a set of local tools that never touch the network. Help itself needs no API key and no connection, which makes openai <command> --help the fastest way to learn the flags.
It suits developers testing a prompt without writing a script, ops people who want file uploads and batches in a cron job, and coding agents that need a documented interface instead of hand-rolled curl.
You have three install routes, all listed in the project README:
brew install openai/tools/openai Enter fullscreen mode Exit fullscreen mode Go. Requires Go 1.26 or later. go install 'github.com/openai/openai-cli/cmd/openai@latest' export PATH = " $PATH: $( go env GOPATH ) /bin" Enter fullscreen mode Exit fullscreen mode Self-managed release installs can update themselves during interactive runs. If you pin versions in CI, set OPENAI_CLI_NO_AUTO_UPDATE=1 to stop automatic installs, or OPENAI_CLI_NO_UPDATE_CHECK=1 to switch off update checks entirely. Homebrew and Go installs keep their update notices but leave upgrades to the package manager.
The CLI reads a standard API key from OPENAI_API_KEY (or the --api-key flag, which you should avoid because it lands in shell history). If you don't have one yet, our guide to getting an OpenAI API key walks through it.
The quickest setup is the built-in guide:
openai help setup Enter fullscreen mode Exit fullscreen mode It points you to the API keys page and gives you a read -rs OPENAI_API_KEY line for Bash or zsh, so the key is typed hidden and never echoed.
Forget the key and you get a clear, scriptable failure. This is the real output with no key set:
It exits with status 1 and tells you exactly where a key can come from. Add --format-error json when a script needs the raw error body.
The command shape follows the API: openai <resource> [subresource...] <command> [flags...]. These are the commands that earn their place in a toolbox.
openai responses create \ --model gpt-5.5 \ --input "Say this is a test" Enter fullscreen mode Exit fullscreen mode Long prompts don't need escaping. JSON input flags read from a file with @path:
openai responses create --model gpt-5.5 --input @prompt.txt Enter fullscreen mode Exit fullscreen mode If you pipe JSON or YAML from a source you don't trust, set OPENAI_UNTRUSTED_STDIN=1 so that input can't trigger local file reads.
openai files upload report.txt --purpose user_data openai files get file-example openai files download file-example --output downloaded-report.txt Enter fullscreen mode Exit fullscreen mode Run a batch Put one request per line in requests.jsonl, each with a unique custom_id, then:
openai files upload requests.jsonl --purpose batch openai batches create --input-file-id file-example \ --endpoint /v1/responses --completion-window 24h openai batches wait batch_example --output-dir./results Enter fullscreen mode Exit fullscreen mode batches wait polls until the batch finishes and saves the result files, which removes the polling loop you'd otherwise write. The project's batch guide lists the current limits as 50,000 requests and 200 MB per input file, with a 24h completion window. Batch pricing differs from synchronous calls; see our OpenAI API pricing breakdown before you queue a large job.
The tokenizer command runs fully offline: no credentials, no network, no saved input.
The default encoding is o200k_base, and openai tokenizer encodings lists the others ( cl100k_base, plus two legacy ones). The help is honest about limits: a plain-text count excludes request structure and multimodal inputs, so it isn't a billing figure. For a server-side count, use openai responses input-tokens count.
The default output is readable text, even when piped. Ask for data explicitly:
openai models list --format jsonl | jq '.id' openai files list --format json > files.json openai files get file-example --transform filename --raw-output Enter fullscreen mode Exit fullscreen mode --format accepts auto, text, json, jsonl, yaml, explore (an interactive JSON viewer) and pretty. --transform pulls fields with GJSON syntax, and jq handles anything fancier. Always check the exit status before trusting a redirected file: a failed request can leave a partial one behind.
When a call misbehaves, --debug adds per-attempt HTTP timing; scrub its logs before sharing them. If you're hitting 429s, our OpenAI rate limits guide explains the tiers.
Three tools share a vendor and two share a name. This is the short version:
Run openai codex and the OpenAI CLI prints Codex install commands itself, noting it's a separate tool with its own sign-in. Our Codex CLI guide covers the agent side, and the source lives at github.com/openai/codex.
The openai Python package also installs a binary named openai. If you've ever run pip install openai, you may have two:
On this Mac the Python one reports openai 2.30.0 and offers api, tools, migrate and grit subcommands; the Go one reports openai version 1.44.1. Whichever directory comes first on your PATH wins. Run which -a openai and openai --version after you install. If the output says openai version 1.44.1 (or newer), you have the right one. If it prints a bare version number like openai 2.30.0, reorder your PATH or call the new binary by its full path.
The OpenAI CLI makes calls to OpenAI. It doesn't know about your own API: the endpoints your app exposes on top of OpenAI, the environments you deploy to, or the assertions that prove a release didn't break anything. That's a different job, and it's where Apidog CLI comes in. You don't pick one over the other; most teams that ship an AI feature want both.
Better still, let your coding agent run both. Set up Apidog CLI once:
npm install -g apidog-cli@latest apidog login --with-token <YOUR_TOKEN> npx -y skills add https://apidog.com # pick your agent when prompted Enter fullscreen mode Exit fullscreen mode Then give your agent one [REDACTED PROMPT] Use the openai CLI to confirm my key works with one responses create call on gpt-5.5. Then import./openapi.yaml into Apidog project, create a test case for POST /v1/summarize that asserts a 200 and a non-empty "summary" field, run it against the staging environment and summarize any failures.
The agent checks the key with ` openai `, then works through Apidog CLI. It reads the schema before writing any payload, validates the file, and only then creates and runs the case: Enter fullscreen mode Exit fullscreen mode bash apidog import --project --format openapi --file./openapi.yaml apidog cli-schema get test-case-create apidog cli-schema validate test-case-create --file case.json apidog test-case create --project --file case.json apidog run --test-case --project -e -r cli,json