langchain - ✅(Solved) Fix Add support for /responses websocket [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35415Fetched 2026-04-08 00:26:19
View on GitHub
Comments
2
Participants
3
Timeline
11
Reactions
4
Author
Timeline (top)
labeled ×4subscribed ×3commented ×2cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #35578: feat(openai): add websocket streaming support for responses API

Description (problem / solution / changelog)

Description: Adds WebSocket streaming capability to the OpenAI Responses API integration. Enables lower-latency streaming by connecting via WebSocket instead of HTTP when use_websocket=True is specified. Fixes #35415

Verification: All 8 unit tests passing (5 WebSocket-specific, 3 HTTP baseline regression tests). Tested with both default HTTP and WebSocket modes.

Changed files

  • libs/langchain/tests/unit_tests/chat_models/test_base.py (modified, +1/-0)
  • libs/langchain_v1/tests/unit_tests/chat_models/test_chat_models.py (modified, +1/-0)
  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +127/-1)
  • libs/partners/openai/pyproject.toml (modified, +4/-0)
  • libs/partners/openai/tests/unit_tests/chat_models/test_responses_stream.py (modified, +117/-0)
  • libs/partners/openai/uv.lock (modified, +19/-1)
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a feature request, not a bug report or usage question.
  • I added a clear and descriptive title that summarizes the feature request.
  • I used the GitHub search to find a similar feature request and didn't find it.
  • I checked the LangChain documentation and API reference to see if this feature already exists.
  • This is not related to the langchain-community package.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Feature Description

Openai released support for websockets for the /responses API, it's supposed to increase speed, specially in TTFT and tool calling:

Relevant resources: https://github.com/openai/openai-python/releases/tag/v2.22.0 https://developers.openai.com/api/docs/guides/websocket-mode/

Use Case

When using the OpenAI /responses API via the websockets instead of HTTPS

Proposed Solution

Implement support for it.

Alternatives Considered

Not applicable

Additional Context

I'm not sure just updating the dependency to would be enough, or if more work is required "openai>=2.22.0,<3.0.0", https://github.com/langchain-ai/langchain/blob/0b975d4d1ba532d4da16af222824951aeabba9d6/libs/partners/openai/pyproject.toml#L27

extent analysis

Fix Plan

Implement Websocket Support for OpenAI /responses API

Step 1: Update OpenAI Dependency

Update the openai dependency in pyproject.toml to the latest version that supports websockets:

[tool.poetry.dependencies]
openai = "^2.22.0"

Step 2: Modify OpenAI Client to Use Websockets

Update the OpenAI client to use websockets instead of HTTPS. This may involve creating a new OpenAIWebSocketClient class that inherits from the existing OpenAIHttpClient class.

import websockets

class OpenAIWebSocketClient:
    def __init__(self, api_key, endpoint="https://api.openai.com"):
        self.api_key = api_key
        self.endpoint = endpoint

    async def send_request(self, request):
        async with websockets.connect(self.endpoint) as ws:
            await ws.send(request)
            response = await ws.recv()
            return response

Step 3: Update LangChain to Use Websocket Client

Update LangChain to use the new websocket client instead of the default HTTPS client.

from langchain import OpenAIApi

class WebsocketOpenAIApi(OpenAIApi):
    def __init__(self, api_key, endpoint="https://api.openai.com"):
        self.api_key = api_key
        self.endpoint = endpoint
        self.client = OpenAIWebSocketClient(api_key, endpoint)

    async def send_request(self, request):
        return await self.client.send_request(request)

Step 4: Test Websocket Support

Test the websocket support by sending a request to the OpenAI API using the new websocket client.

async def test_websocket_support():
    api_key = "YOUR_API_KEY"
    api = WebsocketOpenAIApi(api_key)
    request = {"model": "text-dav

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING