# Frequent 504 Gateway Timeout Errors on Inference API – sentence-transformers/all-MiniLM-L6-v2

**URL:** <https://discuss.huggingface.co/t/frequent-504-gateway-timeout-errors-on-inference-api-sentence-transformers-all-minilm-l6-v2/173034>\
**Category:** Beginners\
**Created:** [February 2, 2026, 10:29pm UTC](https://discuss.huggingface.co/t/frequent-504-gateway-timeout-errors-on-inference-api-sentence-transformers-all-minilm-l6-v2/173034 "2026-02-02T22:29:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MathanRamar](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@MathanRamar](https://discuss.huggingface.co/u/MathanRamar)\
**Post date:** [February 2, 2026, 10:29pm UTC](https://discuss.huggingface.co/t/frequent-504-gateway-timeout-errors-on-inference-api-sentence-transformers-all-minilm-l6-v2/173034/1 "2026-02-02T22:29:36Z")

</div>

Hi Hugging Face Support Team,

We are currently using the Inference API endpoint for the model **sentence-transformers/all-MiniLM-L6-v2** in our production application for semantic similarity scoring.

Recently, we have been experiencing frequent failures with the following error:

504 Server Error: Gateway Time-out  
[router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2](http://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2)

Details:  
• Multiple retries triggered  
• Each request waits ~30–60 seconds before timing out  
• Previously the same requests were completing quickly  
• No changes were made on our server or application side  
• This issue occurs intermittently but very frequently under moderate load

Our usage pattern:  
• Multiple similarity requests per document (batch style)  
• Requests made sequentially via HTTPS POST  
• Python requests library

Could you please confirm:

1. Whether there are current rate limits or throttling applied to this endpoint?

2. If the model is under heavy load or cold-start delays?

3. Recommended best practices for higher reliability (batching / dedicated endpoints / paid tier)?

4. Whether upgrading to a paid or dedicated endpoint would avoid these timeouts?

This issue is affecting our service reliability, so your guidance would be greatly appreciated.

Thank you for your supports

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 3, 2026, 12:32am UTC](https://discuss.huggingface.co/t/frequent-504-gateway-timeout-errors-on-inference-api-sentence-transformers-all-minilm-l6-v2/173034/2 "2026-02-03T00:32:44Z")

</div>

If the error is 504, it probably doesn’t mean you’ve hit an account-level limit. However, free Endpoints are fundamentally published for demo purposes, so you generally shouldn’t expect them to be very stable for production use.😅

If you’re using it for product integration, I recommend using a Dedicated Endpoint or using [TEI](https://huggingface.co/docs/text-embeddings-inference/index) to host it on your own server.

* * *

## What a `504` means on `router.huggingface.co/hf-inference/...`

A **`504 Gateway Time-out`** from `router.huggingface.co` usually means:

- the **router (gateway)** waited too long for an upstream backend to produce a response, then gave up; and
- your client-side timeout settings generally **cannot override** a server-side gateway cutoff.

A Hugging Face forum deep-dive on timeouts describes this pattern as a **gateway/proxy cap** , distinct from a normal application error body. ([Hugging Face Forums](https://discuss.huggingface.co/t/inquiry-about-120s-timeout-on-hugging-face-inference-endpoint-for-llama-3-1-8b/147764 "Inquiry About 120s Timeout on Hugging Face Inference Endpoint for Llama 3.1-8B - Models - Hugging Face Forums"))

This fits your symptoms (30–60s “hang” → `504`) more than classic rate limiting.

* * *

## Important: make sure you are using the “pipeline” URL for this model

For `sentence-transformers/all-MiniLM-L6-v2`, the model maintainers pinned a notice that the inference URL moved to:

- `.../pipeline/feature-extraction` (embeddings)
- `.../pipeline/sentence-similarity` (similarity)

…and they provide curl examples. ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/discussions/116 "sentence-transformers/all-MiniLM-L6-v2 · Updated feature-extraction API URL"))

If you are calling:

- `https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2`

without `/pipeline/...`, fix that first. It won’t solve all `504`s, but it eliminates a common source of “it used to work quickly, then became flaky”.

* * *

## Answers to your questions

### 1) Are there rate limits or throttling on this endpoint?

**Yes, there are rate limits in the Hugging Face ecosystem** , and hitting them is normally expressed as **HTTP `429 Too Many Requests`** with `RateLimit*` headers (5-minute windows, tiers by plan). ([Hugging Face](https://huggingface.co/docs/hub/en/rate-limits "Hub Rate limits"))

However:

- **Rate limiting ≠ your current symptom**. You’re seeing **`504` after long waits** , which typically indicates **queueing / backend load / router timeouts** , not a clean “you are over quota” response.
- Inference via “HF Inference” is **serverless** and shared; it’s documented as a serverless service (formerly “Inference API (serverless)”). ([Hugging Face](https://huggingface.co/docs/inference-providers/en/providers/hf-inference "HF Inference"))

If you want to confirm whether any of your failures are rate-limit related, log the status codes: if you never see `429`, rate limits are probably not the primary cause.

### 2) Heavy load or cold starts?

Both are plausible on serverless:

- **HF Inference is serverless** and focuses mostly on **CPU inference** use-cases like embeddings / classification. ([Hugging Face](https://huggingface.co/docs/inference-providers/en/providers/hf-inference "HF Inference"))
- Serverless systems can exhibit **cold starts** and/or **capacity contention** , which shows up to clients as timeouts.

There are multiple public reports of intermittent `504`s on HF serverless / router paths, sometimes acknowledged as fixed by staff after reports (suggesting operational issues, not client misuse). ([Hugging Face Forums](https://discuss.huggingface.co/t/huggingface-gateway-time-out-just-how-frequent-is-this/168678 "Huggingface Gateway Time-out: Just how frequent is this? - Inference Endpoints on the Hub - Hugging Face Forums"))

Also note: the official status page can show “Operational” even while particular models/providers have trouble. The status page currently shows operational and “no incidents reported” for recent months (as of Feb 2, 2026). ([Hugging Face Status](https://status.huggingface.co/ "Hugging Face status"))

### 3) Best practices for higher reliability

#### A. Reduce calls: use the **sentence-similarity** pipeline when you can

Instead of many “pairwise” requests, send:

- one `source_sentence`
- many `other_sentences`

in a single request to `.../pipeline/sentence-similarity`. The pinned model discussion explicitly mentions this endpoint. ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/discussions/116 "sentence-transformers/all-MiniLM-L6-v2 · Updated feature-extraction API URL"))  
A staff reply in a real outage thread shows using the Python client’s `sentence_similarity` for this model. ([Hugging Face Forums](https://discuss.huggingface.co/t/api-error-for-model-sentence-transformers-all-minilm-l6-v2/168083 "API error for model sentence-transformers/all-MiniLM-L6-v2 - Transformers - Hugging Face Forums"))

This is often the single biggest reliability improvement because it reduces:

- request count
- per-request overhead
- total time spent waiting in upstream queues

#### B. Batch embeddings (if you must embed) and cache aggressively

If you embed chunks, send **lists of texts** per request (batching), and cache embeddings by `(model_id, text_hash)` so you don’t recompute.

#### C. Keep inputs short and chunk long documents

The model card states: **inputs longer than 256 word pieces are truncated by default**. ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 "sentence-transformers/all-MiniLM-L6-v2"))  
There is also a model discussion about this exact behavior and the need to split into meaningful parts. ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/discussions/14 "sentence-transformers/all-MiniLM-L6-v2"))

If you send long document text repeatedly, you increase latency and cost while potentially not improving embedding quality past the truncation point.

#### D. Connection management + backoff (avoid “retry storms”)

- Use a single `requests.Session()` with connection pooling/keep-alive.
- Use **bounded retries** with exponential backoff + jitter.
- Add a circuit breaker: if `504` rate spikes, stop hammering the endpoint for a short cooldown.

A forum post about repeated gateway timeouts notes that these are often intermittent and sometimes resolve after platform-side fixes—aggressive retries can worsen congestion. ([Hugging Face Forums](https://discuss.huggingface.co/t/huggingface-gateway-time-out-just-how-frequent-is-this/168678 "Huggingface Gateway Time-out: Just how frequent is this? - Inference Endpoints on the Hub - Hugging Face Forums"))

#### E. Prefer the official client when possible

`huggingface_hub.InferenceClient` is designed to work across:

- the (free) Inference API,
- Inference Endpoints,
- third-party Inference Providers. ([Hugging Face](https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_client "Inference"))

In practice, it also reduces “URL drift” problems (wrong base URL / wrong task path) during platform transitions. ([Hugging Face Forums](https://discuss.huggingface.co/t/inquiry-about-120s-timeout-on-hugging-face-inference-endpoint-for-llama-3-1-8b/147764 "Inquiry About 120s Timeout on Hugging Face Inference Endpoint for Llama 3.1-8B - Models - Hugging Face Forums"))

### 4) Would paid or dedicated endpoints avoid these timeouts?

**Paid (PRO) helps with billing/quotas; it does not inherently guarantee the serverless router won’t time out.**

- Inference Providers pricing shows Free vs PRO monthly credits and pay-as-you-go eligibility. ([Hugging Face](https://huggingface.co/docs/inference-providers/en/pricing "Pricing and Billing"))
- But `504` reports exist even when users suspect plan-related issues, and the more direct fix in several threads is “HF staff applied a fix.” ([Hugging Face Forums](https://discuss.huggingface.co/t/huggingface-gateway-time-out-just-how-frequent-is-this/168678 "Huggingface Gateway Time-out: Just how frequent is this? - Inference Endpoints on the Hub - Hugging Face Forums"))

If you need production-grade reliability, the typical step is:

#### Move to dedicated **Inference Endpoints** (recommended)

HF Inference docs explicitly distinguish **HF Inference (serverless)** from **Inference Endpoints (dedicated + autoscaling)**. ([Hugging Face](https://huggingface.co/docs/inference-providers/en/providers/hf-inference "HF Inference"))

#### For embeddings specifically: use **Text Embeddings Inference (TEI)** on a dedicated endpoint

TEI is designed for embeddings workloads and includes **token-based dynamic batching** to improve throughput and reduce tail latency under load. ([Hugging Face](https://huggingface.co/docs/inference-endpoints/en/engines/tei "Text Embeddings Inference (TEI)"))

* * *

## Why your specific workload pattern tends to trigger `504`s

You described:

- “Multiple similarity requests per document”
- “Sequential HTTPS POST”
- “Moderate load”

This often creates an “amplification” effect:

1. Each document triggers many API calls.
2. Under concurrency (multiple docs in flight), calls accumulate faster than they complete.
3. The shared serverless backend queues up work.
4. The router hits its max wait and returns `504`.

If you switch to:

- **one `sentence-similarity` call per document** (or per chunk),
- or **one batched embeddings call per N chunks** ,  
you usually reduce request counts by 10×–100×, which directly lowers timeout risk.

* * *

## Similar cases/issues online (high-signal)

1. **Same model: intermittent `504` / multi-minute delay** , and a staff-suggested workaround using the Python client. (Sep 2025) ([Hugging Face Forums](https://discuss.huggingface.co/t/api-error-for-model-sentence-transformers-all-minilm-l6-v2/168083 "API error for model sentence-transformers/all-MiniLM-L6-v2 - Transformers - Hugging Face Forums"))
2. **Other embedding model (`bge-large-en-v1.5`) timing out** on the same router path; staff applied a fix. (Sep 2025) ([Hugging Face Forums](https://discuss.huggingface.co/t/huggingface-gateway-time-out-just-how-frequent-is-this/168678 "Huggingface Gateway Time-out: Just how frequent is this? - Inference Endpoints on the Hub - Hugging Face Forums"))
3. **General HF inference `503/504` reports** on serverless inference. (Mar–Sep 2025) ([Hugging Face Forums](https://discuss.huggingface.co/t/hf-inference-api-503-504-server-error/148267 "HF Inference API: 503/504 Server Error"))
4. **Discussion of gateway timeout mechanics** and the difference between cold-start waits and gateway caps. ([Hugging Face Forums](https://discuss.huggingface.co/t/inquiry-about-120s-timeout-on-hugging-face-inference-endpoint-for-llama-3-1-8b/147764 "Inquiry About 120s Timeout on Hugging Face Inference Endpoint for Llama 3.1-8B - Models - Hugging Face Forums"))
5. **Platform transition notes** : legacy `api-inference.huggingface.co/models/...` path is being deprecated in favor of the router; mis-targeting endpoints is a recurring source of breakage. ([Hugging Face Forums](https://discuss.huggingface.co/t/inquiry-about-120s-timeout-on-hugging-face-inference-endpoint-for-llama-3-1-8b/147764 "Inquiry About 120s Timeout on Hugging Face Inference Endpoint for Llama 3.1-8B - Models - Hugging Face Forums"))

* * *

## Good docs / guides / references (to implement fixes)

### Official documentation

- **HF Inference (serverless)** overview + examples. ([Hugging Face](https://huggingface.co/docs/inference-providers/en/providers/hf-inference "HF Inference"))
- **Feature Extraction task docs** (embeddings usage examples). ([Hugging Face](https://huggingface.co/docs/inference-providers/en/tasks/feature-extraction "Feature Extraction"))
- **`huggingface_hub.InferenceClient` reference**. ([Hugging Face](https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_client "Inference"))
- **Model pinned “API URL moved”** (use `/pipeline/...`). ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/discussions/116 "sentence-transformers/all-MiniLM-L6-v2 · Updated feature-extraction API URL"))
- **Model card truncation note (256 word pieces)**. ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 "sentence-transformers/all-MiniLM-L6-v2"))
- **TEI on Inference Endpoints** (dynamic batching, optimized inference). ([Hugging Face](https://huggingface.co/docs/inference-endpoints/en/engines/tei "Text Embeddings Inference (TEI)"))
- **Inference Providers pricing/billing** (Free vs PRO, pay-as-you-go). ([Hugging Face](https://huggingface.co/docs/inference-providers/en/pricing "Pricing and Billing"))
- **Hub rate-limits behavior (`429`, headers, tiers)** (useful to distinguish from `504`). ([Hugging Face](https://huggingface.co/docs/hub/en/rate-limits "Hub Rate limits"))

### Community / issues (useful for operational context)

- Timeout/availability threads showing intermittent `504`s and fixes. ([Hugging Face Forums](https://discuss.huggingface.co/t/huggingface-gateway-time-out-just-how-frequent-is-this/168678 "Huggingface Gateway Time-out: Just how frequent is this? - Inference Endpoints on the Hub - Hugging Face Forums"))
- Recent router outage / errors reported on GitHub issues (not specific to your model but relevant to router stability). ([GitHub](https://github.com/huggingface/huggingface_hub/issues/3688 "Production outage – Hugging Face Router returns 500 ..."))

* * *

## Recommended “next actions” checklist

1. **Switch to the correct pipeline URL** (`/pipeline/sentence-similarity` or `/pipeline/feature-extraction`). ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/discussions/116 "sentence-transformers/all-MiniLM-L6-v2 · Updated feature-extraction API URL"))

2. **Collapse per-document calls** into:

3. **Chunk inputs** to fit the model’s practical length constraints. ([Hugging Face](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 "sentence-transformers/all-MiniLM-L6-v2"))

4. Implement **bounded retries + jitter** and a **circuit breaker**.

5. If reliability is a hard requirement: move embeddings to a **dedicated endpoint using TEI**. ([Hugging Face](https://huggingface.co/docs/inference-endpoints/en/engines/tei "Text Embeddings Inference (TEI)"))
