PHPackages                             saifulferoz/laravel-ai-realtime - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. saifulferoz/laravel-ai-realtime

ActiveLibrary

saifulferoz/laravel-ai-realtime
===============================

Realtime speech-to-speech voice sessions and WebRTC ephemeral credentials for Laravel AI

v0.1.0(today)00MITPHPPHP ^8.2CI failing

Since Aug 24Pushed todayCompare

[ Source](https://github.com/saifulferoz/laravel-ai-realtime)[ Packagist](https://packagist.org/packages/saifulferoz/laravel-ai-realtime)[ RSS](/packages/saifulferoz-laravel-ai-realtime/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (7)Versions (2)Used By (0)

Laravel AI Realtime
===================

[](#laravel-ai-realtime)

 [![Latest Version on Packagist](https://camo.githubusercontent.com/f48a95fac0203cb57e2d0f44ed9cb39cab3716fbae175daed9aec2417d17833f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616966756c6665726f7a2f6c61726176656c2d61692d7265616c74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/saifulferoz/laravel-ai-realtime) [![GitHub Tests Action Status](https://camo.githubusercontent.com/181791508ece8e66fe89f0caaae91505001fc6607ef1e24dfcd7e96b57779f24/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616966756c6665726f7a2f6c61726176656c2d61692d7265616c74696d652f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/saifulferoz/laravel-ai-realtime/actions) [![Total Downloads](https://camo.githubusercontent.com/1898b673190af0f089bc36727ecc10c333710fd2c129f18948c5d4bb630e4ede/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616966756c6665726f7a2f6c61726176656c2d61692d7265616c74696d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/saifulferoz/laravel-ai-realtime) [![License](https://camo.githubusercontent.com/daf852a2ee4273bb2add7f06d1159e2617568a416ad757ca211725231fa1d9aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f73616966756c6665726f7a2f6c61726176656c2d61692d7265616c74696d653f7374796c653d666c61742d737175617265)](LICENSE.md)

Realtime speech-to-speech voice sessions and WebRTC ephemeral credential generation for **[Laravel AI](https://github.com/laravel/ai)** (`laravel/ai`).

Supports **OpenAI** (`POST /v1/realtime/client_secrets`) and **Azure OpenAI** (`POST /openai/v1/realtime/client_secrets`) GA APIs.

---

🚀 Architecture
--------------

[](#-architecture)

```
[ Frontend / Mobile App ]
         │
         │ 1. Request session credentials
         ▼
[ Laravel App (Control Plane) ] ── (laravel-ai-realtime) ──► [ OpenAI / Azure ]
         │                                                      (Mints Ephemeral Token)
         │ 2. Returns short-lived client_secret (token)
         ▼
[ Frontend / Mobile App ]
         │
         │ 3. Direct bidirectional audio stream (WebRTC / Data Plane)
         ▼
[ OpenAI / Azure Realtime Server ]  (< 300ms latency, zero PHP server load)

```

1. **Security**: Your master API key remains private on your backend server. Laravel mints a short-lived ephemeral client token (`client_secret`).
2. **Performance**: Voice media streaming connects directly from client (browser/native app) to OpenAI/Azure via WebRTC, bypassing PHP processes and avoiding proxy bottlenecks.

---

📦 Installation
--------------

[](#-installation)

```
composer require saifulferoz/laravel-ai-realtime
```

---

🛠️ Usage
--------

[](#️-usage)

### 1. Using the `realtime(...)` Helper

[](#1-using-the-realtime-helper)

```
use function Laravel\Ai\agent;
use function LaravelAi\Realtime\realtime;

$agent = agent(
    instructions: 'You are a warm customer service agent for ACME.',
    tools: [new LookupOrderTool],
);

// Generate ephemeral session credentials for WebRTC client
$session = realtime($agent, voice: 'alloy');

return response()->json([
    'client_secret' => $session->clientSecret(),
    'expires_at' => $session->expiresAt(),
    'session_id' => $session->id(),
]);
```

### 2. Using the `Realtime` Facade

[](#2-using-the-realtime-facade)

```
use LaravelAi\Realtime\Facades\Realtime;

$session = Realtime::createSession(
    provider: 'openai',
    model: 'gpt-realtime',
    instructions: 'You are an airline customer support voice agent.',
    voice: 'marin',
    modalities: ['text', 'audio'],
    options: [
        'turn_detection' => ['type' => 'server_vad'],
        'output_audio_format' => 'pcm16',
    ]
);

return response()->json([
    'token' => $session->clientSecret(),
    'expires_at' => $session->expiresAt(),
]);
```

### 3. Using the `HasRealtimeSession` Trait in Class Agents

[](#3-using-the-hasrealtimesession-trait-in-class-agents)

```
namespace App\Ai\Agents;

use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;
use LaravelAi\Realtime\Concerns\HasRealtimeSession;

class SupportAgent implements Agent
{
    use Promptable;
    use HasRealtimeSession;

    public function instructions(): string
    {
        return 'You are an intelligent support assistant.';
    }
}

// In Controller:
$agent = new SupportAgent();
$session = $agent->realtime(voice: 'alloy');
```

---

🧪 Testing and Fakes
-------------------

[](#-testing-and-fakes)

Testing real-time voice credential endpoints is simple with `Realtime::fake()`:

```
use LaravelAi\Realtime\Facades\Realtime;

test('voice session controller returns ephemeral credentials', function () {
    Realtime::fake([
        'id' => 'sess_fake_123',
        'value' => 'ek_fake_secret_token',
        'expires_at' => 1790000000,
    ]);

    $response = $this->postJson('/api/voice/session');

    $response->assertOk()
        ->assertJson([
            'client_secret' => 'ek_fake_secret_token',
        ]);

    Realtime::assertCreated(function ($prompt, $provider) {
        return $provider === 'openai';
    });
});
```

---

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [LICENSE.md](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/42f7ccbb50ac26336f56240519756fffae416abcdc6ff44540947bd2cc941487?d=identicon)[saifulferoz](/maintainers/saifulferoz)

---

Top Contributors

[![saifulferoz](https://avatars.githubusercontent.com/u/15348453?v=4)](https://github.com/saifulferoz "saifulferoz (1 commits)")

---

Tags

laravelaiopenaiazurerealtimeWebRTCvoicespeech-to-speech

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/saifulferoz-laravel-ai-realtime/health.svg)

```
[![Health](https://phpackages.com/badges/saifulferoz-laravel-ai-realtime/health.svg)](https://phpackages.com/packages/saifulferoz-laravel-ai-realtime)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

80427.1M248](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818355.4k3](/packages/defstudio-telegraph)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M337](/packages/laravel-ai)[illuminate/auth

The Illuminate Auth package.

9328.5M1.4k](/packages/illuminate-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
