VOOZH about

URL: https://www.scriptbyai.com/openai-cli/

⇱ OpenAI CLI: Run OpenAI API Calls from Your Terminal (Official)


Skip to content

The OpenAI CLI is the official command-line interface for the OpenAI REST API, written in Go and published by OpenAI as an open-source project. It enables your terminal to access OpenAI endpoints for text generation, file management, audio, images, and organization-level usage reporting.

You can use the CLI to send requests, inspect responses, and pull admin-level usage data from a shell. It can be useful for testing model behavior, scripting automated API workflows, and exploring endpoints before embedding them into a full application.

Features

  • Runs OpenAI REST API requests from the terminal with the openai command.
  • Uses a resource-based command structure: openai [resource] <command> [flags...].
  • Accepts text input and file arguments for supported API endpoints.
  • Outputs results in seven configurable formats: auto, explore, json, jsonl, pretty, raw, and yaml.
  • Uses GJSON syntax to transform response data directly in terminal output.
  • Passes files to the API with @filename syntax and automatic filetype detection for text and binary input.
  • Sends files as plain text with @file:// or base64-encoded data with @data://.
  • Accepts a standard API key for normal endpoints and an admin API key for admin endpoints.
  • Loads credentials and project settings from environment variables or inline flags.
  • Uses debug mode to show HTTP request and response details. You should not share debug logs if they contain private payloads or credentials.
  • Supports a custom base URL for alternate API backends.

OpenAI CLI vs OpenAI Codex CLI

OpenAI CLI and Codex CLI solve different developer problems. OpenAI CLI is the better fit when you want direct API access from shell commands. Codex CLI is the better fit when you want an AI coding agent that can inspect a project, edit code, and run terminal workflows.

CategoryOpenAI CLICodex CLI
Main purposeAPI calls from the terminal.Agentic coding from the terminal.
Best use caseScripts, API requests, admin usage checks, file-based API workflows.Code edits, repository inspection, code review, and terminal coding workflows.
Primary commandopenaicodex
InstallationHomebrew or Go install.npm, Homebrew cask, or release binary.
AuthenticationAPI key or admin API key.ChatGPT sign-in or API-key setup.
Coding agent behaviorNo built-in repository agent workflow.Runs as a local coding agent.
Output controlOutput formats and GJSON transforms.Agent sessions, code changes, and local workflow control.
Best reader choiceUse it to call OpenAI APIs directly.Use it to work on code with an AI agent.

How to Use It

1. Install OpenAI CLI with Homebrew:

brew install openai/tools/openai

2. You can also install OpenAI CLI with Go:

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

Go places the binary in the Go bin directory. The default location is $HOME/go/bin, unless GOPATH changes the location.

go env GOPATH

A missing openai command usually means the Go bin directory needs PATH access.

export PATH="$PATH:$(go env GOPATH)/bin"

3. Set an OpenAI API key:

export OPENAI_API_KEY="sk-..."

4. Run a Responses API request:

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

5. Set an admin API key when you need admin endpoints:

export OPENAI_ADMIN_KEY="sk-admin-..."

6. Query organization usage with an admin key:

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

7. Read command-specific help:

openai --help
openai responses create --help

8. Pass a file as an argument:

openai <command> --arg @abe.jpg

9. Pass a file inside JSON:

openai <command> --arg '{image: "@abe.jpg"}'

10. Pass a file inside YAML:

openai <command> <<YAML
arg:
 image: "@abe.jpg"
YAML

11. Escape an @ string:

openai <command> --username '\@abe'

12. Use explicit file encoding:

openai <command> --arg @file://myfile.txt

The @data:// syntax sends a file as base64-encoded data.

openai <command> --arg @data://file.txt

13. Run the project locally after cloning the repository:

./scripts/run args...

Quick Reference

Basic Commands

SyntaxPurpose
openai [resource] <command> [flags...]Runs a command against an API resource.
openai --helpShows top-level command help.
openai [resource] <command> --helpShows command-specific help.
openai --versionShows the installed CLI version.
openai -vShows the installed CLI version.

Installation Commands

MethodCommandRequirement
Homebrewbrew install openai/tools/openaiHomebrew installed.
Gogo install 'github.com/openai/openai-cli/cmd/openai@latest'Go 1.25 or later.
Local repository run./scripts/run args...Cloned project repository.

Authentication Variables

Environment variableRequiredDefault valuePurpose
OPENAI_API_KEYNonullStandard API authentication.
OPENAI_ADMIN_KEYNonullAdmin endpoint authentication.
OPENAI_ORG_IDNonullOrganization selection.
OPENAI_PROJECT_IDNonullProject selection.
OPENAI_WEBHOOK_SECRETNonullWebhook verification.

Global Flags

FlagEnvironment variablePurpose
--api-keyOPENAI_API_KEYSets the standard API key.
--admin-api-keyOPENAI_ADMIN_KEYSets the admin API key.
--organizationOPENAI_ORG_IDSets the organization.
--projectOPENAI_PROJECT_IDSets the project.
--webhook-secretOPENAI_WEBHOOK_SECRETSets the webhook secret.
--helpNoneShows command-line usage.
--debugNoneEnables HTTP request and response debug logging.
--versionNoneShows the CLI version.
-vNoneShows the CLI version.
--base-urlNoneUses a custom API backend URL.
--formatNoneChanges the normal output format.
--format-errorNoneChanges the error output format.
--transformNoneTransforms normal output with GJSON syntax.
--transform-errorNoneTransforms error output with GJSON syntax.

Output Formats

FormatUse
autoLets the CLI choose an output format.
exploreUses an exploratory output view.
jsonOutputs JSON.
jsonlOutputs JSON Lines.
prettyOutputs readable formatted text.
rawOutputs raw response data.
yamlOutputs YAML.

File Argument Syntax

SyntaxPurpose
@myfile.extPasses a local file as an argument.
@abe.jpgPasses an image file.
{image: "@abe.jpg"}Passes a file reference inside JSON-style input.
'\@abe'Sends a literal string that starts with @.
@file://myfile.txtSends a file as plain text.
@data://file.txtSends a file as base64-encoded data.
@file:///tmp/file.txtSends an absolute path as plain text.
@data:///tmp/file.datSends an absolute path as base64-encoded data.

Development Linking Commands

The ./scripts/link script links the CLI against another OpenAI Go SDK version during development.

./scripts/link github.com/org/repo@version

A local SDK copy can also serve as the linked target.

./scripts/link ../path/to/openai-go

The script defaults to ../openai-go when no argument is supplied.

./scripts/link

Alternatives and Related Resources

Pros

  • Open-source under OpenAI.
  • Installs via Homebrew or Go.
  • Seven output formats.
  • GJSON output transforms.
  • Explicit file encoding syntax.
  • Standard and admin API keys.

Cons

  • No graphical interface.
  • Not a coding agent.
  • Requires terminal comfort.
  • Admin endpoints need admin keys.
  • Debug logs can expose data.

FAQs

Q: Is the OpenAI CLI free?
A: The CLI is free and open-source. API usage is billed through your OpenAI account based on the endpoints and models you use.

Q: Does the OpenAI CLI require a signup?
A: You need an OpenAI account and a valid API key for standard API calls. You need an admin API key for organization-level admin endpoints.

Q: What is the difference between the OpenAI CLI and the OpenAI Codex CLI?
A: The OpenAI CLI is an API wrapper for terminal requests, resource management, and usage stats. The Codex CLI is an agentic coding tool that reads and edits files on your local machine in response to natural language prompts.

Q: Does the OpenAI CLI run on Windows?
A: The Go-based install works on Windows, macOS, Linux, and other platforms Go supports. The Homebrew method is mainly for macOS and Linux environments.

Q: Can the OpenAI CLI send local files to the API?
A: Yes. You can pass files with @filename, send plain text with @file://, or send base64-encoded data with @data://.

Q: Should you use debug mode?
A: Debug mode is useful for troubleshooting HTTP requests, but it can show request bodies, response bodies, and sensitive data. You should keep debug logs private and remove secrets before sharing logs.

Changelog

v1.2.0 (06/01/2026)

  • Added more features

Leave a ReplyCancel Reply

Trending now

Get the latest & top AI tools sent directly to your email.

Subscribe now to explore the latest & top AI tools and resources, all in one convenient newsletter. No spam, we promise!