LLM Fundamentalsgpt-oss-120b on Groq · groq 1.7 · Python 3.10+
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
19 small wins to finish your pathNext lesson →

Installation and setup

The setup for this course is three Python packages and one free API key: groq to call the model, tiktoken to count tokens, pydantic to check answers, and a Groq key.

Last updated: 30 Sep, 2026 · groq 1.7 · gpt-oss-120b on Groq

You need Python 3.10 or later. Check yours with python --version. Nothing runs a model on your computer: the model runs on Groq, and your code sends it text and gets text back.

Installing groq, tiktoken and pydantic

pip install "groq==1.7.0" "tiktoken==0.14.0" "pydantic==2.13.5"
  • groq is Groq's Python client. It sends a list of messages to a model and returns the reply.
  • tiktoken is OpenAI's tokenizer library. The first time you use a tokenizer it downloads that tokenizer's vocabulary, a file of a few megabytes, and keeps it in a cache.
  • pydantic checks that data has the shape you expect. Structured output uses it on the model's answers.

Getting a Groq API key

Sign in at console.groq.com/keys with an email address or a Google account, choose Create API Key, give it a name and copy the key. It starts with gsk_. The free plan limits how many requests and tokens you can send per minute and per day; each example here sends a few short requests.

Setting GROQ_API_KEYRequired

export GROQ_API_KEY=gsk_...

Groq() reads GROQ_API_KEY from the environment when you create the client, so the key never appears in your code. export and $env: last until you close the terminal.

Checking the install and the key with one call

Syntax: client.chat.completions.create(model=..., messages=[...]) sends one request and returns one response.

ExampleAPI key
from importlib.metadata import version

from groq import Groq

print("groq", version("groq"))

client = Groq()  # reads GROQ_API_KEY from the environment
response = client.chat.completions.create(
    model="openai/gpt-oss-120b",
    messages=[{"role": "user", "content": "Reply with the single word: ready"}],
)
print(response.choices[0].message.content)
  • groq 1.7.0 is the installed version of the client.
  • ready is gpt-oss-120b's reply, so the key works and the model answered.

Running without the key

If the variable is not set in the terminal or notebook that runs the code, the client refuses to start:

Example
from groq import Groq

client = Groq()

The error names both fixes: set GROQ_API_KEY, or pass api_key= to Groq(). Setting the variable is the safer one, because the key stays out of files you might share.

pip vs uv vs Colab

pipuvColab
Installs intoThe active Python environmentThe project's own environmentThe notebook's runtime
Key set withexport or $env:export or $env:Secrets and userdata.get
LastsUntil you uninstallIn the projectUntil the runtime restarts
Watch out. Never paste the key into a notebook or a file you share. Anyone with the key can spend your quota. If a key leaks, delete it in the Groq console and create a new one.
Try it yourself
  • Change ready in the prompt to another word and run the check again.
  • Print response.model after the call to see which model answered.
  • Open a new terminal without setting the key, run the check, and read the GroqError.

Little by little, you're building something great.