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.
Syntax: the string has two parts, and two optional arguments override what the provider part would choose.
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.
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}")groq openai/gpt-oss-120b gemini gemini-2.5-flash-lite ollama llama3 openai gpt-4o-mini
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.
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.
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"])groq/openai/gpt-oss-120b True [] gemini/gemini-2.5-flash-lite True [] openai/gpt-4o-mini False ['OPENAI_API_KEY'] anthropic/claude-sonnet-4-5 False ['ANTHROPIC_API_KEY']
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.
| Provider | Key variable | Example model string | Cost |
|---|---|---|---|
| Groq | GROQ_API_KEY | groq/openai/gpt-oss-120b | Free key |
| Gemini | GEMINI_API_KEY | gemini/gemini-2.5-flash-lite | Free key |
| OpenRouter | OPENROUTER_API_KEY | openrouter/openai/gpt-oss-20b:free | Free models end in :free |
| OpenAI | OPENAI_API_KEY | openai/gpt-4o-mini | Paid |
| Anthropic | ANTHROPIC_API_KEY | anthropic/claude-sonnet-4-5 | Paid |
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.
# 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.
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])UnsupportedParamsError | litellm.UnsupportedParamsError: gemini does not support parameters: ['logit_bias'], for model=gemini-2.5
BadRequestError | litellm.BadRequestError: GroqException - {"error":{"message":"property 'top_k' is unsupported","type":"i- Gemini and
logit_biasraisedUnsupportedParamsError. LiteLLM knows Gemini has no such option, and it refused before sending anything. - Groq and
top_kraisedBadRequestError.top_kis 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.
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)Blue
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
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])litellm.BadRequestError: LLM Provider NOT provided. Pass in the LLM provider you are trying to call. You passed model=support-bot
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_baseand no key.
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.Related
- Previous: completion(): your first call
- Next: Model aliases: names of your own
- Reference: Providers, Groq and Gemini in the LiteLLM docs
- Add
"openrouter/openai/gpt-oss-20b:free"to thevalidate_environmentloop 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_biasexample withoutdrop_paramsand read the error.
Little by little, you're building something great.