{"record":{"id":"2f913a4f2f92a49e","repo":"mlflow/mlflow","slug":"deployments-proxy-request-failed-with-error-code","errorCode":null,"errorMessage":"Deployments proxy request failed with error code {response.status_code}. Error message: {response.text}","messagePattern":"Deployments proxy request failed with error code (.+?)\\. Error message: (.+?)","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/server/handlers.py","lineNumber":2469,"sourceCode":"            )\n\n\n@catch_mlflow_exception\ndef gateway_proxy_handler():\n    target_uri = MLFLOW_DEPLOYMENTS_TARGET.get()\n    if not target_uri:\n        # Pretend an empty gateway service is running\n        return {\"endpoints\": []}\n\n    args = request.args if request.method == \"GET\" else request.json\n    gateway_path = args.get(\"gateway_path\")\n    _validate_gateway_path(request.method, gateway_path)\n    json_data = args.get(\"json_data\", None)\n    response = requests.request(request.method, f\"{target_uri}/{gateway_path}\", json=json_data)\n    if response.status_code == 200:\n        return response.json()\n    else:\n        raise MlflowException(\n            message=f\"Deployments proxy request failed with error code {response.status_code}. \"\n            f\"Error message: {response.text}\",\n            error_code=response.status_code,\n        )\n\n\n@catch_mlflow_exception\n@_disable_if_artifacts_only\ndef create_promptlab_run_handler():\n    def assert_arg_exists(arg_name, arg):\n        if not arg:\n            raise MlflowException(\n                message=f\"CreatePromptlabRun request must specify {arg_name}.\",\n                error_code=INVALID_PARAMETER_VALUE,\n            )\n\n    _validate_content_type(request, [\"application/json\"])\n","sourceCodeStart":2451,"sourceCodeEnd":2487,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/server/handlers.py#L2451-L2487","documentation":"The deployments proxy forwards the request to the target AI Gateway server via requests.request(). If the upstream response status is not 200, the handler wraps the upstream status code and response body text into an MlflowException and re-raises it. The error_code is the raw upstream HTTP status, so a 404 or 500 from the gateway surfaces here.","triggerScenarios":"The upstream gateway endpoint does not exist (404), the gateway rejects the payload (400/422), the gateway errors internally (5xx), or target_uri is wrong so the upstream route isn't found.","commonSituations":"Misconfigured target_uri for the gateway server, gateway endpoint deleted or renamed while clients still invoke it, invalid request payload failing gateway-side validation, gateway server down or crashing.","solutions":["Read the 'Error message' in the exception — it contains the upstream response text with the real cause.","Verify the gateway server URL (target_uri) is correct and reachable with curl.","Confirm the endpoint name in 'gateway/{name}/invocations' still exists — use GET api/2.0/endpoints to list endpoints.","Fix the request payload per the gateway's schema, and retry on 5xx."],"exampleFix":"// before\nclient.invoke('my-ep')  # endpoint deleted -> 404 wrapped by proxy\n// after\nendpoints = requests.get(f'{gateway_uri}/api/2.0/endpoints').json()\nassert any(e['name'] == 'my-ep' for e in endpoints['endpoints'])\nclient.invoke('my-ep')","handlingStrategy":"retry","validationCode":"import requests\nif requests.get(f'{target_uri}/api/2.0/endpoints', timeout=5).status_code != 200:\n    raise RuntimeError(f'Gateway at {target_uri} is not healthy')","typeGuard":null,"tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    result = proxy_invoke(endpoint, payload)\nexcept MlflowException as e:\n    if e.error_code in (500, 502, 503, 504):\n        result = proxy_invoke(endpoint, payload)  # retry transient\n    else:\n        log.error('Gateway rejected: %s', e.message)\n        raise","preventionTips":["Health-check the gateway server before invoking endpoints.","Validate endpoint names against GET api/2.0/endpoints.","Log the upstream error text included in the message before retrying.","Validate payloads against the endpoint's declared schema client-side."],"tags":["http","network","upstream-error","mlflow-gateway"],"backgroundTag":"upstream-http-error","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}