Skip to content

Commit 1ec2b74

Browse files
authored
fix(responses): include text.format when verbosity set for plain-text responses
When model_settings.verbosity was set and no output schema was provided, the code previously built response_format = {"verbosity": ...} which is an invalid `text` payload for the Responses API. The Responses API expects a `text` object to include a `format` field (for plain text use "format": "text"). This patch ensures a valid payload is sent by using: {"format": "text", "verbosity": <value>} Impact: - Prevents 400/BadRequest errors when callers use verbosity with plain text responses (no JSON schema). - Backwards compatible for callers that already use output_schema.
1 parent f91b38f commit 1ec2b74

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/agents/models/openai_responses.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ async def _fetch_response(
299299
if response_format is not omit:
300300
response_format["verbosity"] = model_settings.verbosity # type: ignore [index]
301301
else:
302-
response_format = {"verbosity": model_settings.verbosity}
302+
# When no output_schema is present, text needs an explicit format key.
303+
# Use the plain text format with verbosity to produce a valid `text` payload.
304+
response_format = {"format": "text", "verbosity": model_settings.verbosity}
303305

304306
stream_param: Literal[True] | Omit = True if stream else omit
305307

@@ -501,7 +503,7 @@ def _convert_tool(cls, tool: Tool) -> tuple[ToolParam, ResponseIncludable | None
501503
}
502504
includes = None
503505
else:
504-
raise UserError(f"Unknown tool type: {type(tool)}, tool")
506+
raise UserError(f"Unknown tool type: {type(tool)} for tool {tool!r}")
505507

506508
return converted_tool, includes
507509

0 commit comments

Comments
 (0)