Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Installation

OpenAI CLI

The official command-line tool for the OpenAI REST API.

Install · Explore commands · CLI reference · Guides

OpenAI CLI terminal showing commands for images, files, batches, and JSON output

Looking for the coding agent? Use Codex CLI.

Installation

Installing with Homebrew

brew install openai/tools/openai

Installing a prebuilt binary

Open Assets for the release you want. Choose a release with a download for your system and processor.

System Release filename pattern
macOS *_macos_arm64.zip for Apple silicon or *_macos_amd64.zip for Intel
Linux *_linux_*.tar.gz for your processor
Windows *_windows_amd64.zip for 64-bit Intel or AMD, *_windows_arm64.zip for Arm64, or *_windows_386.zip for 32-bit Windows

Calculate the download’s SHA-256 with shasum -a 256 FILE (macOS), sha256sum FILE (Linux), or Get-FileHash -LiteralPath FILE (PowerShell). Replace FILE with the downloaded file’s path. Search build attestations for the full filename. Open the publish-release.yml result from refs/heads/main. Match the filename and SHA-256 under Subjects before installing.

macOS and Linux. Extract the archive. Put openai in $HOME/.local/bin. Create that directory if needed. Add it to your shell’s PATH if needed.

Windows. Choose Extract All. Put openai.exe in %LOCALAPPDATA%\Programs\OpenAI CLI. Open PowerShell in that folder and run .\openai.exe --version. Add the folder to your user Path. Open a new PowerShell window.

Linux packages. Install the matching .deb, .rpm, or .pkg.tar.zst file with your distribution’s package manager. On Alpine, use the verified tarball unless your system trusts the release .apk.

Installing with Go

With Go 1.26 or later, run:

go install github.com/openai/openai-cli/cmd/openai@latest

Add GOBIN to your PATH, or use the first GOPATH entry’s bin directory when GOBIN is empty. Run go env GOBIN GOPATH to see your settings.

Checking and upgrading

Run openai --version to check your installation. For an archive, replace the executable with the release you choose. For a Linux package, install the newer package. For Homebrew, run brew upgrade --cask openai/tools/openai. For Go, repeat the install command or replace latest with a release tag.

Upgrades are manual by default. On a supported private installation, run openai updates enable to turn on automatic upgrades. Run openai updates disable to return to manual upgrades.

Quickstart

Explore commands

Find a command by describing what you want to do. No API key needed.

openai explore

Try searching for count tokens offline. Use the arrow keys to highlight a command, then press Enter to select it.

Authentication

When you’re ready to make an API request, run the setup guide for your shell.

openai help setup

For scripts, supply OPENAI_API_KEY through your environment or secret manager. Create an API key

Things to try

Send a request

openai responses create --model gpt-5.5 --input "Say this is a test"

Generate an image and save it locally

openai images generate --prompt "A tiny orange robot watering a houseplant"

Images are saved to ~/Downloads/gpt-images/, and the command prints their paths. Use --output-dir for an existing destination directory or --name for a filename. Supported terminals can preview the result. See the image guide for editing, model selection, and preview settings.

Upload a file and retrieve it later

openai files upload report.txt --purpose user_data
openai files get file-example
openai files download file-example --output downloaded-report.txt

Use your own local file and replace file-example with the ID returned by the upload. See working with files for more examples.

Run requests in a batch

Submit a JSONL request file, then wait for the batch and download its results:

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

Replace the file and batch IDs with the returned IDs. The batch guide includes a sample requests.jsonl and explains result files and failed requests.

Export API data for a script

openai models list --format jsonl | jq '.id'
openai files list --format json > files.json

Choose --format json for a JSON document or --format jsonl for records. The default output is readable text, even in pipes. The first example uses jq.

Usage

Commands follow the API’s resources:

openai <resource> [subresource...] <command> [flags...]

Browse commands and options with help. Help needs no API key or network connection.

openai --help
openai images generate --help
openai admin organization --help

openai help COMMAND and openai COMMAND --help show the same page. Command groups list their available commands. Each action shows its usage, required inputs, and relevant flags. When an action has an example, help shows it before the flag descriptions. To read about one flag, append it after -h, as in openai responses create -h --stream. For every flag’s description, use openai help --all responses create. Existing colon-separated commands, such as openai admin:organization:usage completions, also work.

Admin requests

Admin endpoints use OPENAI_ADMIN_KEY, a separate admin API key. For example, retrieve one day of organization usage:

openai admin organization usage completions --start-time 1735689600 --end-time 1735776000 --bucket-width 1d

Output and errors

Successful JSON responses display readable text by default. Select a data format explicitly when parsing results. Use --transform to extract fields with GJSON syntax:

openai files get file-example --transform filename --raw-output

Errors go to stderr as readable summaries. Use --format-error json for API error details, or --transform-error to extract error fields. Explicit --format json, jsonl, raw, and yaml also apply to errors unless --format-error overrides them; --format-error text restores summaries. API error details and --debug logs can contain sensitive data: sanitize them before sharing.

--debug adds per-attempt HTTP timing. Add --debug-body for redacted JSON previews or --debug-sse --debug-event-timing for bounded stream diagnostics. See HTTP debugging for capture limits and timing boundaries.

Check the command’s exit status before using redirected results; a failed request can leave an incomplete output file. See reading command results for list formats, streaming, binary downloads, and error behavior.

File input

Binary uploads take a plain path. JSON input flags can read a value from a local file with @path:

openai files upload report.txt --purpose user_data
openai responses create --model gpt-5.5 --input @prompt.txt

For a complete request, responses create and chat completions create accept --request-file request.json. Use --request-file - to wait for a pipeline, including delayed producers. Run openai help piping for tokenizer, upload, and script examples.

Use OPENAI_UNTRUSTED_STDIN=1 when piping JSON or YAML from an untrusted source so input cannot cause local file reads. In that mode, provide upload paths explicitly as flags. See file arguments and encoding for escaping literal @ values, JSON/YAML input, and text or base64 encoding.

Shell shortcuts

Set up shell completion to complete commands and file paths. Command insertion lets you search examples with Ctrl+X, then Tab and insert them without running them.

The first eligible interactive run saves image-picker Tab shortcuts for future Bash, zsh, and fish sessions. Open a new terminal to use them. See setup and removal for requirements and opt-out. In PowerShell, press Enter after openai images generate to open the picker.

Guides

Task Guide
Generate, edit, save, and preview images Images
Upload and download files Files
Submit batches and collect results Batches
Create vector stores, upload files, and search Vector stores
Generate speech and work with audio Audio
Inspect and count tokens locally Tokenizer
Test webhook handling Webhooks
Parse results in scripts Output formats
Configure headers, mTLS, and file input CLI reference

Use the CLI from a coding agent

The optional OpenAI CLI skill helps a shell agent choose API commands and interpret their output. Install the CLI in the environment where the agent runs.

From your project, use GitHub CLI to install the skill from a tagged release that includes it:

gh skill install openai/openai-cli openai-cli --agent codex --scope project

Choose your agent with --agent. Options include claude-code, cursor, gemini-cli, and github-copilot. Run gh skill install --help for the full list. Use --scope user to share the skill across your projects.

For an unreleased checkout, use its local path instead:

gh skill install /path/to/openai-cli openai-cli --from-local --agent codex --scope project

For manual installation, copy the entire skills/openai-cli folder into the appropriate skills directory.

Agent Current project All projects for this user
Codex .agents/skills/ ~/.agents/skills/
Claude Code .claude/skills/ ~/.claude/skills/

Start a new agent session in the target project. For example, ask “Upload requests.jsonl to OpenAI for a future batch.”

Development

To install from source, follow the Go installation instructions.

scripts/run is a development helper for running the CLI from a cloned checkout:

./scripts/run --help

See the development instructions for its dependency, credential, path, and exit-status behavior.

To test against another OpenAI Go SDK version, use ./scripts/link:

./scripts/link github.com/org/repo@version
./scripts/link ../path/to/openai-go

With no arguments, it uses ../openai-go. See CONTRIBUTING.md for setup, checks, and repository structure.

Contributing

Please share bug reports and feature requests through GitHub issues. Pull requests are limited to repository collaborators; we do not accept pull requests from non-collaborators. See CONTRIBUTING.md for the contribution policy and development guide. See the security model for trust boundaries. For security vulnerabilities, follow SECURITY.md.

License

Copyright 2026 OpenAI

This project is licensed under the Apache License 2.0.