# OpenAI CLI

> The official command-line tool for calling the OpenAI REST API from a terminal or shell scripts.

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.

## 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

## Integrations
OpenAI API, Homebrew, Go, jq, OpenAI Terraform provider

## Platforms
WINDOWS, MACOS, LINUX, API, CLI

## Pricing
Open Source

## Version
v1.42.1

## Links
- Website: https://github.com/openai/openai-cli
- Documentation: https://github.com/openai/openai-cli/blob/main/docs/cli-reference.md
- Repository: https://github.com/openai/openai-cli
- EveryDev.ai: https://www.everydev.ai/tools/openai-cli
