Skip to content

feat: add WebSocket mode for OpenAI Responses API#4843

Open
dsfaccini wants to merge 2 commits intopydantic:mainfrom
dsfaccini:openai-websockets
Open

feat: add WebSocket mode for OpenAI Responses API#4843
dsfaccini wants to merge 2 commits intopydantic:mainfrom
dsfaccini:openai-websockets

Conversation

@dsfaccini
Copy link
Copy Markdown
Collaborator

Summary

  • Add WebSocket transport mode to existing OpenAIResponsesModel via explicit connect_ws() context manager method
  • Reuse existing event processing pipeline (_get_event_iterator) since WS and HTTP use identical event types
  • TDD-first approach: plan → tests → implementation

This PR starts with the plan. Tests and implementation will follow in subsequent commits.

References

Test plan

  • WS cassette infrastructure (adapted from PR Add realtime speech-to-speech API support #4375's realtime module)
  • Lifecycle tests (connect/disconnect/double-connect error)
  • Request tests (simple text, streaming, sequential, tools, structured output)
  • Guard tests (concurrent serialization, incompatible settings)
  • Edge case tests (post-disconnect fallback, connection error propagation)

Closes #4414

  • AI generated code

Plan for integrating OpenAI's WebSocket support into the existing
OpenAIResponsesModel via an explicit connect_ws() context manager method.

Closes pydantic#4414

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added size: M Medium PR (101-500 weighted lines) feature New feature request, or PR implementing a feature (enhancement) labels Mar 25, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

PLAN.md Outdated
- `tests/websockets/test_openai_responses.py` — TDD test stubs
- `tests/websockets/cassettes/test_openai_responses/{test_id}.yaml` — cassette files (recorded after implementation)

### 1. `connect_ws()` on `OpenAIResponsesModel`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd just call it connect

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I do strongly prefer connect_ws because it's explicit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature request, or PR implementing a feature (enhancement) size: M Medium PR (101-500 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate OpenAI newly WebSocket mode in ResponsesApi

2 participants