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
What is the OpenAI CLI?
</h2> <p>The OpenAI CLI is an open-source Go binary, published by OpenAI at <a href="https://github.com/openai/openai-cli" rel="noopener noreferrer">github.com/openai/openai-cli</a> under the Apache 2.0 license. Its commands mirror the API's resources (<code>responses</code>, <code>files</code>, <code>batches</code>, <code>images</code>, <code>audio</code>, <code>vector-stores</code>, <code>admin</code>), so anything you'd send with curl or an SDK becomes one terminal command with flags.</p> <p>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.</p> <p>Here's what you get on a first run:</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpvhs2ilrd4x9j9whm16y.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpvhs2ilrd4x9j9whm16y.png" alt="openai --version and openai --help output from OpenAI CLI v1.44.1" width="800" height="484"></a></p> <p>The help groups commands by job: generate content (<code>responses</code>, <code>chat</code>, <code>images</code>, <code>audio</code>, <code>videos</code>), data and retrieval (<code>files</code>, <code>uploads</code>, <code>vector-stores</code>, <code>embeddings</code>), 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 <code>openai <command> --help</code> the fastest way to learn the flags.</p> <p>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.</p> <h2>How to install the OpenAI CLI
</h2> <p>You have three install routes, all listed in the project README:</p> <ol> <li> <strong>Prebuilt binary.</strong> Download the archive for your OS and architecture from <a href="https://github.com/openai/openai-cli/releases/latest" rel="noopener noreferrer">GitHub Releases</a> (macOS, Linux and Windows builds are published), extract it and put <code>openai</code> on your PATH.</li> <li> <strong>Homebrew.</strong> </li> </ol> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code> brew <span class="nb">install </span>openai/tools/openai </code></pre> </div> <ol> <li> <strong>Go.</strong> Requires Go 1.26 or later. </li> </ol> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code> go <span class="nb">install</span> <span class="s1">'github.com/openai/openai-cli/cmd/openai@latest'</span> <span class="nb">export </span><span class="nv">PATH</span><span class="o">=</span><span class="s2">"</span><span class="nv">$PATH</span><span class="s2">:</span><span class="si">$(</span>go <span class="nb">env </span>GOPATH<span class="si">)</span><span class="s2">/bin"</span> </code></pre> </div> <p>Self-managed release installs can update themselves during interactive runs. If you pin versions in CI, set <code>OPENAI_CLI_NO_AUTO_UPDATE=1</code> to stop automatic installs, or <code>OPENAI_CLI_NO_UPDATE_CHECK=1</code> to switch off update checks entirely. Homebrew and Go installs keep their update notices but leave upgrades to the package manager.</p> <h2>How OpenAI CLI authentication works
</h2> <p>The CLI reads a standard API key from <code>OPENAI_API_KEY</code> (or the <code>--api-key</code> flag, which you should avoid because it lands in shell history). If you don't have one yet, our guide to <a href="http://apidog.com/blog/openai-api-key?utm_source=dev.to&utm_medium=wanda&utm_content=n8n-post-automation">getting an OpenAI API key</a> walks through it.</p> <p>The quickest setup is the built-in guide:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>openai <span class="nb">help </span>setup </code></pre> </div> <p>It points you to the <a href="https://platform.openai.com/settings/organization/api-keys" rel="noopener noreferrer">API keys page</a> and gives you a <code>read -rs OPENAI_API_KEY</code> line for Bash or zsh, so the key is typed hidden and never echoed.</p> <p>Forget the key and you get a clear, scriptable failure. This is the real output with no key set:</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzscjsnnl4zluusynpqmj.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzscjsnnl4zluusynpqmj.png" alt="OpenAI CLI returns HTTP 401 Unauthorized when no API key is configured" width="800" height="287"></a></p> <p>It exits with status 1 and tells you exactly where a key can come from. Add <code>--format-error json</code> when a script needs the raw error body.</p> <p>The other auth settings:</p> <div class="table-wrapper-paragraph"><table> <thead> <tr> <th>Setting</th> <th>Flag</th> <th>Environment variable</th> <th>Use it for</th> </tr> </thead> <tbody> <tr> <td>API key</td> <td><code>--api-key</code></td> <td><code>OPENAI_API_KEY</code></td> <td>Every normal API call</td> </tr> <tr> <td>Admin key</td> <td><code>--admin-api-key</code></td> <td><code>OPENAI_ADMIN_KEY</code></td> <td> <code>openai admin ...</code> (usage, projects); a project key can't replace it</td> </tr> <tr> <td>Base URL</td> <td><code>--base-url</code></td> <td><code>OPENAI_BASE_URL</code></td> <td>Pointing the CLI at another host or a gateway</td> </tr> <tr> <td>mTLS cert and key</td> <td> <code>--mtls-client-cert-file</code>, <code>--mtls-client-key-file</code> </td> <td> <code>OPENAI_MTLS_CLIENT_CERT_FILE</code>, <code>OPENAI_MTLS_CLIENT_KEY_FILE</code> </td> <td>Mutual TLS, which needs an explicit HTTPS base URL</td> </tr> </tbody> </table></div> <h2>First OpenAI CLI commands to run
</h2> <p>The command shape follows the API: <code>openai <resource> [subresource...] <command> [flags...]</code>. These are the commands that earn their place in a toolbox.</p> <h3>Make a Responses API call
</h3> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>openai responses create <span class="se">\</span> <span class="nt">--model</span> gpt-5.5 <span class="se">\</span> <span class="nt">--input</span> <span class="s2">"Say this is a test"</span> </code></pre> </div> <p>Long prompts don't need escaping. JSON input flags read from a file with <code>@path</code>:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>openai responses create <span class="nt">--model</span> gpt-5.5 <span class="nt">--input</span> @prompt.txt </code></pre> </div> <p>If you pipe JSON or YAML from a source you don't trust, set <code>OPENAI_UNTRUSTED_STDIN=1</code> so that input can't trigger local file reads.</p> <h3>Upload and fetch files
</h3> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>openai files upload report.txt <span class="nt">--purpose</span> user_data openai files get file-example openai files download file-example <span class="nt">--output</span> downloaded-report.txt </code></pre> </div> <h3>Run a batch
</h3> <p>Put one request per line in <code>requests.jsonl</code>, each with a unique <code>custom_id</code>, then:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>openai files upload requests.jsonl <span class="nt">--purpose</span> batch openai batches create <span class="nt">--input-file-id</span> file-example <span class="se">\</span> <span class="nt">--endpoint</span> /v1/responses <span class="nt">--completion-window</span> 24h openai batches <span class="nb">wait </span>batch_example <span class="nt">--output-dir</span> ./results </code></pre> </div> <p><code>batches wait</code> polls until the batch finishes and saves the result files, which removes the polling loop you'd otherwise write. The project's <a href="https://github.com/openai/openai-cli/blob/main/docs/batches.md" rel="noopener noreferrer">batch guide</a> lists the current limits as 50,000 requests and 200 MB per input file, with a <code>24h</code> completion window. Batch pricing differs from synchronous calls; see our <a href="http://apidog.com/blog/openai-api-pricing?utm_source=dev.to&utm_medium=wanda&utm_content=n8n-post-automation">OpenAI API pricing</a> breakdown before you queue a large job.</p> <h3>Count tokens locally, with no key
</h3> <p>The <code>tokenizer</code> command runs fully offline: no credentials, no network, no saved input.</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzsuyi7b9q66c2js1zspf.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzsuyi7b9q66c2js1zspf.png" alt="openai tokenizer count output in text and JSON formats" width="799" height="230"></a></p> <p>The default encoding is <code>o200k_base</code>, and <code>openai tokenizer encodings</code> lists the others (<code>cl100k_base</code>, 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 <code>openai responses input-tokens count</code>.</p> <h3>Get output a script can parse
</h3> <p>The default output is readable text, even when piped. Ask for data explicitly:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>openai models list <span class="nt">--format</span> jsonl | jq <span class="s1">'.id'</span> openai files list <span class="nt">--format</span> json <span class="o">></span> files.json openai files get file-example <span class="nt">--transform</span> filename <span class="nt">--raw-output</span> </code></pre> </div> <p><code>--format</code> accepts <code>auto</code>, <code>text</code>, <code>json</code>, <code>jsonl</code>, <code>yaml</code>, <code>explore</code> (an interactive JSON viewer) and <code>pretty</code>. <code>--transform</code> pulls fields with <a href="https://github.com/tidwall/gjson/blob/master/SYNTAX.md" rel="noopener noreferrer">GJSON syntax</a>, and <a href="https://jqlang.org/" rel="noopener noreferrer">jq</a> handles anything fancier. Always check the exit status before trusting a redirected file: a failed request can leave a partial one behind.</p> <p>When a call misbehaves, <code>--debug</code> adds per-attempt HTTP timing; scrub its logs before sharing them. If you're hitting 429s, our <a href="http://apidog.com/blog/openai-api-user-rate-limits?utm_source=dev.to&utm_medium=wanda&utm_content=n8n-post-automation">OpenAI rate limits guide</a> explains the tiers.</p> <h2>OpenAI CLI vs Codex CLI vs the old openai command
</h2> <p>Three tools share a vendor and two share a name. This is the short version:</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4gy92t3yo7mb4uajynpc.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4gy92t3yo7mb4uajynpc.png" alt="Comparison of OpenAI CLI, Codex CLI and Apidog CLI: what each terminal tool is for" width="799" height="313"></a></p> <div class="table-wrapper-paragraph"><table> <thead> <tr> <th></th> <th>OpenAI CLI</th> <th>Codex CLI</th> <th>Legacy Python <code>openai</code> </th> </tr> </thead> <tbody> <tr> <td>Command</td> <td><code>openai</code></td> <td><code>codex</code></td> <td><code>openai</code></td> </tr> <tr> <td>What it is</td> <td>A client for the REST API</td> <td>A coding agent that reads, edits and runs code in your project</td> <td>A CLI bundled with the <code>openai</code> Python package</td> </tr> <tr> <td>Install</td> <td>Binary, Homebrew or Go</td> <td> <code>npm install -g @openai/codex</code> or <code>brew install --cask codex</code> </td> <td><code>pip install openai</code></td> </tr> <tr> <td>Auth</td> <td><code>OPENAI_API_KEY</code></td> <td>Handles its own sign-in</td> <td>API key</td> </tr> <tr> <td>Use it when</td> <td>You want one specific API call, or API steps in a script</td> <td>You want an agent to implement or debug a change</td> <td>You maintain older scripts built on it</td> </tr> </tbody> </table></div> <p>Run <code>openai codex</code> and the OpenAI CLI prints Codex install commands itself, noting it's a separate tool with its own sign-in. Our <a href="http://apidog.com/blog/openai-codex-cli?utm_source=dev.to&utm_medium=wanda&utm_content=n8n-post-automation">Codex CLI guide</a> covers the agent side, and the source lives at <a href="https://github.com/openai/codex" rel="noopener noreferrer">github.com/openai/codex</a>.</p> <h3>Watch for the PATH clash
</h3> <p>The <code>openai</code> Python package also installs a binary named <code>openai</code>. If you've ever run <code>pip install openai</code>, you may have two:</p> <p><a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx2zqrc04y0a1ztgrz93m.png" class="article-body-image-wrapper"><img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx2zqrc04y0a1ztgrz93m.png" alt="which -a openai shows two openai binaries: the new OpenAI CLI and the legacy Python SDK command" width="800" height="283"></a></p> <p>On this Mac the Python one reports <code>openai 2.30.0</code> and offers <code>api</code>, <code>tools</code>, <code>migrate</code> and <code>grit</code> subcommands; the Go one reports <code>openai version 1.44.1</code>. Whichever directory comes first on your PATH wins. Run <code>which -a openai</code> and <code>openai --version</code> after you install. If the output says <code>openai version 1.44.1</code> (or newer), you have the right one. If it prints a bare version number like <code>openai 2.30.0</code>, reorder your PATH or call the new binary by its full path.</p> <h2>Where Apidog CLI fits next to the OpenAI CLI
</h2> <p>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 <a href="https://apidog.com/apidog-cli/?utm_source=dev.to&utm_medium=wanda&utm_content=n8n-post-automation">Apidog CLI</a> comes in. You don't pick one over the other; most teams that ship an AI feature want both.</p> <p>Better still, let your coding agent run both. Set up Apidog CLI once:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>npm <span class="nb">install</span> <span class="nt">-g</span> apidog-cli@latest apidog login <span class="nt">--with-token</span> <YOUR_TOKEN> npx <span class="nt">-y</span> skills add https://apidog.com <span class="c"># pick your agent when prompted</span> </code></pre> </div> <p>Then give your agent one [REDACTED PROMPT]<br> Use the openai CLI to confirm my key works with one responses create call on gpt-5.5.<br> Then import ./openapi.yaml into Apidog project , create a test case for<br> POST /v1/summarize that asserts a 200 and a non-empty "summary" field, run it<br> against the staging environment and summarize any failures.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code> The agent checks the key with <span class="sb">`</span>openai<span class="sb">`</span>, <span class="k">then </span>works through Apidog CLI. It reads the schema before writing any payload, validates the file, and only <span class="k">then </span>creates and runs the <span class="k">case</span>:</code></pre>
</div> <p><br> bash<br> apidog import --project --format openapi --file ./openapi.yaml<br> apidog cli-schema get test-case-create<br> apidog cli-schema validate test-case-create --file case.json<br> apidog test-case create --project --file case.json<br> apidog run --test-case --project -e -r cli,json</p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>Two details from apidog test-case create --help save a round trip: the case needs a valid categoryId (list them with apidog test-case category --project <id>), and payloads should come from cli-schema, never from memory. The same apidog run line with -r junit drops into CI, as our Apidog CLI CI/CD guide shows. If Codex is your agent, start with Apidog CLI in Codex.
Apidog's Free plan covers up to 4 users, so a small team can try this without a purchase decision.
FAQ
Is the OpenAI CLI free? The tool is free and open source under Apache 2.0. The API calls it makes are billed to your OpenAI account at normal API rates. Local commands like openai tokenizer and every --help page cost nothing and need no key.
Is the OpenAI CLI the same as Codex CLI? No. openai sends direct API requests, one per command. codex is a coding agent that reads and edits your project and runs commands. They install separately and authenticate separately.
How do I install the OpenAI CLI on a Mac? Run brew install openai/tools/openai, or download the macos_arm64 (Apple Silicon) or macos_amd64 (Intel) zip from GitHub Releases and put the binary on your PATH. Then run openai --version to confirm you aren't hitting the older Python openai command.
Does the OpenAI CLI work in shell scripts and CI? Yes, that's its main design goal. Use --format json or jsonl for parseable output, check the exit status, keep the key in OPENAI_API_KEY from your secret manager, and set OPENAI_CLI_NO_AUTO_UPDATE=1 to keep the version pinned.
When was the OpenAI CLI released? Version 1.0.0 was published on GitHub on May 5, 2026. As of October 28, 2026 the latest release is 1.44.1, from October 27. </code></pre>
</div>Original source
Tags
Related Articles
Continue reading with these similar posts

Sources: Missouri RB Hardy, shot in offseason, to return vs. Arkansas
Missouri All-America tailback Ahmad Hardy is set to make his season debut for the Tigers this weekend at Arkansas, sources told ESPN.

Red Wings suspend Larkin as team explores trade options; players keen to move on
The Red Wings announced Thursday that star forward Dylan Larkin has been suspended without pay after informing the team he no longer wanted to play for Detroit.

Packers' Jacobs says TD celebration was ode to gospel song, not mocking arrest
The Packers' Josh Jacobs said he was surprised his first-half TD celebration was perceived by some as mocking his May arrest, saying it was an ode to a gospel song.

Israel faces weeks of coalition haggling as Netanyahu’s party claims election 'stolen'
Israel's election leaves the country facing weeks of coalition bargaining and an uphill battle for the opposition party to form a majority government.
Herdr has released native app
Comments

Satellite vs Fiber Internet: ഇന്ത്യയുടെ ഇന്റർനെറ്റ് വിപ്ലവത്തിന് ആര് മികച്ചത്?
ഇന്ന് ഇന്റർനെറ്റ് ഒഴിച്ചുകൂടാനാവാത്ത ഭാഗമായി മാറിക്കഴിഞ്ഞു. ഇപ്പോൾ ഇന്ത്യയിൽ നിലവിൽ ഏറ്റവും ജനപ്രിയമായ ഇന്റർനെറ്റ് മാധ്യമം ഒപ്റ്റിക്കൽ ഫൈബർ (Fiber Internet) ആണ്. എന്നാൽ രാജ്യത്ത് സജീവ ചർച്ചയായി മാറിക്