fix(types): omit ImageUrl.detail when None#564
Merged
Conversation
ImageUrl.detail serializes as an explicit "detail": null when unset. The OpenAI API tolerates this, but stricter OpenAI-compatible gateways validate detail as a Literal['auto','low','high'] and reject null with HTTP 400. Skip serializing the field when None so it is simply absent.
64bit
approved these changes
Jun 18, 2026
64bit
left a comment
Owner
There was a problem hiding this comment.
Thank you for detailed description and PR!
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.
Problem
ImageUrl.detail(async-openai/src/types/shared/image_url.rs) is anOption<ImageDetail>with noskip_serializing_if, so when it isNonethe request body carries an explicit"detail": null:{ "type": "image_url", "image_url": { "url": "data:image/png;base64,…", "detail": null } }The official OpenAI API tolerates this, but stricter OpenAI-compatible gateways validate
detailas aLiteral['auto','low','high']and reject the explicitnullwith an HTTP 400:Since
detailis an optional field, the correct wire representation when unset is to omit it entirely (the server then applies its own default,auto).Fix
Add
#[serde(skip_serializing_if = "Option::is_none")]toImageUrl.detailso the field is omitted whenNone. No behavioural change against the OpenAI API itself; it just stops emitting an explicitnullthat some compatible backends reject.Deserialization is unaffected (the field already round-trips), and explicit values (
Some(Auto/Low/High)) still serialize as before.