LiteLLMLiteLLM 1.105 · Python 3.10+
Dashboard
0%

Installation and setup

Setup is the one-time work of installing the litellm package and storing a provider's key in an environment variable, after which every example in this course runs on your own machine.

Last updated: 12 Oct, 2026 · LiteLLM 1.105

The words you will meet defined the terms. This lesson installs the package and gets the two free keys. It makes a first real call, then shows the error that a missing key gives.

Installing litellm with the proxy extra

pip install "litellm[proxy]==1.105.0" installs LiteLLM and the extra packages the gateway server needs. The [proxy] part is called an extra. The ==1.105.0 part pins the version. LiteLLM changes quickly, and the outputs in this course are those of that version. It needs Python 3.10 or later.

pip install "litellm[proxy]==1.105.0"

Checking the installed version takes one line.

ExampleThe installed version
from importlib.metadata import version

print(version("litellm"))

Getting a Groq key and a Gemini key

The course uses two free providers, so no payment details are needed.

  • Groq serves the open gpt-oss models. Create a key at console.groq.com/keys. The models used are groq/openai/gpt-oss-120b and groq/openai/gpt-oss-20b.
  • Google AI Studio serves Gemini. Create a key at aistudio.google.com/apikey. The model used is gemini/gemini-2.5-flash-lite.

Free keys have usage limits. Groq limits requests and tokens per minute, so a call that fails with a rate limit message works again after a minute. Gemini's free tier also limits requests per day for each model. The limit was 20 for gemini-2.5-flash-lite when this was written, so the Gemini examples are few. A Gemini call that fails with a 429 and the words quota exceeded has used up that day's requests. The Groq examples keep working.

Storing the keys in environment variables

LiteLLM reads GROQ_API_KEY for models that start with groq/ and GEMINI_API_KEY for models that start with gemini/. Set both in the terminal you run Python from, or in Colab's Secrets panel.

export GROQ_API_KEY=gsk_...
export GEMINI_API_KEY=AIza...

Keep keys out of code and out of version control. A key written into a file is a key that is shared the moment the file is.

Making a first call to Groq and to Gemini

completion() takes a model string and a list of messages. max_tokens=400 is a limit on the reply length. The Groq models write hidden thinking tokens first, and a small limit can leave no room for the answer. A limit of 400 is safe. completion(): your first call shows what happens with a small one.

ExampleAPI keyThe first real call, to two providers
from litellm import completion

messages = [{"role": "user", "content": "Say hello."}]

for model in ["groq/openai/gpt-oss-120b", "gemini/gemini-2.5-flash-lite"]:
    response = completion(model=model, messages=messages, max_tokens=400)
    print(model, "->", response.choices[0].message.content)

Both replies came back through the same response.choices[0].message.content. If this printed two answers, the install and both keys work. The wording of the answers changes from run to run.

Reading the error that a missing key gives

A key that is not set is the most common first problem. The next example removes GROQ_API_KEY from the environment of this one program, then makes the same call and prints the exception. It is the last example in the lesson, because the key stays removed until the program ends.

ExampleA call with no Groq key
import os
import litellm
from litellm import completion

litellm.suppress_debug_info = True   # hide LiteLLM's two help lines before an error
os.environ.pop("GROQ_API_KEY", None)   # behave as if the key was never set

try:
    completion(
        model="groq/openai/gpt-oss-120b",
        messages=[{"role": "user", "content": "Say hello."}],
        max_tokens=400,
    )
except Exception as error:
    print(type(error).__module__ + "." + type(error).__name__)
    print(error)

Reading what the missing key produced

  • The exception is litellm.exceptions.BadRequestError, and its message starts with GroqException. LiteLLM sent the call without a key, Groq refused it, and LiteLLM wrapped Groq's refusal in its own exception class.
  • The message names the cause. Invalid API Key comes from Groq. An empty key and a wrong key look the same to Groq.
  • Without the suppress_debug_info line, LiteLLM prints two help lines of its own, a feedback link and a hint about litellm._turn_on_debug(), before the error. Later lessons set it to keep their output short.
  • Why it is a BadRequestError and not an AuthenticationError is explained, with the other exception classes, in Exceptions: one set for every provider.

Where you use this setup

  • A notebook or script on your own machine with the keys set in the terminal.
  • A Colab notebook, where the keys sit in Secrets and are copied into os.environ at the top.
  • A gateway server, which reads provider keys from its own environment so applications never hold them. The gateway part returns to this.
Watch out. A key set in one terminal is not set in another. A script run from an editor's own terminal, a notebook kernel started before the key was exported, and a new Colab session each start without it. When a call says Invalid API Key, print os.environ.get("GROQ_API_KEY") is not None first.
Try it yourself
  • Call os.environ.get("GEMINI_API_KEY") and check it is not None before running the first call.
  • Remove the os.environ.pop line and run the last example again. The call now succeeds.
  • Change the Gemini key to api_key="wrong" in a call and read the exception class, which is not the one Groq gave.

This is what real progress feels like.