LiteLLMLiteLLM 1.105 · Python 3.10+
Dashboard
0%

Providers and keys: the model string

A model string is the text passed as model=: a provider name, a slash and the provider's model id, and LiteLLM reads the part before the first slash to choose the provider, its address and the environment variable that holds its key.

Last updated: 12 Oct, 2026 · LiteLLM 1.105

completion(): your first call used the same Groq model each time. Changing provider is the next step, and it changes only the model string. This lesson shows how the string is read and how to check which key a model needs. It also shows what happens when a parameter does not travel to a provider.

The model string groq/openai/gpt-oss-120b is split at its first slash. The part before it, groq, names the provider, which decides the API address and that the key comes from the <code>GROQ_API_KEY</code> environment variable. The part after it, openai/gpt-oss-120b, is the model id and is sent to Groq unchanged, including its own slash.

Syntax: the string has two parts, and two optional arguments override what the provider part would choose.

python
completion(
    model="groq/openai/gpt-oss-120b",   # provider/model-id
    messages=messages,
    api_key="...",   # use this key, not the environment variable
    api_base="...",  # send the call to this address
)

Splitting a model string into provider and model id

get_llm_provider is the function LiteLLM uses to split the string. It returns four values, and the example unpacks the first two.

ExampleThe provider and the model id from four strings
import litellm

names = ["groq/openai/gpt-oss-120b", "gemini/gemini-2.5-flash-lite", "ollama/llama3", "openai/gpt-4o-mini"]
for name in names:
    model, provider, _, _ = litellm.get_llm_provider(name)
    print(f"{provider:7} {model}")

The provider is the part before the first slash. Everything after it is the model id, and it reaches the provider unchanged: openai/gpt-oss-120b is Groq's own name for its copy of that model, slash included. The two values the example ignores are the API key and the address, which is why it unpacks only two.

Watch out. get_llm_provider returns your API key as its third value. Printing the whole result prints the key. Unpack what you need, as above, and never paste the full tuple into a chat, a log or an issue.

Checking which key a model needs

validate_environment reports whether the variables a model needs are set. It makes no call, so it is a quick check for a new provider.

ExampleWhich keys are set and which are missing
import litellm

names = ["groq/openai/gpt-oss-120b", "gemini/gemini-2.5-flash-lite", "openai/gpt-4o-mini", "anthropic/claude-sonnet-4-5"]
for name in names:
    check = litellm.validate_environment(model=name)
    print(name, check["keys_in_environment"], check["missing_keys"])

The first two lines read True and an empty list because the keys from the setup lesson are set. The OpenAI and Anthropic models report False and name the variable each would need. The course never calls them, and this check still works for any provider LiteLLM lists.

ProviderKey variableExample model stringCost
GroqGROQ_API_KEYgroq/openai/gpt-oss-120bFree key
GeminiGEMINI_API_KEYgemini/gemini-2.5-flash-liteFree key
OpenRouterOPENROUTER_API_KEYopenrouter/openai/gpt-oss-20b:freeFree models end in :free
OpenAIOPENAI_API_KEYopenai/gpt-4o-miniPaid
AnthropicANTHROPIC_API_KEYanthropic/claude-sonnet-4-5Paid

Overriding the key and the address for one call

api_key replaces the environment variable for a single call, which is how one program uses two accounts with the same provider. api_base replaces the provider's address, which is how a call reaches a model served on your own machine.

python
# Not run here: it needs Ollama running on this machine.
completion(
    model="ollama_chat/llama3.1",
    api_base="http://localhost:11434",   # where Ollama listens
    messages=[{"role": "user", "content": "Hello"}],
)

The Ollama call is not run here. It shows the pattern: a local server needs an address and no key, and every other part of the call is unchanged.

Sending a parameter the provider does not accept

LiteLLM translates the OpenAI parameters, such as temperature and max_tokens, for each provider. Some providers lack some of them. Two real refusals follow, one raised by LiteLLM before any request and one by the provider after it.

ExampleTwo parameters that did not travel
import litellm

litellm.suppress_debug_info = True
messages = [{"role": "user", "content": "hi"}]
cases = [
    ("gemini/gemini-2.5-flash-lite", {"logit_bias": {"1": 1}}),
    ("groq/openai/gpt-oss-20b", {"top_k": 3}),
]
for model, extra in cases:
    try:
        litellm.completion(model=model, messages=messages, max_tokens=400, **extra)
    except Exception as error:
        print(type(error).__name__, "|", str(error)[:104])
  • Gemini and logit_bias raised UnsupportedParamsError. LiteLLM knows Gemini has no such option, and it refused before sending anything.
  • Groq and top_k raised BadRequestError. top_k is not an OpenAI parameter, so LiteLLM passed it through, and Groq answered that the property is unsupported.

drop_params=True tells LiteLLM to remove what a provider cannot take and carry on.

ExampleAPI keyThe same Gemini call with drop_params
import litellm

response = litellm.completion(
    model="gemini/gemini-2.5-flash-lite",
    messages=[{"role": "user", "content": "Name one colour."}],
    max_tokens=400,
    logit_bias={"1": 1},   # Gemini has no logit_bias
    drop_params=True,      # drop it instead of raising
)
print(response.choices[0].message.content)

It answered, with logit_bias removed. litellm.drop_params = True sets it for every call. That suits code that moves between providers. It also means an option can stop having any effect without a message, so it is off unless you turn it on.

Reading an error for a string with no provider

ExampleA model string LiteLLM cannot place
import litellm

litellm.suppress_debug_info = True
try:
    litellm.completion(model="support-bot", messages=[{"role": "user", "content": "hi"}], max_tokens=400)
except litellm.BadRequestError as error:
    print(str(error).splitlines()[0])

support-bot has no provider prefix, and LiteLLM does not recognise it as a model id. It cannot know where to send the call, so it says so before sending anything. Model aliases: names of your own gives a name like this a meaning.

Where you use provider prefixes

  • Comparing providers on the same prompts by looping over model strings.
  • Keeping a free model for development and a paid one for production, changed through one string.
  • Reaching a model on your own hardware with api_base and no key.
Watch out. get_supported_openai_params lists what LiteLLM forwards for a provider, and not what each model accepts. It lists logit_bias as supported for Groq, and a Groq gpt-oss call with it is refused by the model. A parameter that passes this check can still fail at the provider.
Try it yourself
  • Add "openrouter/openai/gpt-oss-20b:free" to the validate_environment loop and read the variable it names.
  • Call litellm.get_llm_provider("gemini/gemini-2.5-flash-lite") and read which two values are the provider and the model id, without printing the key.
  • Run the Gemini logit_bias example without drop_params and read the error.

Little by little, you're building something great.