Repository navigation
Conversation
OpenAI-compatible image hosts (e.g. PSNC's llm.hpc.psnc.pl serving Z-Image-Turbo) commonly report absent optional response fields such as `quality` and `background` as an explicit `null` instead of omitting them. The openai-images response schema declared those with Schema.optional, which rejects null, so a valid 200 response failed to decode with "OpenAI Images returned an invalid response". Use optionalNullish for the rendered-setting fields (output_format, size, quality, background), matching the null-tolerant fields already used for data[].url / data[].b64_json, and normalizing null to undefined. Closes anomalyco#60189
There was a problem hiding this comment.
Looks good. I reproduced #60189 from source on the base: a mock OpenAI-compatible host that returns background: null and quality: null gets OpenAI Images returned an invalid response with HTTP 502. With this PR the same request returns the image. The new test fails on the base and passes here. test/image.test.ts, the OpenAI images recorded tests and tsc all pass.
The null-to-undefined handling suits these fields. A null output_format falls back to working out the format from the bytes, just like a missing one, and the streaming events still override output_format as required.
Public API: unchanged. This only changes how provider responses are decoded inside packages/ai.
No blocking concerns.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #60189
Type of change
What does this PR do?
OpenAI-compatible image hosts (e.g. PSNC's
llm.hpc.psnc.plservingZ-Image-Turbo) commonly report absent optional response fields such asqualityandbackgroundas an explicitnullinstead of omitting them.The
openai-imagesresponse schema declared those rendered-setting fields withSchema.optional(Schema.String), which only acceptsundefined— nevernull. So a successful 200 response from such a host failed to decode withOpenAI Images returned an invalid response, and image generation was unusable.This PR switches
output_format,size,qualityandbackgroundtooptionalNullish, which toleratesnulland normalizes it toundefined. This matches the null-tolerant handling already used fordata[].url/data[].b64_jsonin the same response schema.optionalNullish(not plainoptionalNull) keeps the decoded fieldsstring | undefined, so downstream consumers that assumestring | undefinedare unaffected (typecheck passes).How did you verify your code works?
packages/ai/test/image.test.tsthat returns an openai-images response wherequalityandbackgroundarenull(plusurl: null), and asserts it decodes successfully. Before the fix this test failed withExpected string | undefined at ["quality"](the exact decode error from production); after the fix it passes.bun test test/image.test.ts— 41 pass, 0 fail.bun test test/provider/{zai-images,xai-images,alibaba-images,minimax-images,media-entrypoints,meta-images.recorded,xai-images.recorded,zai-images.recorded,openai-images.recorded}.test.ts— 50 pass, 0 fail (no regressions).bun x tsc --noEmitinpackages/ai— passes.Visual
N/A (non-visual protocol fix).
Screenshots / recordings
N/A.
Checklist