Skip to main content

Overview

Pipecat provides two variants of the OpenAI Responses API LLM service:
  • OpenAIResponsesLLMService (WebSocket-based, recommended): Maintains a persistent WebSocket connection for lower-latency inference and automatically uses previous_response_id to send only incremental context when possible.
  • OpenAIResponsesHttpLLMService (HTTP-based): Uses server-sent events (SSE) via HTTP streaming. Each request opens a new connection. Use this when WebSocket is not available or preferred.
Both variants support streaming text responses, function calling, usage metrics, and out-of-band inference, and work with the universal LLMContext and LLMContextAggregatorPair.
The Responses API is a newer OpenAI API designed for conversational AI applications. It differs from the Chat Completions API in its request/response structure and streaming format. See OpenAI Responses API documentation for more details.

WebSocket vs HTTP

Use WebSocket (OpenAIResponsesLLMService) when:
  • You need the lowest possible latency for real-time conversations
  • Your workflow involves frequent tool/function calls
  • You want automatic incremental context optimization without server-side storage
Use HTTP (OpenAIResponsesHttpLLMService) when:
  • WebSocket connections are blocked by your infrastructure
  • You prefer stateless request/response patterns
  • You don’t need the incremental context optimization
The WebSocket variant’s previous_response_id optimization works with store=False (the default) using a connection-local in-memory cache—no conversations are stored on OpenAI’s servers. The HTTP variant does not offer this optimization by default, as it would require store=True (30-day OpenAI-side conversation storage).

OpenAI Responses API Reference

Pipecat’s API methods for OpenAI Responses integration

Example Implementation

Interruptible conversation example

OpenAI Documentation

Official OpenAI Responses API documentation

OpenAI Platform

Access models and manage API keys

Installation

To use OpenAI services, install the required dependencies:

Prerequisites

OpenAI Account Setup

Before using OpenAI Responses LLM services, you need:
  1. OpenAI Account: Sign up at OpenAI Platform
  2. API Key: Generate an API key from your account dashboard
  3. Model Selection: Choose from available models (GPT-4.1, GPT-4o, GPT-4o-mini, etc.)
  4. Usage Limits: Set up billing and usage limits as needed

Required Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key for authentication

Configuration

Common Parameters

These parameters are available for both OpenAIResponsesLLMService and OpenAIResponsesHttpLLMService:
str
default:"None"
OpenAI API key. If None, uses the OPENAI_API_KEY environment variable.
str
default:"None"
Custom base URL for the OpenAI API. Override for proxied or self-hosted deployments. The WebSocket variant uses it only for run_inference(); set ws_url for its streaming connection.
str
default:"None"
OpenAI organization ID. The WebSocket variant sends it only with run_inference() requests.
str
default:"None"
OpenAI project ID. The WebSocket variant sends it only with run_inference() requests.
Mapping[str, str]
default:"None"
Additional HTTP headers to include in every request. The WebSocket variant sends them only with run_inference() requests.
str
default:"None"
Service tier to use: "auto", "default", "flex", "scale", "fast", "priority" or "ultrafast". "fast" is OpenAI’s low-latency tier, the name that replaced "priority"; both values are accepted. "ultrafast" is the access-controlled Ultrafast Processing tier, which shortens the time between output tokens on the models that offer it.
OpenAIResponsesLLMSettings
default:"None"
Runtime-configurable model settings. See Settings below.
float | None
default:"5.0"
How long a request may go without producing output before it is abandoned and re-issued, when retry_on_timeout is set.
bool | None
default:"False"
Whether to re-issue the request once if it produces no output within retry_timeout_secs. The retry has no timeout.

WebSocket-Specific Parameters

The following parameter is only available for OpenAIResponsesLLMService (WebSocket variant):
str
default:"wss://api.openai.com/v1/responses"
WebSocket endpoint URL. Override for custom deployments or proxies.

Settings

Runtime-configurable settings passed via the settings constructor argument using OpenAIResponsesLLMService.Settings(...). These can be updated mid-conversation with LLMUpdateSettingsFrame. See Service Settings for details.
NOT_GIVEN and None values are omitted from the API request entirely, letting the OpenAI API use its own defaults.

Reasoning Configuration

The reasoning parameter accepts an OpenAIResponsesReasoningConfig object that controls reasoning behavior for reasoning-capable models (GPT-5.x series and o-series models like o1, o3). The default model gpt-4.1 does not support reasoning. When reasoning is not set, Pipecat sends each listed model the lowest effort OpenAI documents for it ("none" on most GPT-5.1 and later models, "minimal" on the original GPT-5 models, "low" on the o-series, "medium" on the GPT-5.2 and later -pro models, "high" on gpt-5-pro) and logs what it sent. A reasoning model it doesn’t list runs at OpenAI’s default and logs a warning. Reasoning models use internal reasoning tokens before producing a response. This configuration controls how much reasoning they do and whether a human-readable summary is returned. Parameters: Effort levels:
  • "none": Disables reasoning for latency-sensitive use
  • "minimal", "low", "medium", "high", "xhigh": Progressive levels of reasoning effort
  • "max": Applies the model’s deepest reasoning
At lower effort levels, the model reasons only when a turn calls for it, so simple prompts may produce no summary. Example:
The encrypted reasoning itself is preserved across turns regardless of the summary setting. The summary is only for observability and debugging.

Usage

Basic Setup

WebSocket variant (recommended):
HTTP variant:

With Custom Settings

Both OpenAIResponsesLLMService.Settings and OpenAIResponsesHttpLLMService.Settings use the same OpenAIResponsesLLMSettings class, so settings are identical between variants.

Updating Settings at Runtime

Model settings can be changed mid-conversation using LLMUpdateSettingsFrame:

Out-of-Band Inference

Run a one-shot inference without pushing frames through the pipeline:

Structured Output with Response Schema

Pass a response_schema to enforce a JSON structure in the reply:
The Responses API enforces the schema on models that support it (gpt-4o-mini and later). Older models (gpt-4-turbo, gpt-3.5, o1-preview, o1-mini) ignore it with a warning.

Notes

  • Persistent WebSocket connection: OpenAIResponsesLLMService keeps a WebSocket connection open and reconnects automatically when it drops, including at OpenAI’s 60-minute connection limit. For HTTP streaming, use OpenAIResponsesHttpLLMService.
  • Incremental context optimization: The WebSocket variant uses previous_response_id to send only incremental context when the conversation prefix hasn’t changed, reducing latency and costs. This works with store=False (no server-side storage) via a connection-local cache.
  • Responses API vs Chat Completions API: The Responses API has a different request/response structure compared to the Chat Completions API. Use OpenAILLMService for the Chat Completions API and OpenAIResponsesLLMService or OpenAIResponsesHttpLLMService for the Responses API.
  • Universal LLM Context: Both services work with the universal LLMContext and LLMContextAggregatorPair, making it easy to switch between different LLM providers.
  • Function calling: Supports OpenAI’s tool/function calling format. Register function handlers with llm.register_function() to handle tool calls automatically.
  • Usage metrics: Automatically tracks token usage, including cached tokens and reasoning tokens.
  • Service tiers: Supports OpenAI’s service tier system for prioritizing requests.
  • Empty responses: If a response completes with no text and no function call (for example, only reasoning items or a refusal), the service logs a warning listing the response’s output items and pushes a non-fatal ErrorFrame. Nothing reaches the TTS, so handle it in on_pipeline_error, for example by running the LLM again.

Event Handlers

OpenAIResponsesLLMService and OpenAIResponsesHttpLLMService support the following event handlers, inherited from LLMService: