{"record":{"id":"a3c2f4545249981e","repo":"BerriAI/litellm","slug":"litellm-rejected-your-key-http-resp-status-code","errorCode":null,"errorMessage":"LiteLLM rejected your key (HTTP {resp.status_code}). Run `lite login` to refresh it, or pass a valid --api-key.","messagePattern":"LiteLLM rejected your key \\(HTTP (.+?)\\)\\. Run `lite login` to refresh it, or pass a valid --api-key\\.","errorType":"exception","errorClass":"AgentRunError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/client/cli/commands/agents.py","lineNumber":140,"sourceCode":"    api_key: str,\n    *,\n    get: Callable[..., requests.Response] = requests.get,\n) -> None:\n    \"\"\"Probe the proxy with the key so bad creds fail here, not inside the agent.\n\n    Raises AgentRunError when the proxy is unreachable or rejects the key. Other\n    non-2xx responses are tolerated; the agent's own call is the real test.\n    \"\"\"\n    url: Final = base_url.rstrip(\"/\") + \"/v1/models\"\n    try:\n        resp: Final = get(url, headers={\"Authorization\": f\"Bearer {api_key}\"}, timeout=10)\n    except requests.RequestException as e:\n        raise AgentRunError(\n            f\"Could not reach the LiteLLM proxy at {base_url.rstrip('/')}: {e}. \"\n            \"Is it running, and is --base-url (or LITELLM_PROXY_URL) correct?\"\n        )\n    if resp.status_code in (401, 403):\n        raise AgentRunError(\n            f\"LiteLLM rejected your key (HTTP {resp.status_code}). \"\n            \"Run `lite login` to refresh it, or pass a valid --api-key.\"\n        )\n\n\n_WINDOWS_SHIM_SUFFIXES: Final[frozenset[str]] = frozenset({\".cmd\", \".bat\"})\n_CMD_PERCENT_GUARD: Final = \"%%cd:~,%\"\n_CMD_LINE_BREAKS: Final = (\"\\r\", \"\\n\")\n\n\ndef _double_trailing_backslashes(segment: str) -> str:\n    bare: Final = segment.rstrip(\"\\\\\")\n    return bare + \"\\\\\" * 2 * (len(segment) - len(bare))\n\n\ndef _quote_for_cmd(token: str) -> str:\n    \"\"\"Quote one token so both parsers that read it see the original text.\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/client/cli/commands/agents.py#L122-L158","documentation":"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.","triggerScenarios":"Thrown at litellm/proxy/client/cli/commands/agents.py:140 when the library encounters an invalid state.","commonSituations":"The CLI's stored or provided API key was rejected by the proxy.","solutions":["Run `lite login` to refresh your credentials.","Pass a valid key with --api-key."],"exampleFix":"lite login","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}