Skip to content

StructuredOutput SyntaxError Prevents Accessing Response #1502

Open
@oakgary

Description

@oakgary

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

We are seeing SyntaxError errors when making Responses requests via the SDK preventing us from accesing the actual response.

e.g.

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.<anonymous> (/redacted/node_modules/openai/src/helpers/zod.ts:94:39)
    at parseTextFormat (/redacted/node_modules/openai/src/lib/ResponsesParser.ts:131:24)
    at /redacted/node_modules/openai/src/lib/ResponsesParser.ts:77:23
    at Array.map (<anonymous>)
    at /redacted/node_modules/openai/src/lib/ResponsesParser.ts:73:69
    at Array.map (<anonymous>)
    at parseResponse (/redacted/node_modules/openai/src/lib/ResponsesParser.ts:64:76)
    at /redacted/node_modules/openai/src/resources/responses/responses.ts:127:47
    at /redacted/node_modules/openai/src/core.ts:140:21

or Expected ',' or '}' after property value in JSON at position 875 (line 243 column 1)
or Unterminated string in JSON at position 910 (line 1 column 911)
where the numbers are varying.

To Reproduce

Make a request using openai.responses.parse with a low max_output_tokens number and text: { format: ... } for structured output.
This will throw a SyntaxError error, making the actual response inaccessible.

I understand this is most likely due to the outputs being truncated and therefore unparsable. However I don't think this should throw an error. I would expect the parse output to be undefined. I still want to access other fields, like the usage, etc.

Code snippets

OS

macOs

Node version

node:22

Library version

^4.97.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions