Skip to content

Add extra request parameters extra_query and extra_body #500

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
Apr 14, 2025
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/agents/model_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass, fields, replace
from typing import Literal

from openai._types import Body, Query
from openai.types.shared import Reasoning


Expand Down Expand Up @@ -58,6 +59,14 @@ class ModelSettings:
"""Whether to include usage chunk.
Defaults to True if not provided."""

extra_query: Query | None = None
"""Additional query fields to provide with the request.
Defaults to None if not provided."""

extra_body: Body | None = None
"""Additional body fields to provide with the request.
Defaults to None if not provided."""

def resolve(self, override: ModelSettings | None) -> ModelSettings:
"""Produce a new ModelSettings by overlaying any non-None values from the
override on top of this instance."""
Expand Down
2 changes: 2 additions & 0 deletions src/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ async def _fetch_response(
store=self._non_null_or_not_given(store),
reasoning_effort=self._non_null_or_not_given(reasoning_effort),
extra_headers=_HEADERS,
extra_query=model_settings.extra_query,
extra_body=model_settings.extra_body,
metadata=self._non_null_or_not_given(model_settings.metadata),
)

Expand Down
2 changes: 2 additions & 0 deletions src/agents/models/openai_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ async def _fetch_response(
parallel_tool_calls=parallel_tool_calls,
stream=stream,
extra_headers=_HEADERS,
extra_query=model_settings.extra_query,
extra_body=model_settings.extra_body,
text=response_format,
store=self._non_null_or_not_given(model_settings.store),
reasoning=self._non_null_or_not_given(model_settings.reasoning),
Expand Down