Skip to content

Add support for predicted outputs in OpenAIModelSettings #2106

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 1 commit into from
Jul 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pydantic_ai_slim/pydantic_ai/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from openai.types.chat.chat_completion_content_part_image_param import ImageURL
from openai.types.chat.chat_completion_content_part_input_audio_param import InputAudio
from openai.types.chat.chat_completion_content_part_param import File, FileFile
from openai.types.chat.chat_completion_prediction_content_param import ChatCompletionPredictionContentParam
from openai.types.responses import ComputerToolParam, FileSearchToolParam, WebSearchToolParam
from openai.types.responses.response_input_param import FunctionCallOutput, Message
from openai.types.shared import ReasoningEffort
Expand Down Expand Up @@ -126,6 +127,12 @@ class OpenAIModelSettings(ModelSettings, total=False):
For more information, see [OpenAI's service tiers documentation](https://platform.openai.com/docs/api-reference/chat/object#chat/object-service_tier).
"""

openai_prediction: ChatCompletionPredictionContentParam
"""Enables [predictive outputs](https://platform.openai.com/docs/guides/predicted-outputs).

This feature is currently only supported for some OpenAI models.
"""


class OpenAIResponsesModelSettings(OpenAIModelSettings, total=False):
"""Settings used for an OpenAI Responses model request.
Expand Down Expand Up @@ -320,6 +327,7 @@ async def _completions_create(
reasoning_effort=model_settings.get('openai_reasoning_effort', NOT_GIVEN),
user=model_settings.get('openai_user', NOT_GIVEN),
service_tier=model_settings.get('openai_service_tier', NOT_GIVEN),
prediction=model_settings.get('openai_prediction', NOT_GIVEN),
temperature=sampling_settings.get('temperature', NOT_GIVEN),
top_p=sampling_settings.get('top_p', NOT_GIVEN),
presence_penalty=sampling_settings.get('presence_penalty', NOT_GIVEN),
Expand Down