BerriAI/litellm · critical · ValueError

FIREWORKS_API_KEY is not set

Error message

FIREWORKS_API_KEY is not set

What it means

FireworksAIConfig.validate_environment() runs on every Fireworks chat/Completion request to build auth headers. It resolves the key from the explicit api_key argument, then FIREWORKS_API_KEY, then FIREWORKS_AI_API_KEY; if all are None it raises 'FIREWORKS_API_KEY is not set' before any network call is made.

Source

Thrown at litellm/llms/fireworks_ai/common_utils.py:65

            or get_secret_str("FIREWORKS_AI_API_KEY")
            or get_secret_str("FIREWORKSAI_API_KEY")
            or get_secret_str("FIREWORKS_AI_TOKEN")
        )
        return dynamic_api_key

    def validate_environment(
        self,
        headers: dict,
        model: str,
        messages: list[AllMessageValues],
        optional_params: dict,
        litellm_params: dict,
        api_key: str | None = None,
        api_base: str | None = None,
    ) -> dict:
        api_key = self._get_api_key(api_key)
        if api_key is None:
            raise ValueError("FIREWORKS_API_KEY is not set")

        auth_headers: Final = {"Authorization": f"Bearer {api_key}", **headers}
        content_type_header: Final = (
            {} if any(key.lower() == "content-type" for key in auth_headers) else {"Content-Type": "application/json"}
        )
        return self._add_session_affinity_header({**auth_headers, **content_type_header}, litellm_params)

    def _add_session_affinity_header(self, headers: dict, litellm_params: dict) -> dict:
        if any(key.lower() == "x-session-affinity" for key in headers):
            return headers
        session_id: Final = get_fireworks_session_id(litellm_params)
        if not session_id:
            return headers
        return {**headers, "x-session-affinity": session_id}

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set FIREWORKS_API_KEY (or the legacy alias FIREWORKS_AI_API_KEY) in the runtime environment.
  2. Or pass the key per call: litellm.completion(model='fireworks_ai/...', api_key='fw_...', ...).
  3. Check the value is non-empty (get_secret_str returns None for ''), e.g. print(bool(os.getenv('FIREWORKS_API_KEY'))) in the failing context.

Example fix

# before
response = litellm.completion(model="fireworks_ai/accounts/fireworks/models/llama-v3p1-8b-instruct", messages=[{"role": "user", "content": "hi"}])

# after
response = litellm.completion(
    model="fireworks_ai/accounts/fireworks/models/llama-v3p1-8b-instruct",
    messages=[{"role": "user", "content": "hi"}],
    api_key=os.environ["FIREWORKS_API_KEY"],
)
Defensive patterns

Strategy: validation

Validate before calling

import os

def get_fireworks_key() -> str:
    key = os.getenv("FIREWORKS_API_KEY") or os.getenv("FIREWORKS_AI_API_KEY")
    if not key:
        raise RuntimeError("Set FIREWORKS_API_KEY before using fireworks_ai models")
    return key

# call before any completion
key = get_fireworks_key()

Try / catch

try:
    resp = litellm.completion(model="fireworks_ai/...", messages=msgs)
except ValueError as e:
    if "FIREWORKS_API_KEY is not set" in str(e):
        raise RuntimeError("Fireworks credentials missing in deployment") from e
    raise

Prevention

When it happens

Trigger: Calling litellm.completion(model='fireworks_ai/...', messages=[...]) with neither api_key= passed nor FIREWORKS_API_KEY / FIREWORKS_AI_API_KEY present in the environment (or set to an empty string).

Common situations: New integration where the env var was forgotten; .env file not loaded in the deployed environment; variable renamed during a provider migration; secret cleared in CI for a supposedly mocked test.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/5cc306e1d820c330. Report an issue: GitHub.