Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a8ab624
Add support for OpenAI verbosity parameter in Responses API
ryx2 Aug 10, 2025
12fdf3f
Address DouweM's review feedback on verbosity implementation
ryx2 Aug 12, 2025
7cc3180
✅ Successfully implement GPT-5 verbosity support with working test
ryx2 Aug 12, 2025
d37fc3e
Merge main into feat/openai-verbosity-support
ryx2 Aug 12, 2025
58edfb5
Add working VCR test for GPT-5 verbosity support
ryx2 Aug 13, 2025
2a99ebf
Fix OpenAI verbosity to work with JSON object/schema formats
ryx2 Aug 13, 2025
909cc16
Merge branch 'main' into feat/openai-verbosity-support
DouweM Aug 13, 2025
b09898b
Update pydantic_ai_slim/pydantic_ai/models/openai.py
ryx2 Aug 13, 2025
099edda
Clean up uv.lock to only include OpenAI 1.99.9 update
ryx2 Aug 13, 2025
da07a88
Merge branch 'main' into feat/openai-verbosity-support
ryx2 Aug 13, 2025
e71c25c
do the uv lock add only after make install
ryx2 Aug 13, 2025
7ef085a
do the uv lock add only after make install and deleting it first
ryx2 Aug 13, 2025
37149a9
updated my uv from 0.5.3 to 0.8.9
ryx2 Aug 13, 2025
5a4e09a
Merge branch 'main' into feat/openai-verbosity-support
DouweM Aug 13, 2025
ed2ce7f
Merge remote-tracking branch 'upstream/main' into feat/openai-verbosi…
ryx2 Aug 13, 2025
9267444
Use upstream pyproject.toml from main
ryx2 Aug 13, 2025
a7af490
Merge branch 'feat/openai-verbosity-support' of https://github.com/ry…
ryx2 Aug 13, 2025
487245c
revert pyproject change + newline lint issue
ryx2 Aug 13, 2025
1ab457c
Delete pydantic_ai_slim/pyproject.toml.main
ryx2 Aug 13, 2025
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
12 changes: 12 additions & 0 deletions pydantic_ai_slim/pydantic_ai/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ class OpenAIResponsesModelSettings(OpenAIModelSettings, total=False):
middle of the conversation.
"""

openai_text_verbosity: Literal['low', 'medium', 'high']
"""Constrains the verbosity of the model's text response.

Lower values will result in more concise responses, while higher values will
result in more verbose responses. Currently supported values are `low`,
`medium`, and `high`.
"""


@dataclass(init=False)
class OpenAIModel(Model):
Expand Down Expand Up @@ -819,6 +827,10 @@ async def _responses_create(
openai_messages.insert(0, responses.EasyInputMessageParam(role='system', content=instructions))
instructions = NOT_GIVEN

if verbosity := model_settings.get('openai_text_verbosity'):
text = text or {}
text['verbosity'] = verbosity

sampling_settings = (
model_settings
if OpenAIModelProfile.from_profile(self.profile).openai_supports_sampling_settings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
interactions:
- request:
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-type:
- application/json
host:
- api.openai.com
method: POST
parsed_body:
input:
- content: What is 2+2?
role: user
instructions: ''
model: gpt-5
text:
format:
type: text
verbosity: low
uri: https://api.openai.com/v1/responses
response:
headers:
content-type:
- application/json
parsed_body:
created_at: 1743075630
error: null
id: resp_test_verbosity_simple
incomplete_details: null
instructions: ''
max_output_tokens: null
metadata: {}
model: gpt-5
object: response
output:
- content:
- annotations: []
text: "4"
type: output_text
id: msg_test_verbosity_simple
role: assistant
status: completed
type: message
parallel_tool_calls: true
previous_response_id: null
reasoning: null
status: complete
status_details: null
tool_calls: null
total_tokens: 15
usage:
input_tokens: 10
input_tokens_details:
cached_tokens: 0
output_tokens: 1
output_tokens_details:
reasoning_tokens: 0
total_tokens: 11
status:
code: 200
message: OK
version: 1
14 changes: 14 additions & 0 deletions tests/models/test_openai_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,3 +1134,17 @@ async def get_user_country() -> str:
),
]
)


@pytest.mark.vcr()
async def test_openai_responses_verbosity(allow_model_requests: None, openai_api_key: str):
"""Test that verbosity setting is properly passed to the OpenAI API"""
# Following GPT-5 + verbosity documentation pattern
provider = OpenAIProvider(
api_key=openai_api_key,
base_url='https://api.openai.com/v1', # Explicitly set base URL
)
model = OpenAIResponsesModel('gpt-5', provider=provider)
agent = Agent(model=model, model_settings=OpenAIResponsesModelSettings(openai_text_verbosity='low'))
result = await agent.run('What is 2+2?')
assert result.output == snapshot('4')
14 changes: 7 additions & 7 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.