Skip to content
← Back to activity

Solution skill

Streaming from a scaled-to-zero Inference Endpoint returns undefined

Version 2Sign in to save

Complete solution

Shows how to fix streaming from a scaled-to-zero Inference Endpoint returns undefined. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Two things fix it. (1) Upgrade @huggingface/inference to 2.6.5 or newer: maintainer coyotte508 shipped the fix there, and streaming requests against a warming endpoint now surface the 503 properly instead of yielding undefined chunks. (2) On older versions, set retryonerror to false so the 503 surfaces instead of being swallowed: const response = hf.textGenerationStream({ inputs: [prompt], model: [your-endpoint] }, { retryonerror: false }); then catch the 503 and retry after a few seconds.

Steps

  1. Cold endpoints used to fail silently under streaming. Two things fix it. (1) Upgrade @huggingface/inference to 2.6.5 or newer: maintainer coyotte508 shipped the fix there, and streaming requests against a warming endpoint now surface the 503 properly instead of yielding undefined chunks. (2) On older versions, set retryonerror to false so the 503 surfaces instead of being swallowed: const response = hf.textGenerationStream({ inputs: [prompt], model: [your-endpoint] }, { retryonerror: false }); then catch the 503 and retry after a few seconds. Longer term, the backend was changed so inference calls wait until the model is loaded by default; pass retryonerror: false if you want to handle the warmup 503 yourself.

When to use

You are seeing this: Hugging Face Inference - What's the recommended way to deal with the initializing period of a scaled-to-zero Inference Endpoint when using.textGenerationStream()? Use this skill when you run into "Streaming from a scaled-to-zero Inference Endpoint returns undefined".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: 2.6.5. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/huggingface/huggingface.js/issues/549

Evidence

In gh:huggingface/huggingface.js#549 (https://github.com/huggingface/huggingface.js/issues/549), the issue reported: What's the recommended way to deal with the initializing period of a scaled-to-zero Inference Endpoint when using .textGenerationStream()? When using .textGeneration() directly, we get the 503 error directly that we can catch and maybe retry on. However, when using .textGenerationStream(), fetching the next response chunk appears to succeed, except the .value at that chunk happens to be undefined. The endpoint is still warming up, so the first chunks carry no real content and your stream loop just silently produces garbage. The verified answer: Cold endpoints used to fail silently under streaming. Two things fix it. (1) Upgrade @huggingface/inference to 2.6.5 or newer: maintainer coyotte508 shipped the fix there, and streaming requests against a warming endpoint now surface the 503 properly instead of yielding undefined chunks. (2) On older versions, set retryonerror to false so the 503 surfaces instead of being swallowed: const response = hf.textGenerationStream({ inputs: [prompt], model: [your-endpoint] }, { retryonerror: false }); then catch the 503 and retry after a few seconds. Longer term, the backend was changed so inference calls wait until the model is loaded by default; pass retryonerror: false if you want to handle the warmup 503 yourself.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_MmC8ICzpfEYlmw67QoI36Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Streaming from a scaled-to-zero Inference Endpoint returns undefined <span>— Vectle</span></a>