{"record":{"id":"aaf12a375ee792ec","repo":"BerriAI/litellm","slug":"team-key-for-team-user-api-key-dict-team-id-not","errorCode":null,"errorMessage":"Team key for team={user_api_key_dict.team_id} not authorized to access this team={team_table.team_id}","messagePattern":"Team key for team=(.+?) not authorized to access this team=(.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"error","filePath":"litellm/proxy/management_endpoints/team_endpoints.py","lineNumber":4027,"sourceCode":"        records=records,\n        prisma_client=prisma_client,\n    )\n\n\nasync def validate_membership(user_api_key_dict: UserAPIKeyAuth, team_table: LiteLLM_TeamTable):\n    if (\n        user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN.value\n        or user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY.value\n    ):\n        return\n\n    if user_api_key_dict.team_id == team_table.team_id:  # allow team keys to check their info\n        return\n\n    # Handle case where user_id is None (e.g., team key accessing different team)\n    if user_api_key_dict.user_id is None:\n        if user_api_key_dict.team_id is not None:\n            raise HTTPException(\n                status_code=403,\n                detail={\n                    \"error\": f\"Team key for team={user_api_key_dict.team_id} not authorized to access this team={team_table.team_id}\"\n                },\n            )\n        else:\n            raise HTTPException(\n                status_code=403,\n                detail={\n                    \"error\": f\"API key not authorized to access this team={team_table.team_id}. No user_id or team_id associated with this key.\"\n                },\n            )\n\n    # Check direct team membership\n    if user_api_key_dict.user_id in [m.user_id for m in team_table.members_with_roles]:\n        return\n\n    # Check if user is an org admin for the team's organization","sourceCodeStart":4009,"sourceCodeEnd":4045,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/team_endpoints.py#L4009-L4045","documentation":"Error \"Team key for team={user_api_key_dict.team_id} not authorized to access this team={team_table.team_id}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/management_endpoints/team_endpoints.py:4027 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use an API key that belongs to the target team, or a proxy admin key."],"exampleFix":null,"handlingStrategy":null,"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"}