We’re encountering a 404 Not Found error from the HuggingFace Inference endpoint when the request includes the X-Forwarded-Host header.
The issue appears to stem from the presence of this header, even if we use any private/public domain:
X-Forwarded-Host: google.com
Without Header – Works
When this header is removed, the request succeeds.
Identical payloads and endpoints return valid responses when the header is omitted.
With Header – Fails
If included (even with a valid public domain), the request fails with:
{
"error": "Not Found: google.com"
}
You can use curl command to replicate this issue
curl "https://{your-inference-endpoint}/v1/chat/completions" \
-X POST \
-H "Authorization: Bearer <HF_TOKEN>" \
-H "Content-Type: application/json" \
-H "X-Forwarded-Host: any-domain.com" \
-d '{
"model": "unsloth/DeepSeek-R1-GGUF",
"messages": [{"role": "user", "content": "What is deep learning?"}],
"max_tokens": 150
}'
Please let us know if there’s a workaround or config option available to suppress this behavior.
1 Like
I can confirm this issue exists and have found a workaround. I was experiencing the same 404 error when trying to access the Hugging Face Inference API through Kong Gateway.
my setup was like this:
- Kong Gateway proxying requests to
https://api-inference.huggingface.co/models/{model}/v1/chat/completions
- Kong automatically adds
X-Forwarded-Host
header with the IP/hostname clients use to reach Kong
- Getting consistent 404 responses:
Cannot POST /models/{model}/v1/chat/completions
The X-Forwarded-Host
header does indeed seem to be causing HF’s routing to fail. The header value depends on how clients connect to Kong:
X-Forwarded-Host: localhost
when hitting Kong via localhost
X-Forwarded-Host: 10.0.12.80
when hitting Kong via its network IP
X-Forwarded-Host: my-domain.com
when using a custom domain
Any value in this header causes HF to return 404, regardless of whether it’s a valid domain.
I resolved this by adding a post-function plugin in Kong to strip the problematic header:
plugins:
- name: post-function
config:
access:
- |
ngx.var.upstream_x_forwarded_host=nil
After removing this header, requests to HF Inference API work perfectly through Kong.
This affects anyone trying to proxy HF Inference API requests through reverse proxies that automatically add forwarded headers (Kong, nginx, HAProxy, etc.).
Would be great if HF could either:
- Ignore the
X-Forwarded-Host
header for routing decisions, or
- Document this limitation so proxy users know to strip these headers
Hope this helps others encountering the same issue!
1 Like