Once the OpenAI CLI is installed and authenticated, the terminal becomes a fast place to prototype prompts. Here are the calls you'll reach for most, from a one-off completion to something you can wire into a script.
A basic chat completion
The simplest useful call sends a prompt and prints the model's reply.
openai api chat.completions.create \
-m gpt-4o-mini \
-g user "Explain a Kafka consumer group in one sentence."The -g flag adds a message with a role; repeat it to build a multi-turn
conversation with system and assistant messages.
Script it with the SDK
For anything reusable, drop into Python. The SDK mirrors the CLI and is easier to compose.
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY from the environment
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You summarize text concisely."},
{"role": "user", "content": "Summarize: " + open("notes.txt").read()},
],
)
print(response.choices[0].message.content)Pipe output into your workflow
Because the CLI writes to stdout, you can chain it with everyday Unix tools.
cat error.log | openai api chat.completions.create \
-m gpt-4o-mini \
-g system "You are a log analyst." \
-g user "$(cat -)" > analysis.txtTakeaways
chat.completions.createwith-gflags covers most interactive use.- Move to the Python SDK the moment a call needs to be reusable.
- CLI output is just stdout, so it composes with pipes and redirects.
Keep model ids in a variable or config so you can swap models without editing every script.