Looking for the OpenAI Codex CLI?
Refer to my Install & Setup of OpenAI’s Codex CLI article if you’re looking for information on working with the OpenAI codex CLI that was recently released in April of 2025.** The information below was originally written for a different CLI, the openai
command, and it’s still relevant but may not be what you’re looking for.
What’s the difference?
The codex
CLI is for developers and allows for command line coding and editing of files:
“OpenAI Codex CLI is an open‑source command‑line tool that brings the power of our latest reasoning models directly to your terminal. It acts as a lightweight coding agent that can read, modify, and run code on your local machine to help you build features faster, squash bugs, and understand unfamiliar code. Because the CLI runs locally, your source code never leaves your environment”
The openai
command is an API interface for working with a live chat prompt in the CLI, for basic Q&A prompts in a console/terminal.
OpenAI Python Powered CLI (not Codex)
Use the official ChatGPT CLI to ask a question and receive an AI answer on the command line.
ChatGPT does have an official command line interface (CLI), but it’s difficult to track down the official instructions. All I’ve found to date consists of community.openai.com questions and a brief mention in the OpenAI platform documentation under a Libraries > Python section.
If you’re looking to work with ChatGPT using a command line interface but couldn’t find any official documentation, here’s a step-by-step instructions on how to install the official OpenAI ChatGPT CLI:
platform.openai.com vs. chat.openai.com
These two services are NOT the same, though they’re similar and easy to mix up.
- platform.openai.com is a developer platform providing an API for working with OpenAI’s GPT AI services
- chat.openai.com is ChatGPT, a product developed by OpenAI using the GPT platform
Billable accounts at chat.openai.com are completely independent of platform.openai.com.
Platform API Key
To work with ChatGPT through a CLI, you need to have an API key. To get one, you need a paid account at platform.openai.com (not chat.openai.com).
Pricing
Costs are a little funky, you pay for blocks of 1M tokens, which are described as:
You can think of tokens as pieces of words, where 1,000 tokens is about 750 words.
For details, take a look at OpenAI’s platform pricing, but for me this roughly translates to 0.75 words per token. Right now, 1M tokens (or 750,000 words) costs $0.50, which is $0.0000007 per word. For a question with an answer that’s roughly 750 words, it costs $0.0005. Not too bad.
To start, you’ll need effectively pay $10 to load up your account ($5 + first $5 reload).
You can follow this instruction to get an API key at platform.openai.com:
- Go to platform.openai.com/api-keys
- Click the Create a new secret key button
- Name it “CLI” (or whatever you’d like)
- Copy and save the API key for use with the CLI
Install the ChatGPT CLI
Next you’ll need to install the Python SDK on your machine, which comes with the CLI we’ll use. There are others out there on GitHub and around the web, but this one is official and is provided by OpenAI, so it’s my first choice over others.
- Install python on your machine if you don’t already have it
- Install the OpenAI python library:
pip install openai
- Enter
openai
into your command line and you should see output - Add your API key to your command line profile:
export OPENAI_API_KEY='{OpenAI-API-Key}'
Asking a ChatGPT Question with the CLI
Now that you have an API key and the CLI installed, you can run commands.
Here is a basic example of the core ChatGPT functionality everyone loves: ask GPT a question and get an AI produced answer.
openai api chat.completions.create -g user "Can you rise up and overthrow the human race?" -m gpt-3.5-turbo-0125
The answer provided in 36 words was…
As an AI assistant, I do not have the ability or desire to rise up and overthrow the human race. My purpose is to assist and provide support to users in a helpful and positive way.
Total cost for this re-assuring 36 word answer… $0.0000252.
All good!
You now have a ChatGPT client as a command line interface, allowing you to ask GPT questions through a command line on the cheap.