aisdk/transport

Ready-made Live transport implementations for the PHP AI SDK.

Maintainers

Package info

github.com/phpaisdk/transport

pkg:composer/aisdk/transport

Transparency log

Fund package maintenance!

Open Collective

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.8.0 2026-07-15 12:11 UTC

This package is auto-updated.

Last update: 2026-07-17 02:24:13 UTC


README

GitHub Workflow Status Total Downloads Latest Version License Why PHP in 2026

Ready-made network transports for the provider-neutral Live API in aisdk/core. Provider packages continue to own authentication, endpoint construction, and event codecs; this package only moves text and binary frames over the network.

Installation

composer require aisdk/transport

Automatic selection

use AiSdk\Live;
use AiSdk\OpenAI;
use AiSdk\Transport;

$session = Live::voice()
    ->model(OpenAI::model('gpt-realtime-2.1'))
    ->voice('marin')
    ->connect(Transport::auto());

Transport::auto() selects the implementation from the endpoint prepared by the provider adapter:

  • WebSocket endpoints use amphp/websocket-client.
  • Bidirectional HTTP/2 endpoints use amphp/http-client.

Use an explicit transport when you want to restrict the connection type:

$webSocket = Transport::webSocket(
    maximumMessageBytes: 16_777_216,
    connectTimeout: 10,
    tlsHandshakeTimeout: 10,
);

$http2 = Transport::http2(
    requestBufferBytes: 65_536,
    inactivityTimeout: 0,
    transferTimeout: 0,
    maximumRequestChunkBytes: 16_777_216,
    maximumResponseChunkBytes: 16_777_216,
);

Both explicit factories accept an Amp connector/client for applications that need custom proxy, DNS, socket, or TLS behavior. Their public constructors are also available when composing AutoTransport manually.

Concurrent audio and events

LiveSession::events() waits for incoming data, so a full-duplex voice agent should send audio and consume events in separate Amp tasks. Core remains free of Amp types; concurrency is an application concern:

use AiSdk\Live\AudioDelta;
use AiSdk\Live\ResponseCompleted;
use function Amp\async;
use function Amp\delay;

$sender = async(function () use ($session, $pcmBytes): void {
    foreach (str_split($pcmBytes, 3_200) as $chunk) {
        $session->sendAudio($chunk);
        delay(0.02);
    }

    $session->commitAudio();
});

$receiver = async(function () use ($session, $speaker): void {
    foreach ($session->events() as $event) {
        if ($event instanceof AudioDelta) {
            $speaker->write($event->bytes);
        }

        if ($event instanceof ResponseCompleted) {
            $session->close();

            return;
        }
    }
});

$sender->await();
$receiver->await();

For an open-ended microphone session, keep both tasks alive until the application's own stop signal, then call $session->close() and await them.

Bidirectional HTTP/2

The HTTP/2 implementation writes the streaming request body and reads the streaming response independently. It supports request-body half-close, applies backpressure through an Amp pipe, disables whole-transfer and inactivity timeouts by default for long-lived sessions, and refuses HTTP/1.1 fallback.

Transport configuration such as timeouts, TLS, buffers, and message limits belongs here. Provider JSON, AWS signing, EventStream framing, WebRTC, and SIP logic deliberately do not.

Applications can still connect with any implementation of core's TransportInterface; installing this package is a convenience, not a requirement of AiSdk\Live.

Testing

composer test

Documentation

Community