BerriAI/litellm · error · Exception
Missing api_key, make sure you pass in your api key
Error message
Missing api_key, make sure you pass in your api key
What it means
In Bytez's validate_environment, after headers are built it checks the resolved api_key argument; if falsy it raises this generic Exception. The Authorization header would otherwise read 'Key None'. Unlike other providers it does not fall back to an env var here — the key must arrive via the api_key argument (litellm resolves env-based keys before this point).
Solutions
- Pass api_key on the call: litellm.completion(..., api_key="...").
- Set the key in the environment so litellm resolves it (standard provider env pattern, e.g. BYTEZ_API_KEY) for the process running litellm.
- For LiteLLM proxy, add api_key to the model's config entry (litellm_params).
- Verify the key reaches your code path by printing bool(api_key) just before the call.
Example fix
# before
litellm.completion(model="bytez/meta-llama/Llama-3.1-8B-Instruct", messages=msgs)
# after
litellm.completion(
model="bytez/meta-llama/Llama-3.1-8B-Instruct",
messages=msgs,
api_key=os.environ["BYTEZ_API_KEY"],
) Defensive patterns
Strategy: validation
Validate before calling
import os
def bytez_key() -> str | None:
return os.environ.get("BYTEZ_API_KEY") or os.environ.get("BYTEZ_API_TOKEN") Try / catch
try:
litellm.completion(model="bytez/org/model", messages=msgs, api_key=key)
except Exception as e:
if "api_key" in str(e):
raise RuntimeError("BYTEZ credentials missing") from e
raise Prevention
- Resolve the key once at startup and fail fast if absent.
- In proxy deployments, put api_key in the model's litellm_params so it is always attached.
When it happens
Trigger: Calling litellm.completion(model="bytez/...", messages=msgs) with no api_key and no BYTEZ_API_KEY available for litellm to auto-resolve; passing api_key=None explicitly; proxy model entry missing the api_key field.
Common situations: First call to a newly added bytez model; proxy config listing the model without api_key and without the env var on the host; key stored under a differently-named env var.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- BFL_API_KEY is not set. Please set it via environment…
- BRAVE_API_KEY is not set. Set `BRAVE_API_KEY` environment…
- LINKUP_API_KEY is not set. Set `LINKUP_API_KEY` environment…
- XAI API key is required. Set api_key, litellm.xai_key…
- api_key is required
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/68115b97477350dc.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/bytez/chat/transformation.py:138
messages: list[AllMessageValues],
optional_params: dict,
litellm_params: dict,
api_key: str | None = None,
api_base: str | None = None,
) -> dict:
headers.update(
{
"content-type": "application/json",
"Authorization": f"Key {api_key}",
"user-agent": f"litellm/{version}",
}
)
if not messages:
raise Exception("kwarg `messages` must be an array of messages that follow the openai chat standard")
if not api_key:
raise Exception("Missing api_key, make sure you pass in your api key")
return headers
def get_complete_url(
self,
api_base: str | None,
api_key: str | None,
model: str,
optional_params: dict,
litellm_params: dict,
stream: bool | None = None,
) -> str:
encoded_model: Final = encode_url_path_segments(model, field_name="model")
return f"{API_BASE}/{encoded_model}"
def transform_request(
self,
model: str,View on GitHub (pinned to 77b7c6c40c)