{"record":{"id":"851c031f99f73942","repo":"BerriAI/litellm","slug":"internal-server-error","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"enterprise/litellm_enterprise/enterprise_callbacks/example_logging_api.py","lineNumber":21,"sourceCode":"\napp = FastAPI()\n\n\n@app.post(\"/log-event\")\nasync def log_event(request: Request):\n    try:\n        print(\"Received /log-event request\")  # noqa\n        # Assuming the incoming request has JSON data\n        data = await request.json()\n        print(\"Received request data:\")  # noqa\n        print(data)  # noqa\n\n        # Your additional logic can go here\n        # For now, just printing the received data\n\n        return {\"message\": \"Request received successfully\"}\n    except Exception:\n        raise HTTPException(status_code=500, detail=\"Internal Server Error\")\n\n\nif __name__ == \"__main__\":\n    import uvicorn\n\n    uvicorn.run(app, host=\"127.0.0.1\", port=8000)\n","sourceCodeStart":3,"sourceCodeEnd":28,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/enterprise_callbacks/example_logging_api.py#L3-L28","documentation":"Raised as HTTPException 500 in the example_logging_api FastAPI app — a reference implementation showing how to build a custom /log-event callback receiver for litellm proxy logging callbacks. Any exception while parsing the inbound request (most commonly request.json() failing on a non-JSON body) is converted to a bare 500 with no detail.","triggerScenarios":"The litellm proxy is configured with a generic logging callback POSTing to this example server, and a callback payload arrives that is not valid JSON (content-type mismatch, truncated body), causing await request.json() to raise. This is example code, not production API surface.","commonSituations":"Users running the example callback server as-is and sending test events with curl without a JSON content-type; proxy versions whose callback payload shape changed; treating this demo server as a production logging endpoint.","solutions":["Treat this as example code — do not deploy it unmodified in production; copy it into your own service and add real error handling.","Reproduce the failing payload from the proxy logs and validate it parses as JSON.","Ensure the sender sets Content-Type: application/json.","Replace the bare except with one that logs the exception (e.g. via app logger / exception(logger)) before returning 500."],"exampleFix":"# before\n    except Exception:\n        raise HTTPException(status_code=500, detail=\"Internal Server Error\")\n\n# after\n    except Exception:\n        import logging\n        logging.exception(\"failed to process /log-event payload\")\n        raise HTTPException(status_code=400, detail=\"Invalid JSON payload\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"@app.post(\"/log-event\")\nasync def log_event(request: Request):\n    try:\n        data = await request.json()\n    except json.JSONDecodeError as e:\n        logging.warning(\"invalid callback payload: %s\", e)\n        return {\"status\": \"ignored\"}  # never 500 the proxy's callback sender\n    return {\"message\": \"ok\"}","preventionTips":["Never deploy the example logging API unmodified — add real parsing and error handling.","Always send callbacks with Content-Type: application/json.","Return 2xx for ignorable payloads so the proxy's callback sender does not retry spam.","Log request bodies on failure so payload-shape changes are debuggable."],"tags":["enterprise","example","callback-server","fastapi","http-500"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}