{"record":{"id":"3166cad5a46e1399","repo":"BerriAI/litellm","slug":"failed-to-fetch-agentops-token-response-text","errorCode":null,"errorMessage":"Failed to fetch AgentOps token: {response.text}","messagePattern":"Failed to fetch AgentOps token: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/otel/presets/agentops.py","lineNumber":128,"sourceCode":"            return super().export(spans)\n\n    options: Final = spec.options or {}\n    return _LazyAuthAgentOpsExporter(endpoint=spec.endpoint, api_key=options.get(\"api_key\"))\n\n\ndef _fetch_agentops_jwt(api_key: str) -> dict[str, Any]:\n    # Own a short-lived client rather than ``_get_httpx_client()``: that returns\n    # a process-wide cached ``HTTPHandler`` whose connection pool is shared by\n    # every caller, so closing it here would break concurrent/subsequent\n    # requests. This one-shot auth call gets its own client to close.\n    with httpx.Client(timeout=10) as client:\n        response: Final = client.post(\n            url=_AGENTOPS_AUTH_ENDPOINT,\n            headers={\"Content-Type\": \"application/json\", \"Connection\": \"keep-alive\"},\n            json={\"api_key\": api_key},\n        )\n        if response.status_code != 200:\n            raise RuntimeError(f\"Failed to fetch AgentOps token: {response.text}\")\n        return response.json()\n\n\nregister_exporter_factory(_AGENTOPS_EXPORTER_KIND, _build_agentops_exporter)\n","sourceCodeStart":110,"sourceCodeEnd":133,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/otel/presets/agentops.py#L110-L133","documentation":"Raised by litellm's AgentOps OpenTelemetry preset when it exchanges your AGENTOPS_API_KEY for a short-lived JWT at the AgentOps auth endpoint and gets any non-200 status; the endpoint's response body is embedded in the RuntimeError, so the actual reason (invalid key, revoked key, upstream 5xx) is whatever the auth service replied. It fires inside _fetch_agentops_jwt during exporter construction, i.e. at tracing setup time, before any LLM call or span export happens. Because the call uses a dedicated one-shot httpx.Client with a 10s timeout, it cannot come from a shared connection pool being closed.","triggerScenarios":"Enabling the agentops OTEL exporter (e.g. via litellm's otel presets / AGENTOPS_API_KEY env) with an invalid or revoked API key (401/403 from the auth endpoint); AgentOps auth service returning 5xx during an outage; a corporate proxy intercepting the POST (407/502); network egress to the auth host blocked by firewall.","commonSituations":"Enabling AgentOps tracing in the litellm proxy or SDK with a stale key from an old project; CI secrets with trailing newline/whitespace pasted into AGENTOPS_API_KEY; containers in restricted networks that cannot reach the AgentOps auth host; AgentOps incident.","solutions":["Verify AGENTOPS_API_KEY is current and active in the AgentOps dashboard, with no trailing whitespace or newline (print(len(key)) to check)","Reproduce manually: POST {'api_key': key} to the same auth endpoint (_AGENTOPS_AUTH_ENDPOINT in litellm/integrations/otel/presets/agentops.py) with curl/httpx and read the raw status code and body","Check container egress rules / HTTP(S)_PROXY settings so the POST can reach the AgentOps auth host","If AgentOps is temporarily down, disable the agentops OTEL preset and re-enable later","Upgrade litellm in case the auth endpoint or payload format changed between versions"],"exampleFix":"# before\nos.environ['AGENTOPS_API_KEY'] = maybe_stale_key  # possibly revoked\nsetup_otel_with_agentops()  # RuntimeError: Failed to fetch AgentOps token: ...\n\n# after\nimport httpx, os\nkey = os.environ.get('AGENTOPS_API_KEY', '').strip()\nresp = httpx.post(AUTH_ENDPOINT, json={'api_key': key}, timeout=10)\nif resp.status_code != 200:\n    logger.warning('AgentOps auth preflight failed (%s): %s', resp.status_code, resp.text)\n    # skip enabling the agentops exporter; run without it\nelse:\n    setup_otel_with_agentops()","handlingStrategy":"try-catch","validationCode":"import httpx, os\n\nkey = os.environ.get('AGENTOPS_API_KEY', '').strip()\nif not key:\n    raise RuntimeError('AGENTOPS_API_KEY missing; skip agentops exporter')\nresp = httpx.post(AUTH_ENDPOINT, json={'api_key': key}, timeout=10)\nif resp.status_code != 200:\n    logger.warning('AgentOps auth preflight failed: %s %s', resp.status_code, resp.text)","typeGuard":null,"tryCatchPattern":"try:\n    configure_agentops_otel(api_key=key)\nexcept (RuntimeError, httpx.HTTPError) as e:\n    logger.warning('AgentOps tracing disabled (auth failed): %s', e)\n    # proceed without tracing; do not crash the app on telemetry setup","preventionTips":["Store AGENTOPS_API_KEY in a secret manager and strip whitespace when loading","Add a startup preflight that hits the auth endpoint and alerts on non-200 before enabling the exporter","Treat tracing as optional infrastructure: degrade to no-tracing rather than failing boot"],"tags":["agentops","opentelemetry","authentication","tracing","network"],"backgroundTag":"auth-token-fetch-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}