Skip to content

Commit e04d87c

Browse files
Add extra request parameters extra_query and extra_body (#500)
Added the possibility to pass `extra_query` and `extra_body` parameters when sending a request. In this implementation I added the attributes to `ModelSettings` as suggested by @rm-openai in #487 . I'll be happy to add some tests if you have any suggestions.
1 parent d0693a1 commit e04d87c

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/agents/model_settings.py

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dataclasses import dataclass, fields, replace
44
from typing import Literal
55

6+
from openai._types import Body, Query
67
from openai.types.shared import Reasoning
78

89

@@ -58,6 +59,14 @@ class ModelSettings:
5859
"""Whether to include usage chunk.
5960
Defaults to True if not provided."""
6061

62+
extra_query: Query | None = None
63+
"""Additional query fields to provide with the request.
64+
Defaults to None if not provided."""
65+
66+
extra_body: Body | None = None
67+
"""Additional body fields to provide with the request.
68+
Defaults to None if not provided."""
69+
6170
def resolve(self, override: ModelSettings | None) -> ModelSettings:
6271
"""Produce a new ModelSettings by overlaying any non-None values from the
6372
override on top of this instance."""

src/agents/models/openai_chatcompletions.py

+2
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ async def _fetch_response(
540540
store=self._non_null_or_not_given(store),
541541
reasoning_effort=self._non_null_or_not_given(reasoning_effort),
542542
extra_headers=_HEADERS,
543+
extra_query=model_settings.extra_query,
544+
extra_body=model_settings.extra_body,
543545
metadata=self._non_null_or_not_given(model_settings.metadata),
544546
)
545547

src/agents/models/openai_responses.py

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ async def _fetch_response(
245245
parallel_tool_calls=parallel_tool_calls,
246246
stream=stream,
247247
extra_headers=_HEADERS,
248+
extra_query=model_settings.extra_query,
249+
extra_body=model_settings.extra_body,
248250
text=response_format,
249251
store=self._non_null_or_not_given(model_settings.store),
250252
reasoning=self._non_null_or_not_given(model_settings.reasoning),

0 commit comments

Comments
 (0)