BerriAI/litellm · error · AgentRunError

LiteLLM rejected your key (HTTP {resp.status_code}). Run `li

Error message

LiteLLM rejected your key (HTTP {resp.status_code}). Run `lite login` to refresh it, or pass a valid --api-key.

What it means

Pre-flight probe in the agents CLI: GET {base}/v1/models returned an HTTP error status, so the stored/explicit API key is rejected; the user is directed to re-login or pass --api-key before the agent subprocess launches.

Source

Thrown at litellm/proxy/client/cli/commands/agents.py:140

    api_key: str,
    *,
    get: Callable[..., requests.Response] = requests.get,
) -> None:
    """Probe the proxy with the key so bad creds fail here, not inside the agent.

    Raises AgentRunError when the proxy is unreachable or rejects the key. Other
    non-2xx responses are tolerated; the agent's own call is the real test.
    """
    url: Final = base_url.rstrip("/") + "/v1/models"
    try:
        resp: Final = get(url, headers={"Authorization": f"Bearer {api_key}"}, timeout=10)
    except requests.RequestException as e:
        raise AgentRunError(
            f"Could not reach the LiteLLM proxy at {base_url.rstrip('/')}: {e}. "
            "Is it running, and is --base-url (or LITELLM_PROXY_URL) correct?"
        )
    if resp.status_code in (401, 403):
        raise AgentRunError(
            f"LiteLLM rejected your key (HTTP {resp.status_code}). "
            "Run `lite login` to refresh it, or pass a valid --api-key."
        )


_WINDOWS_SHIM_SUFFIXES: Final[frozenset[str]] = frozenset({".cmd", ".bat"})
_CMD_PERCENT_GUARD: Final = "%%cd:~,%"
_CMD_LINE_BREAKS: Final = ("\r", "\n")


def _double_trailing_backslashes(segment: str) -> str:
    bare: Final = segment.rstrip("\\")
    return bare + "\\" * 2 * (len(segment) - len(bare))


def _quote_for_cmd(token: str) -> str:
    """Quote one token so both parsers that read it see the original text.

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Run `lite login` to refresh your credentials.
  2. Pass a valid key with --api-key.

Example fix

lite login
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/client/cli/commands/agents.py:140 when the library encounters an invalid state.

Common situations: The CLI's stored or provided API key was rejected by the proxy.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/a3c2f4545249981e. Report an issue: GitHub.