fix(ai-openai): allow null for fields OpenAI returns null for#2145
Open
lindit wants to merge 1 commit into
Open
fix(ai-openai): allow null for fields OpenAI returns null for#2145lindit wants to merge 1 commit into
lindit wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: b5aeea3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
4 tasks
The OpenAPI spec marks several fields as optional-only that OpenAI actually returns as `null`, causing `HttpClientResponse.schemaBodyJson` to fail with `SchemaError(Expected <type>, got null at [<field>])`: - OpenAIFile.status_details — Files API (createFile / retrieveFile / listFiles): always returned as null in current responses. - Batch.model — null on freshly created batches that haven't been validated yet. - Batch.output_file_id — null until the batch completes successfully. - Batch.error_file_id — null unless errors occurred. Patched the codegen spec to mark each field nullable. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3a43b2a to
b5aeea3
Compare
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.
Summary
OpenAI returns
nullfor several response fields the OpenAPI spec marks as optional-only, causingHttpClientResponse.schemaBodyJsonto fail decoding with:This PR adds JSON Patch entries to
packages/ai/openai/codegen.yamlmarking each field nullable (matching the precedent already set forModelResponseProperties.user,.safety_identifier,.prompt_cache_key, andResponse.usage):OpenAIFile.status_details— Files API (createFile/retrieveFile/listFiles). The fix flows throughUpload.file,ListFiles200,CreateFile200, andRetrieveFile200.Batch.model—nullon freshly created batches that haven't been validated yet.Batch.output_file_id—nulluntil the batch completes successfully.Batch.error_file_id—nullunless errors occurred.After the patch, each field is emitted as
Schema.optionalKey(Schema.Union([Schema.<T>, Schema.Null])).Note on diff size
Generated.tswas last regenerated on 2026-04-22, so this regeneration also picks up ~3 weeks of unrelated upstream OpenAI spec drift (newAdminApiKeyCreateResponsetype, tightened object literals,int64→unixtimeformat swaps, etc.). This is in line with prior regen commits (e.g.c5a73274was 12,529 / 9,373; this one is 1,896 / 678). Happy to split the regen into a separate prep PR if preferred.Note on
Batch.errors(generator bug, not patched)While sweeping
Batch, OpenAI's own spec example shows"errors": null. I tried addingnullable: trueforBatch.errorstoo, but the generator handlesnullable: trueon object-typed properties incorrectly — it produces a degenerateSchema.Union([Schema.Struct(...)])with noSchema.Nullmember, and the corresponding TS type is unchanged. Primitive-typed properties (the four in this PR) work correctly. Worth filing as a separate generator bug; the workaround is to express it viaanyOf: [{...object schema...}, {type: 'null'}]instead ofnullable: true, which is verbose to encode as a JSON Patch.Test plan
pnpm --filter @effect/ai-openai checkpassespnpm --filter @effect/ai-openai testpasses (90 tests)pnpm --filter @effect/ai-openai buildpassespnpm --filter "./packages/ai/**" checkpasses (all 4 AI packages)createFiledecodes whenstatus_details: null,createBatchdecodes whenmodel: null🤖 Generated with Claude Code