Skip to content

fix(types): omit ImageUrl.detail when None#564

Merged
64bit merged 1 commit into
64bit:mainfrom
yourlogarithm:fix/omit-null-image-detail
Jun 18, 2026
Merged

fix(types): omit ImageUrl.detail when None#564
64bit merged 1 commit into
64bit:mainfrom
yourlogarithm:fix/omit-null-image-detail

Conversation

@yourlogarithm

Copy link
Copy Markdown
Contributor

Problem

ImageUrl.detail (async-openai/src/types/shared/image_url.rs) is an Option<ImageDetail> with no skip_serializing_if, so when it is None the 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 detail as a Literal['auto','low','high'] and reject the explicit null with an HTTP 400:

1 validation error for ChatCompletionContentPartImageParam
image_url.detail
  Input should be 'auto', 'low' or 'high' [type=literal_error, input_value=None, input_type=NoneType]

Since detail is 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")] to ImageUrl.detail so the field is omitted when None. No behavioural change against the OpenAI API itself; it just stops emitting an explicit null that some compatible backends reject.

#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<ImageDetail>,

Deserialization is unaffected (the field already round-trips), and explicit values (Some(Auto/Low/High)) still serialize as before.

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 64bit left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for detailed description and PR!

@64bit 64bit merged commit 7604d6d into 64bit:main Jun 18, 2026
103 checks passed
@yourlogarithm yourlogarithm deleted the fix/omit-null-image-detail branch June 19, 2026 08:22
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.

3 participants