Skip to content

fix(realtime): expose max_output_tokens on RealtimeSessionModelSettings#3223

Merged
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/realtime-max-output-tokens
May 8, 2026
Merged

fix(realtime): expose max_output_tokens on RealtimeSessionModelSettings#3223
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/realtime-max-output-tokens

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Summary

OpenAIRealtimeWebSocketModel._get_session_config already reads max_output_tokens from the settings dict and forwards it to RealtimeSessionCreateRequest.max_output_tokens (see src/agents/realtime/openai_realtime.py:1474), but the field was never declared on RealtimeSessionModelSettings. Type-checked callers had to cast through Any (or use # type: ignore) just to limit per-response output tokens, even though the OpenAI Realtime API supports the field natively.

This patch adds max_output_tokens: NotRequired[int | Literal["inf"]] to the TypedDict so callers can pass either an integer cap or the "inf" sentinel directly. No runtime change is required: the existing forwarding logic already handles both shapes.

Test plan

  • New test_session_config_passes_max_output_tokens covers integer caps, the "inf" sentinel, and the unset (server-default) case via _get_session_config.
  • pytest tests/realtime/ -> 233 passed.
  • ruff check / ruff format --check clean on touched files.

The realtime model already forwards `max_output_tokens` from the settings
dict to the underlying `RealtimeSessionCreateRequest`, but the field was
missing from the public TypedDict. Type-checked callers had to cast to
`Any` to set a per-response token cap. Add the field so it can be passed
through cleanly with both an integer cap and the `"inf"` sentinel.
@github-actions github-actions Bot added bug Something isn't working feature:realtime labels May 8, 2026
@seratch
Copy link
Copy Markdown
Member

seratch commented May 8, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch merged commit c7bcdd4 into openai:main May 8, 2026
10 checks passed
@seratch seratch added this to the 0.17.x milestone May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:realtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants