Repository: livekit/agents
File: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/responses/llm.py (Python)

Code before:
                input=cast(Union[str, ResponseInputParam, openai.NotGiven], chat_ctx),
                stream=True,
                timeout=httpx.Timeout(self._conn_options.timeout),
                **self._extra_kwargs,
            )

            async with stream:
                async for event in stream:
                    retryable = False
                    chunk = None

                    if isinstance(event, ResponseErrorEvent):
                        self._handle_error(event)

                    if isinstance(event, ResponseCreatedEvent):
                        self._handle_response_created(event)

                    if isinstance(event, ResponseOutputItemDoneEvent):
                        chunk = self._handle_output_items_done(event)

                    if isinstance(event, ResponseTextDeltaEvent):
                        chunk = self._handle_response_output_text_delta(event)

                    if isinstance(event, ResponseCompletedEvent):
                        chunk = self._handle_response_completed(event)

                    if chunk is not None:
                        self._event_ch.send_nowait(chunk)

        except openai.APITimeoutError:
            raise APITimeoutError(retryable=retryable)  # noqa: B904
        except openai.APIStatusError as e:
            raise APIStatusError(  # noqa: B904
                e.message,
                status_code=e.status_code,
                request_id=e.request_id,
                body=e.body,
                retryable=retryable,
            )
        except Exception as e:
            raise APIConnectionError(retryable=retryable) from e

    def _handle_error(self, event: ResponseErrorEvent) -> None:
        raise APIStatusError(event.message, status_code=-1, retryable=False)

    def _handle_response_created(self, event: ResponseCreatedEvent) -> None:
        self._response_id = event.response.id

    def _handle_response_completed(self, event: ResponseCompletedEvent) -> llm.ChatChunk | None:
        chunk = None
        if usage := event.response.usage:

Review comment (performance):
Should we set verbosity to 'low' or None and disable thinking by default? This mainly applies when working with the GPT-5 family models. Otherwise, the time to first text token tends to be quite slow, which can make it feel like the LLM request is hanging.

Code after:
                timeout=httpx.Timeout(self._conn_options.timeout),
                **self._extra_kwargs,
            )

            async with stream:
                async for event in stream:
                    retryable = False
                    chunk = None

                    if isinstance(event, ResponseErrorEvent):
                        self._handle_error(event)

                    if isinstance(event, ResponseCreatedEvent):
                        self._handle_response_created(event)

                    if isinstance(event, ResponseOutputItemDoneEvent):
                        chunk = self._handle_output_items_done(event)

                    if isinstance(event, ResponseTextDeltaEvent):
                        chunk = self._handle_response_output_text_delta(event)

                    if isinstance(event, ResponseCompletedEvent):
                        chunk = self._handle_response_completed(event)

                    if chunk is not None:
                        self._event_ch.send_nowait(chunk)

        except openai.APITimeoutError:
            raise APITimeoutError(retryable=retryable)  # noqa: B904
        except openai.APIStatusError as e:
            raise APIStatusError(  # noqa: B904
                e.message,
                status_code=e.status_code,
                request_id=e.request_id,
                body=e.body,
                retryable=retryable,
            )
        except Exception as e:
            raise APIConnectionError(retryable=retryable) from e

    def _handle_error(self, event: ResponseErrorEvent) -> None:
        raise APIStatusError(event.message, status_code=-1, retryable=False)

    def _handle_response_created(self, event: ResponseCreatedEvent) -> None:
        self._response_id = event.response.id

    def _handle_response_completed(self, event: ResponseCompletedEvent) -> llm.ChatChunk | None:
        chunk = None
        if usage := event.response.usage:
            chunk = llm.ChatChunk(
                id=self._response_id,