Skip to content

Use the Groq API from the command line

Groq runs open models such as Llama very fast and has a free tier. Here’s how to use it from the terminal without writing any code.

Groq’s API is OpenAI-compatible, so a raw request looks like this:

Terminal window
curl https://api.groq.com/openai/v1/chat/completions \
-H "Authorization: Bearer $GROQ_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "llama-3.3-70b-versatile",
"messages": [{"role": "user", "content": "Explain DNS in one paragraph"}]}'

That works, but you get raw JSON back, no conversation memory and no idea what it cost. A CLI makes it pleasant.

Terminal window
pip install kunji
kunji keys add groq

Get a key at console.groq.com/keys and paste it when asked. It’s stored in your OS keychain. Then:

Terminal window
kunji chat -m groq:llama-3.3-70b-versatile

Every answer streams as it’s generated and ends with a line like:

llama-3.3-70b-versatile · 60 in · 17 out · <$0.0001 · 0.2s

Make it your default so you don’t need -m:

Terminal window
kunji use groq:llama-3.3-70b-versatile

List the models your key can use:

Terminal window
kunji models groq
Terminal window
kunji ask -m groq:llama-3.3-70b-versatile "summarize this" -f notes.txt
git log --oneline -20 | kunji ask "write release notes from these commits"
tail -100 server.log | kunji @explain

When output is piped, kunji prints plain text, so it’s safe to use in scripts. In CI, set the key as an environment variable instead of using the keychain:

Terminal window
export GROQ_API_KEY=...

If your main provider is rate-limited or down, kunji can retry on Groq automatically:

Terminal window
kunji config set fallback '["groq:llama-3.3-70b-versatile"]'

See Fallback models.

Compare it with your other models on the same prompt:

Terminal window
kunji compare "explain big-O notation" -m groq:llama-3.3-70b-versatile -m openai:gpt-4o-mini

The summary table marks the fastest and cheapest. See Compare models.