nextjs - 💡(How to fix) Fix Large HTTP body truncated in API route (using vercel-ai-sdk) [5 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85810Fetched 2026-04-08 02:13:47
View on GitHub
Comments
5
Participants
4
Timeline
10
Reactions
1
Author
Timeline (top)
commented ×5subscribed ×3issue_type_added ×1labeled ×1

Error Message

SyntaxError: Unexpected token 'a', "are as a S"... is not valid JSON at JSON.parse (<anonymous>) at g (/home/bun/app/.next/server/chunks/my-app_260fae17..js:46:2376) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async /home/bun/app/.next/server/chunks/my-app_260fae17..js:46:902 at async /home/bun/app/.next/server/chunks/my-app_4aac2b5c..js:2785:9624 at async r$.do (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:23:20293) at async r$.handle (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:23:25083) at async u (/home/bun/app/.next/server/chunks/my-app_260fae17..js:46:5991) at async r$.handleResponse (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:19:73806) at async c (/home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:7029)

Root Cause

Use Vercel AI SDK's useChat to stream messages. It makes an HTTP request to /api/chat. Request body gets large (around 10kb) since we add many things into the context. However the root cause is not AI SDK since we see the same error for other API routes that dont use AI SDK but have a large payload.

Code Example

SyntaxError: Unexpected token 'a', "are as a S"... is not valid JSON
    at JSON.parse (<anonymous>)
    at g (/home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:2376)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:902
    at async /home/bun/app/.next/server/chunks/my-app_4aac2b5c._.js:2785:9624
    at async r$.do (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:23:20293)
    at async r$.handle (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:23:25083)
    at async u (/home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:5991)
    at async r$.handleResponse (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:19:73806)
    at async c (/home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:7029)

---

1. Build in `standalone` mode (deployed in GCP VM)
2. `bun` version: 1.2.12
3. `node` version: 23
4. `next` version: 16.0.1
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/needle-ai/needle-mcp

To Reproduce

Use Vercel AI SDK's useChat to stream messages. It makes an HTTP request to /api/chat. Request body gets large (around 10kb) since we add many things into the context. However the root cause is not AI SDK since we see the same error for other API routes that dont use AI SDK but have a large payload.

Requests fail with the following error message

SyntaxError: Unexpected token 'a', "are as a S"... is not valid JSON
    at JSON.parse (<anonymous>)
    at g (/home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:2376)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:902
    at async /home/bun/app/.next/server/chunks/my-app_4aac2b5c._.js:2785:9624
    at async r$.do (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:23:20293)
    at async r$.handle (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:23:25083)
    at async u (/home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:5991)
    at async r$.handleResponse (/home/bun/app/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js:19:73806)
    at async c (/home/bun/app/.next/server/chunks/my-app_260fae17._.js:46:7029)

I traced the line, and figured out that NextRequest.json() is failing due to malformed json body, I examined and saw that it's partial json.

This issue started happening immediately after we updated from NextJS 14 to 16.

Current vs. Expected behavior

Current behaviour: Payload is truncated. Expected behaviour: Request body is not truncated.

Provide environment information

1. Build in `standalone` mode (deployed in GCP VM)
2. `bun` version: 1.2.12
3. `node` version: 23
4. `next` version: 16.0.1

Which area(s) are affected? (Select all that apply)

Dynamic Routes

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

No response

extent analysis

TL;DR

  • The most likely fix is to increase the JSON body parsing limit in NextJS to prevent truncation of large payloads.

Guidance

  • Verify that the issue is indeed caused by the JSON body parsing limit by checking the NextJS documentation for any changes to the default limit between versions 14 and 16.
  • Check the NextRequest.json() method to see if there are any options to increase the parsing limit or handle large payloads.
  • Consider using a streaming JSON parser to handle large payloads instead of loading the entire JSON body into memory.
  • Test the application with a smaller payload to confirm that the issue is indeed related to the payload size.

Example

  • No code example is provided as the issue is related to a specific NextJS version and configuration.

Notes

  • The issue may be specific to the standalone mode or the bun version used, so testing with different configurations may be necessary.
  • The fix may require updating the NextJS configuration or using a different JSON parsing library.

Recommendation

  • Apply workaround: Increase the JSON body parsing limit or use a streaming JSON parser to handle large payloads, as upgrading to a fixed version is not implied in the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING