Skip to content

Realtime: add user agent header #1185

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 21, 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
7 changes: 6 additions & 1 deletion src/agents/realtime/openai_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

from ..exceptions import UserError
from ..logger import logger
from ..version import __version__
from .config import (
RealtimeModelTracingConfig,
RealtimeSessionModelSettings,
Expand Down Expand Up @@ -97,6 +98,8 @@
RealtimeModelSendUserInput,
)

_USER_AGENT = f"Agents/Python {__version__}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this constant in several source files, so it may be about time to have a single unified one. That said, you can go ahead for now, and we can refactor later on.


DEFAULT_MODEL_SETTINGS: RealtimeSessionModelSettings = {
"voice": "ash",
"modalities": ["text", "audio"],
Expand Down Expand Up @@ -160,7 +163,9 @@ async def connect(self, options: RealtimeModelConfig) -> None:
"Authorization": f"Bearer {api_key}",
"OpenAI-Beta": "realtime=v1",
}
self._websocket = await websockets.connect(url, additional_headers=headers)
self._websocket = await websockets.connect(
url, user_agent_header=_USER_AGENT, additional_headers=headers
)
self._websocket_task = asyncio.create_task(self._listen_for_messages())
await self._update_session_config(model_settings)

Expand Down