Skip to content

Fix ChatCompletionStreamOptions serialization for OpenAI-compatible providers#512

Merged
64bit merged 1 commit into64bit:mainfrom
spiceai:evgenii/2026-01-08/upstream-optional-fields-fix
Jan 11, 2026
Merged

Fix ChatCompletionStreamOptions serialization for OpenAI-compatible providers#512
64bit merged 1 commit into64bit:mainfrom
spiceai:evgenii/2026-01-08/upstream-optional-fields-fix

Conversation

@ewgenius
Copy link
Contributor

@ewgenius ewgenius commented Jan 8, 2026

Problem

When include_obfuscation is None, it is serialized as "include_obfuscation": null instead of being omitted from the JSON payload. Some OpenAI-compatible providers (e.g., NVIDIA NIM) reject requests containing unknown fields, causing errors like:

failed deserialization of: {"object":"error","message":"[{'type': 'extra_forbidden', 'loc': ('body', 'stream_options', 'include_obfuscation'), 'msg': 'Extra inputs are not permitted', 'input': None}]","type":"BadRequestError","param":null,"code":400}

Added #[serde(skip_serializing_if = "Option::is_none")] to both fields in ChatCompletionStreamOptions, so None values are omitted from serialization rather than being sent as null

Add serde attribute to omit None values for include_usage and
include_obfuscation. Add tests to verify correct serialization and
deserialization behavior.
Copy link
Owner

@64bit 64bit left a comment

Choose a reason for hiding this comment

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

Usually for this test is not required, thanks for the PR!

@64bit 64bit merged commit 6708a34 into 64bit:main Jan 11, 2026
142 checks passed
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.

2 participants