Skip to content

Annotating the openai.Omit type so that ModelSettings can be serialized by pydantic #938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2025

Conversation

tconley1428
Copy link
Contributor

@tconley1428 tconley1428 commented Jun 25, 2025

Because openai.Omit is not a type which can be serialized by pydantic, it produces difficulty in consistently serializing/deserializing types across the agents SDK, many of which are pydantic types. This adds an annotation to enable pydantic to serialize Omit, in particular in the case of ModelSettings which contains Omit in its extra_headers

@tconley1428
Copy link
Contributor Author

Turns out that while this supports creating the core schema, it doesn't yet actually allow serialization of an Omit

@seratch seratch added enhancement New feature or request feature:core labels Jun 25, 2025
@seratch seratch requested a review from rm-openai June 25, 2025 23:23
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

LGTM

),
)
Omit = Annotated[_Omit, _OmitTypeAnnotation]
Headers: TypeAlias = Mapping[str, Union[str, Omit]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tconley1428 can you confirm that requests to the openAI API still work when headers are set like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can confirm that our normal requests work, but I don't I know if they actually have additional headers (I think a user agent is added by default?), and I'm pretty sure they don't actually have an instance of Omit

@rm-openai rm-openai merged commit 017ad69 into openai:main Jun 27, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants