What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

In Node.js, validate OpenAI structured output by defining a schema and using the official SDK’s client.responses.parse() with zodTextFormat(). Treat the parsed result as optional: check response.output_parsed and handle refusals or incomplete responses. For a temporary 429, respect a valid Retry-After delay, then retry with bounded jittered backoff if needed. Account for retries the SDK already performs so you do not create overlapping retry loops.

Define a schema the API can accept

The examples here use OpenAI’s Responses API and official JavaScript SDK; these details are not a universal contract for other LLM providers. OpenAI Structured Outputs supports a subset of JSON Schema. In strict mode, the schema’s root must be an object and its properties must be required. When a value may be absent, represent that possibility with a required nullable field rather than an omitted property. Unsupported schema features can cause an error.

For the supported schema rules, see OpenAI’s Structured Outputs guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Parse the response and verify that usable data exists

The official Node.js SDK documents client.responses.parse() with zodTextFormat(). A successful HTTP exchange alone does not guarantee that your application has parsed data. The SDK exposes the first successfully parsed text output as response.output_parsed; it is null if no parsed output is available.

  1. Define a Zod schema that follows Structured Outputs’ schema restrictions.
  2. Pass the schema through zodTextFormat() when calling client.responses.parse().
  3. Check response.output_parsed before using the result. Branch on a missing parsed value rather than passing it into downstream code as if it were valid data.
  4. When parsing produced no result, inspect the response status and any incomplete-response details. Handle refusals explicitly as well; a refusal or incomplete response may not yield parsed output.

See the official OpenAI Node.js SDK documentation for the parsing helper and response fields, and the Structured Outputs guide for refusal and incomplete-output behavior.

Diagnose a 429 before retrying

A 429 identifies a rate-limit response, but it does not by itself tell you which limit or condition caused it. Token-rate pressure is one possible cause. Long prompts and oversized output allowances can contribute, so inspect the error details and request shape instead of retrying every 429 blindly. Reduce unnecessary prompt tokens or the output allowance when those are contributing factors.

OpenAI describes rate-limit errors and their causes in its rate limits guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Retry with a delay, jitter, and firm limits

For a retryable temporary 429, use the response’s Retry-After header when it contains a valid delay. That delay is a minimum wait, not a suggestion to retry immediately when it expires. Add a small random delay to reduce the chance that multiple callers retry together. If the header is missing or invalid, use exponential backoff with jitter.

Set both a maximum number of attempts and a maximum total retry duration. Failed retries can count against per-minute limits, so an unbounded loop can worsen the pressure that caused the failure. Stop when either limit is reached and surface the error to the caller or queue the work for a later attempt.

OpenAI’s rate limits guidance discusses retrying with exponential backoff and notes that unsuccessful requests can still count toward rate limits. The delay values and caps should fit your application’s latency and workload; the documentation does not establish one universal retry schedule.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Account for retries in the installed SDK

The official OpenAI SDK already retries eligible errors. If application code adds another retry loop without accounting for SDK-level attempts, one logical request can trigger more calls and wait longer than expected. Check the retry behavior and settings for the SDK version you have installed, then choose one coordinated policy: rely on the SDK defaults where suitable, or configure the SDK and application layer so their retry counts and total time are bounded together.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Retry details can vary with SDK version and settings. Consult the official Node.js SDK documentation and verify the installed version’s behavior rather than assuming a particular delay or attempt count.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.