GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SDK throws 'Unexpected end of JSON input' on empty response bodies · Issue #7889 · anomalyco/opencode

SDK throws 'Unexpected end of JSON input' on empty response bodies #7889

New issue
Copy link
New issue
Copy link
Closed
#8921
Closed
SDK throws 'Unexpected end of JSON input' on empty response bodies#7889
#8921
Copy link
Assignees
thdxr

Description

@coleleavitt
coleleavitt
opened on Jan 12, 2026
Issue body actions

Bug Description

The SDK crashes with SyntaxError: Unexpected end of JSON input when the server returns an empty response body without proper Content-Length: 0 header or 204 status code.

Steps to Reproduce

  1. Make an API call that returns an empty body with status 200
  2. SDK attempts to parse the empty body as JSON
  3. Crashes at client.gen.ts:167

Error Message

SyntaxError: Unexpected end of JSON input
    at json (unknown)
    at <anonymous> (../sdk/js/src/v2/gen/client/client.gen.ts:167:33)

Expected Behavior

  • Empty responses should be handled gracefully (return {})
  • Malformed JSON should provide actionable error messages with status code and URL

Root Cause

  1. Client-side: SDK only checks for status === 204 or Content-Length === "0" before attempting JSON parse. Empty body with 200 status and no Content-Length header falls through to response.json() which throws.

  2. Server-side: OPTIONS handler in /packages/console/app/src/routes/zen/v1/models.ts returns status: 200 with null body instead of status: 204.

Proposed Fix

  • Read response as text first, only parse if non-empty
  • Add try-catch with contextual error messages for malformed JSON
  • Fix server to return proper 204 status for empty responses

Related Issues

  • Unexpected end of json #7715 - Same bug report (duplicate)
  • fix(sdk): improve JSON parsing error handling with contextual messages #7618 - Similar fix attempt (error messages only, doesn't prevent the crash)

Not Related (different root causes)

  • JSON parsing failed: Text #2188, task tool "SyntaxError: Unexpected end of JSON input" #3034, Incomplete JSON when writing out files #5890, [Bug] JSON Parse Error with Zhipu GLM-4.7: Stream chunks are concatenated incorrectly #7692 - These are about model-generated malformed JSON, not SDK response parsing

Activity

  1. github-actions
    assigned
    thdxr
    on Jan 12, 2026
  2. github-actions commented on Jan 12, 2026

    @github-actions
    github-actionsBot
    on Jan 12, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of existing issues. Please check:

    • Unexpected end of json #7715: Unexpected end of json

    Feel free to ignore if none of these address your specific case.

  3. jimgrubb commented on Jan 12, 2026

    @jimgrubb
    jimgrubb
    on Jan 12, 2026
    More actions

    Affected Model: Zen GLM-4.7
    Reproduced: 2 times
    Rate limit error before crash:
    High concurrency usage of this API, please reduce concurrency or contact customer... retrying in 17s attempt #5
    Additional context: The JSON parsing error occurred after seeing rate limiting messages. May be related to truncated/retry responses under load.

  4. dhruvkej9 commented on Jan 12, 2026

    @dhruvkej9
    dhruvkej9
    on Jan 12, 2026
    More actions

    @thdxr any easy temp. way to fix it ??

    Have to restart opencode mid-session due to this.

  5. coleleavitt
    added a commit that references this issue on Jan 16, 2026

    chore(sdk): update @hey-api/openapi-ts to 0.90.4

    This issue will close once commit 927c494 is merged into the 'dev' branch.
    927c494
  6. rekram1-node
    closed this as completedin #8921on Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @thdxr
    thdxr

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.