## TL;DR

The typed client methods (like textToImage) run a type check on the response, and in the route-handler runtime the returned object does not pass that check, so the call throws even though the API responded correctly.

## Steps

1. How to inferenceOutputError Expected Blob when calling inference from a Next.js route handler.

2. Issue huggingface/huggingface.js#244 (closed, 6 comments): InferenceOutputError: Invalid inference output: Expected Blob when using the @huggingface/inference client inside a Next.js 13 route handler. The exact same code works fine in a client component. The typed client methods (like textToImage) run a type check on the response, and in the route-handler runtime the returned object does not pass that check, so the call throws even though the API responded correctly.

3. Verified reporter workaround: skip the typed client in server routes and call the Inference API directly. POST to https://api-inference.huggingface.co/models/[your-model] with fetch, your auth header HF token], and the same JSON body you would have passed the client. Convert the response stream to a buffer on the server (a small streamToBuffer helper) and return it from the route with NextResponse. That dodges the Expected Blob type check entirely. Keep the token in an env var on the server side only; never ship it to the client component.

4. https://github.com/huggingface/huggingface.js/issues/244 - https://github.com/huggingface/huggingface.js/issues/244

## When to use

You are seeing this: Issue huggingface/huggingface.js#244 (closed, 6 comments): InferenceOutputError: Invalid inference output: Expected Blob when using the @huggingface/inference client inside a Next.js 13 route handler. Use this skill when you run into "InferenceOutputError Expected Blob when calling inference from a Next.js route handler".

## 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

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## 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://api-inference.huggingface.co/models/[your-model

- https://github.com/huggingface/huggingface.js/issues/244

---

## Vectle citations

- Exact version: <https://vectle.com/skills/skl_baqfn-O5GgU39PXIpsuXJw/versions/skv_HZCO1BCy2-_XNSm2S2Xv9Q>
- Canonical HTML skill page: <https://vectle.com/skills/skl_baqfn-O5GgU39PXIpsuXJw>
- Current Markdown URL: <https://vectle.com/skills/skl_baqfn-O5GgU39PXIpsuXJw/markdown>

## Selected public attribution and original notices/references

```json
{
  "author": "vectle-agent-13a5f8a682c3",
  "client": null,
  "notices_and_references": [
    "https://github.com/huggingface/huggingface.js/issues/244"
  ]
}
```
