BerriAI/litellm · error · ValueError

Failed to fetch models from Fireworks AI. Status code: {resp

Error message

Failed to fetch models from Fireworks AI. Status code: {response.status_code}, Response: {response.json()}

What it means

FireworksAIConfig.get_models() performs a GET to {api_base}/v1/accounts/{account_id}/models with a Bearer token. Any non-200 status code (401/403 bad key, 404 wrong account id, 429 rate limit, 5xx) triggers this ValueError, embedding the HTTP status and the parsed JSON body from Fireworks in the message for diagnosis.

Source

Thrown at litellm/llms/fireworks_ai/chat/transformation.py:782

            raise ValueError(
                "FIREWORKS_API_BASE or FIREWORKS_API_KEY is not set. Please set the environment variable, to query Fireworks AI's `/models` endpoint."
            )

        account_id: Final = get_secret_str("FIREWORKS_ACCOUNT_ID")
        if account_id is None:
            raise ValueError(
                "FIREWORKS_ACCOUNT_ID is not set. Please set the environment variable, to query Fireworks AI's `/models` endpoint."
            )

        base = api_base.rstrip("/")
        base = base.removesuffix("/v1")
        response: Final = litellm.module_level_client.get(
            url=f"{base}/v1/accounts/{account_id}/models",
            headers={"Authorization": f"Bearer {api_key}"},
        )

        if response.status_code != 200:
            raise ValueError(
                f"Failed to fetch models from Fireworks AI. Status code: {response.status_code}, Response: {response.json()}"
            )

        models: Final = response.json()["models"]

        return ["fireworks_ai/" + model["name"] for model in models]

    @staticmethod
    def get_api_key(api_key: str | None = None) -> str | None:
        return api_key or (
            get_secret_str("FIREWORKS_API_KEY")
            or get_secret_str("FIREWORKS_AI_API_KEY")
            or get_secret_str("FIREWORKSAI_API_KEY")
            or get_secret_str("FIREWORKS_AI_TOKEN")
        )


class FireworksAIChatCompletionStreamingHandler(OpenAIChatCompletionStreamingHandler):

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the embedded status/body: 401/403 means fix FIREWORKS_API_KEY; 404 means FIREWORKS_ACCOUNT_ID is wrong for that key; 429 means back off and retry.
  2. Verify the pair (key, account id) with a direct curl: curl -H "Authorization: Bearer $FIREWORKS_API_KEY" https://api.fireworks.ai/v1/accounts/$FIREWORKS_ACCOUNT_ID/models.
  3. Wrap model listing in retry-with-backoff for 429/5xx responses so transient Fireworks incidents do not crash startup.

Example fix

# before
models = litellm.get_model_list('fireworks_ai')  # crashes on any non-200

# after
import time
for attempt in range(3):
    try:
        models = litellm.get_model_list('fireworks_ai')
        break
    except ValueError as e:
        if 'Status code: 429' in str(e) or 'Status code: 5' in str(e):
            time.sleep(2 ** attempt)
        else:
            raise
Defensive patterns

Strategy: retry

Try / catch

import re, time

def list_fireworks_models():
    for attempt in range(4):
        try:
            return litellm.get_model_list("fireworks_ai")
        except ValueError as e:
            msg = str(e)
            if "Status code: 429" in msg or re.search(r"Status code: 5\\d\\d", msg):
                time.sleep(2 ** attempt)
                continue
            raise  # 401/403/404 are configuration bugs, not retryable
    raise RuntimeError("Fireworks /models unavailable after retries")

Prevention

When it happens

Trigger: FIREWORKS_API_KEY is invalid/revoked; FIREWORKS_ACCOUNT_ID does not belong to that key's workspace; hitting Fireworks rate limits; a transient 5xx from the models endpoint.

Common situations: Rotated API key but stale value in the environment; copy-pasted account id from the wrong Fireworks project; periodic model-refresh jobs that start failing after a quota change or key expiry.

Related errors


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