Skip to content

fix(ai-openai): allow null for fields OpenAI returns null for#2145

Open
lindit wants to merge 1 commit into
Effect-TS:mainfrom
lindit:fix/openai-files-status-details-null
Open

fix(ai-openai): allow null for fields OpenAI returns null for#2145
lindit wants to merge 1 commit into
Effect-TS:mainfrom
lindit:fix/openai-files-status-details-null

Conversation

@lindit
Copy link
Copy Markdown

@lindit lindit commented May 9, 2026

Summary

OpenAI returns null for several response fields the OpenAPI spec marks as optional-only, causing HttpClientResponse.schemaBodyJson to fail decoding with:

SchemaError(Expected <type>, got null at [<field>])

This PR adds JSON Patch entries to packages/ai/openai/codegen.yaml marking each field nullable (matching the precedent already set for ModelResponseProperties.user, .safety_identifier, .prompt_cache_key, and Response.usage):

  • OpenAIFile.status_details — Files API (createFile / retrieveFile / listFiles). The fix flows through Upload.file, ListFiles200, CreateFile200, and RetrieveFile200.
  • Batch.modelnull on freshly created batches that haven't been validated yet.
  • Batch.output_file_idnull until the batch completes successfully.
  • Batch.error_file_idnull unless errors occurred.

After the patch, each field is emitted as Schema.optionalKey(Schema.Union([Schema.<T>, Schema.Null])).

Note on diff size

Generated.ts was last regenerated on 2026-04-22, so this regeneration also picks up ~3 weeks of unrelated upstream OpenAI spec drift (new AdminApiKeyCreateResponse type, tightened object literals, int64unixtime format swaps, etc.). This is in line with prior regen commits (e.g. c5a73274 was 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 adding nullable: true for Batch.errors too, but the generator handles nullable: true on object-typed properties incorrectly — it produces a degenerate Schema.Union([Schema.Struct(...)]) with no Schema.Null member, 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 via anyOf: [{...object schema...}, {type: 'null'}] instead of nullable: true, which is verbose to encode as a JSON Patch.

Test plan

  • pnpm --filter @effect/ai-openai check passes
  • pnpm --filter @effect/ai-openai test passes (90 tests)
  • pnpm --filter @effect/ai-openai build passes
  • pnpm --filter "./packages/ai/**" check passes (all 4 AI packages)
  • Manual verification against the live OpenAI API: createFile decodes when status_details: null, createBatch decodes when model: null

🤖 Generated with Claude Code

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 9, 2026

🦋 Changeset detected

Latest commit: b5aeea3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@effect/ai-openai Patch
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

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

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>
@lindit lindit force-pushed the fix/openai-files-status-details-null branch from 3a43b2a to b5aeea3 Compare May 9, 2026 03:26
@lindit lindit changed the title fix(ai-openai): allow null for OpenAIFile.status_details fix(ai-openai): allow null for fields OpenAI returns null for May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant