Skip to content

[Platform][OpenAI] Support Realtime Sessions (WebRTC / Ephemeral client credentials) #2427

Description

@saifulferoz

Description

Currently, symfony/ai provides abstractions for request-response completion, token streaming (Capability::OUTPUT_STREAMING), speech-to-text (Whisper), and text-to-speech (Capability::OUTPUT_AUDIO).

However, providers such as OpenAI and Azure OpenAI now offer Realtime APIs for low-latency, bidirectional speech-to-speech voice sessions over WebRTC / WebSockets.

Proposed Solution

Instead of proxying heavy WebRTC audio streams through PHP, Symfony acts as the secure session broker & ephemeral credential minter:

  1. Add Capability::REALTIME_SESSION to Symfony\AI\Platform\Capability.
  2. Add RealtimeSessionResult ($result->getClientSecret(), $result->getExpiresAt(), $result->getId(), $result->getModel()).
  3. Add Realtime model class in Symfony\AI\Platform\Bridge\OpenAi.
  4. Implement ModelClient for POST /v1/realtime/sessions and ResultConverter converting responses to RealtimeSessionResult.
  5. Register realtime models (gpt-4o-realtime-preview, etc.) in the OpenAI ModelCatalog and Factory.

Example Usage

use Symfony\AI\Platform\Bridge\OpenAi\Realtime;
use Symfony\AI\Platform\Bridge\OpenAi\Factory;

$platform = Factory::createPlatform($_ENV['OPENAI_API_KEY']);

$result = $platform->invoke(
    new Realtime('gpt-4o-realtime-preview'),
    'You are a customer support agent.',
    [
        'voice' => 'alloy',
        'modalities' => ['text', 'audio'],
        'turn_detection' => ['type' => 'server_vad'],
    ]
);

$session = $result->getResult(); // RealtimeSessionResult

return new JsonResponse([
    'client_secret' => $session->getClientSecret(),
    'expires_at' => $session->getExpiresAt(),
    'session_id' => $session->getId(),
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    PlatformIssues & PRs about the AI Platform component

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions