{"record":{"id":"4d8906771e761912","repo":"BerriAI/litellm","slug":"unsupported-http-method-method-4d8906","errorCode":null,"errorMessage":"Unsupported HTTP method: {method}","messagePattern":"Unsupported HTTP method: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_hooks/custom_code/primitives.py","lineNumber":511,"sourceCode":"    headers: dict[str, str] | None,\n    body: Any | None,\n    timeout: float,\n) -> httpx.Response:\n    \"\"\"Execute the HTTP request using the appropriate client method.\"\"\"\n    json_body, data_body = _prepare_http_body(body)\n\n    if method == \"GET\":\n        return await client.get(url=url, headers=headers)\n    elif method == \"POST\":\n        return await client.post(url=url, headers=headers, json=json_body, data=data_body, timeout=timeout)\n    elif method == \"PUT\":\n        return await client.put(url=url, headers=headers, json=json_body, data=data_body, timeout=timeout)\n    elif method == \"DELETE\":\n        return await client.delete(url=url, headers=headers, json=json_body, data=data_body, timeout=timeout)\n    elif method == \"PATCH\":\n        return await client.patch(url=url, headers=headers, json=json_body, data=data_body, timeout=timeout)\n    else:\n        raise ValueError(f\"Unsupported HTTP method: {method}\")\n\n\nasync def http_get(\n    url: str,\n    headers: dict[str, str] | None = None,\n    timeout: float | None = None,\n) -> dict[str, Any]:\n    \"\"\"\n    Make an async HTTP GET request.\n\n    Convenience wrapper around http_request for GET requests.\n\n    Args:\n        url: The URL to request\n        headers: Optional dict of HTTP headers\n        timeout: Optional timeout in seconds\n\n    Returns:","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_hooks/custom_code/primitives.py#L493-L529","documentation":"ValueError raised by the sandbox's http_request primitive when the method argument is not exactly one of GET, POST, PUT, DELETE, PATCH (uppercase, case-sensitive). The custom-code guardrail deliberately exposes a minimal HTTP surface; any other method — HEAD, OPTIONS, or lowercase 'get' — is rejected before any network call is made.","triggerScenarios":"Custom code calls http_request('HEAD', url) for a health probe, http_request('get', url) with wrong case, or 'OPTIONS' to probe CORS support; the dispatch chain falls through to the else branch and raises.","commonSituations":"Porting code that used requests/httpx directly where methods are case-insensitive; method strings sourced from config that arrive lowercase; HEAD-style health checks.","solutions":["Use one of the five supported uppercase methods: GET, POST, PUT, DELETE, PATCH","Substitute HEAD with GET and ignore the response body","Prefer the convenience wrappers the sandbox exposes (http_get, http_post) which fix the method for you"],"exampleFix":"# before\nresp = await http_request('HEAD', 'https://api.example.com/health')\n\n# after\nresp = await http_get('https://api.example.com/health')","handlingStrategy":"type-guard","validationCode":"_SUPPORTED = {'GET', 'POST', 'PUT', 'DELETE', 'PATCH'}\n\nmethod = (method or 'GET').upper()\nif method not in _SUPPORTED:\n    raise ValueError(f'use one of {sorted(_SUPPORTED)}; got {method!r}')\nresp = await http_request(method, url, json_body=payload)","typeGuard":"def is_supported_http_method(method: object) -> bool:\n    return isinstance(method, str) and method in {'GET', 'POST', 'PUT', 'DELETE', 'PATCH'}","tryCatchPattern":"try:\n    resp = await http_request(method, url)\nexcept ValueError as e:\n    if 'Unsupported HTTP method' in str(e):\n        resp = await http_get(url)  # fall back to the supported surface\n    else:\n        raise","preventionTips":["Normalize method strings to uppercase before calling http_request","Prefer the http_get/http_post wrappers which encode the supported method for you","If a config file supplies the method, validate it against the allowlist at load time"],"tags":["guardrails","custom-code","sandbox","http-client","unsupported-method"],"backgroundTag":"unsupported-http-method","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}