PHPackages                             aisdk/azure - 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. aisdk/azure

ActiveLibrary

aisdk/azure
===========

Official Azure OpenAI provider for the PHP AI SDK.

v0.8.0(1mo ago)010↓25%MITPHPPHP ^8.3CI passing

Since Jul 11Pushed 1mo agoCompare

[ Source](https://github.com/phpaisdk/azure)[ Packagist](https://packagist.org/packages/aisdk/azure)[ Docs](https://github.com/phpaisdk/azure)[ RSS](/packages/aisdk-azure/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (8)Versions (7)Used By (0)

aisdk/azure
===========

[](#aisdkazure)

[![GitHub Workflow Status](https://camo.githubusercontent.com/51cbbb872e0cfdde325c87c45ec8415d6343aa85e818817c72bc1a268cecde6a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706870616973646b2f617a7572652f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/phpaisdk/azure/actions)[![Total Downloads](https://camo.githubusercontent.com/139a43945e968eb9a009bffb70cc73d35a405de6e41e151b7fc00628b5f6aa42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616973646b2f617a757265)](https://packagist.org/packages/aisdk/azure)[![Latest Version](https://camo.githubusercontent.com/f56be9ff87ca7a5e8713de868e7c9b15f90da4147a931a1ced773d471ddcb41c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616973646b2f617a757265)](https://packagist.org/packages/aisdk/azure)[![License](https://camo.githubusercontent.com/75f1685ffbf5d097f972cf01a25ad9360317485d823c483b6f94a6f7c5b4ea2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616973646b2f617a757265)](https://packagist.org/packages/aisdk/azure)[![Why PHP in 2026](https://camo.githubusercontent.com/d2b9305e630caf7daae4ca023de39ece0b885c37461629d42961533f00868b76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5768795f5048502d696e5f323032362d3741383645383f7374796c653d666c61742d737175617265266c6162656c436f6c6f723d313831383162)](https://whyphp.dev)

---

Official Azure OpenAI provider for the framework-agnostic PHP AI SDK, with text, streaming, image, speech, transcription, and embedding generation.

Installation
------------

[](#installation)

```
composer require aisdk/azure
```

Basic Usage
-----------

[](#basic-usage)

```
use AiSdk\Azure;
use AiSdk\Generate;

$result = Generate::text()
    ->model(Azure::model('gpt-4o'))
    ->instructions('Write short, clear answers.')
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text();
```

The identifier passed to `Azure::model()` is the Azure deployment name. It does not have to match the underlying model name.

Deployment names pass through unchanged and do not need to be registered. This package does not ship a model inventory; the SDK performs internal adapter validation before Azure validates support for the selected deployment.

Image and speech generation
---------------------------

[](#image-and-speech-generation)

```
$image = Generate::image('A product photo on a white background')
    ->model(Azure::model('my-image-deployment'))
    ->size('1024x1024')
    ->run();

$speech = Generate::speech('Welcome to our application.')
    ->model(Azure::model('my-speech-deployment'))
    ->voice('alloy')
    ->run();
```

Transcription
-------------

[](#transcription)

```
use AiSdk\Azure;
use AiSdk\Content;
use AiSdk\Generate;

$result = Generate::transcription(Content::audio(__DIR__.'/meeting.mp3'))
    ->model(Azure::model('my-transcription-deployment'))
    ->run();

echo $result->output->text;
```

The default Azure v1 surface uses `/openai/v1/audio/transcriptions`. With `useDeploymentBasedUrls`, the adapter uses the classic deployment URL and configured API version.

Live voice, transcription, and translation
------------------------------------------

[](#live-voice-transcription-and-translation)

Install `aisdk/transport` for ready-made WebSocket connections:

```
composer require aisdk/transport
```

```
use AiSdk\Azure;
use AiSdk\Live;
use AiSdk\Live\AudioDelta;
use AiSdk\Live\TranscriptDelta;
use AiSdk\Transport;

$session = Live::voice()
    ->model(Azure::model('gpt-realtime'))
    ->instructions('You are a concise customer-support agent.')
    ->voice('marin')
    ->connect(Transport::auto());

$session->sendAudio($pcmBytes);

foreach ($session->events() as $event) {
    if ($event instanceof AudioDelta) {
        playAudio($event->bytes);
    }

    if ($event instanceof TranscriptDelta) {
        echo $event->delta;
    }
}
```

Send microphone audio and consume events concurrently in a long-running application. Registered core tools with handlers are executed automatically; unknown calls are emitted as `ToolCallEvent` values and can be answered with `$session->sendToolResult($callId, $result)`.

Azure's dedicated realtime deployments map to separate builders and endpoints:

```
$transcriber = Live::transcribe()
    ->model(Azure::model('gpt-realtime-whisper'))
    ->language('en')
    ->audioFormat('pcm16')
    ->connect(Transport::auto());

$translator = Live::translate()
    ->model(Azure::model('gpt-realtime-translate'))
    ->from('en')
    ->to('es')
    ->connect(Transport::auto());
```

The translation protocol streams audio continuously, so it intentionally does not expose OpenAI-style commit, clear, response-create, or cancel operations.

### Core-only transport

[](#core-only-transport)

`aisdk/transport` is optional. The same operations accept an application implementation of `AiSdk\Live\Contracts\TransportInterface`:

```
$session = Live::voice()
    ->model(Azure::model('gpt-realtime'))
    ->connect($appWebSocketTransport);
```

The [core custom-transport guide](https://github.com/phpaisdk/core#core-without-aisdktransport)contains the complete WebSocket implementation. Azure authentication, endpoint selection, session JSON, and event normalization remain in this package.

### Browser WebRTC

[](#browser-webrtc)

The backend can issue a short-lived credential or proxy the complete SDP exchange. API keys never need to reach the browser:

```
$secret = Live::voice()
    ->model(Azure::model('gpt-realtime'))
    ->voice('marin')
    ->clientSecret();

$answer = Live::voice()
    ->model(Azure::model('gpt-realtime'))
    ->voice('marin')
    ->webRtc($browserOfferSdp);

// Return $answer->sdp from your HTTP endpoint as application/sdp.
// $answer->callId can be used to attach an optional server controller.
if ($answer->callId !== null) {
    $control = Live::voice()
        ->model(Azure::model('gpt-realtime'))
        ->call($answer->callId)
        ->connect(Transport::auto());
}
```

`clientSecret()` and `webRtc()` are also available on Azure's realtime transcription and translation builders because those models document the same WebRTC connection pattern.

### SIP calls and sideband control

[](#sip-calls-and-sideband-control)

Verify the exact raw webhook body before accepting an incoming call:

```
$event = Azure::verifyWebhook($rawBody, $requestHeaders, $signingSecret);

if ($event['type'] === 'realtime.call.incoming') {
    $call = Live::voice()
        ->model(Azure::model('gpt-realtime'))
        ->instructions('Answer as the support desk.')
        ->call($event['data']['call_id'])
        ->accept();

    // Optional server-side WebSocket attached to the provider-hosted call.
    $control = $call->connect(Transport::auto());
    $control->requestResponse();

    // Later:
    $call->hangup();
}
```

The SIP provider carries media. The sideband WebSocket lets PHP monitor events, update the session, run tools, and send response commands using the existing call ID.

Embeddings
----------

[](#embeddings)

```
use AiSdk\Azure;
use AiSdk\Generate;

$result = Generate::embedding(['Search query', 'Document text'])
    ->model(Azure::model('my-embedding-deployment'))
    ->dimensions(512)
    ->providerOptions('azure', ['user' => 'user-123'])
    ->run();

$vector = $result->output->vector;
```

The default Azure `/openai/v1/embeddings` endpoint sends the deployment name in the request's `model` field. When `useDeploymentBasedUrls` is enabled, the same identifier is placed in the classic `/deployments/{deployment}/embeddings` URL.

Streaming
---------

[](#streaming)

```
use AiSdk\Azure;
use AiSdk\Generate;

foreach (Generate::text('Tell me a story.')->model(Azure::model('gpt-4o'))->stream()->chunks() as $chunk) {
    echo $chunk;
}
```

Text API surface
----------------

[](#text-api-surface)

Chat Completions remains the default. Azure's v1 Responses API can be selected for a provider instance or an individual request:

```
Azure::create([
    'apiKey' => 'azure-...',
    'resourceName' => 'my-resource',
    'api' => 'responses',
]);

$result = Generate::text('Explain this code.')
    ->model(Azure::model('my-model-deployment'))
    ->providerOptions('azure', ['api' => 'responses'])
    ->run();
```

Supported values are `chat_completions` and `responses`. Responses requires the current `/openai/v1` endpoint and is intentionally unavailable when `useDeploymentBasedUrls` is enabled.

Configuration
-------------

[](#configuration)

Azure OpenAI resolves the endpoint from either a resource name or an explicit base URL.

VariableDescriptionDefault`AZURE_OPENAI_API_KEY`API key authentication—`AZURE_OPENAI_AUTH_TOKEN` / `AZURE_OPENAI_AD_TOKEN`Microsoft Entra ID bearer token—`AZURE_RESOURCE_NAME`Azure OpenAI resource name—`AZURE_OPENAI_BASE_URL`Resource endpoint (`https://{resource}.openai.azure.com`); `/openai` and `/openai/v1` suffixes are normalized—```
Azure::create([
    'apiKey' => 'azure-...',
    'resourceName' => 'my-resource',
    'apiVersion' => '2024-10-21', // Used only by classic deployment URLs.
    // Set to true to use classic deployment-based URLs.
    'useDeploymentBasedUrls' => false,
]);
```

Authentication
--------------

[](#authentication)

Azure OpenAI accepts an API key **or** Microsoft Entra ID (Azure AD) where the selected endpoint supports it. Microsoft's current embeddings guide documents API-key authentication for the Azure `/openai/v1/embeddings` endpoint, so configure `apiKey` for those requests.

```
// API key
Azure::create(['apiKey' => 'azure-...', 'resourceName' => 'my-resource']);

// Static Entra ID token
Azure::create(['entraToken' => $token, 'resourceName' => 'my-resource']);

// Entra ID token provider (refreshed per request) — plug in MSAL / azure-identity
Azure::create([
    'resourceName' => 'my-resource',
    'tokenProvider' => fn (): string => $credential->getToken('https://ai.azure.com/.default'),
]);
```

The current Azure `/openai/v1` API is the default and does not send an `api-version` query parameter. Set `useDeploymentBasedUrls` to `true` only for a classic deployment URL that still requires one.

Reasoning
---------

[](#reasoning)

```
use AiSdk\Reasoning;

$result = Generate::text('Explain the tradeoff.')
    ->model(Azure::model('o3-mini'))
    ->reasoning(Reasoning::effort('low'))
    ->run();
```

Testing
-------

[](#testing)

```
composer test
```

The default suite uses protocol fixtures and conformance checks. Credentialed Live network verification is separate from the default test run.

Documentation
-------------

[](#documentation)

- [PHP AI SDK documentation](https://phpaisdk.com/docs)
- [Azure documentation](https://phpaisdk.com/docs/azure)

Community
---------

[](#community)

- [Contributing](https://github.com/phpaisdk/.github/blob/main/CONTRIBUTING.md)
- [Support](https://github.com/phpaisdk/.github/blob/main/SUPPORT.md)
- For private security reports, email .

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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

Every ~0 days

Total

6

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef29d1962da41e7526023f215cf844494e209b2fd163742084cb919a3b508021?d=identicon)[aisdk](/maintainers/aisdk)

---

Top Contributors

[![RanaMoizHaider](https://avatars.githubusercontent.com/u/58527494?v=4)](https://github.com/RanaMoizHaider "RanaMoizHaider (11 commits)")

---

Tags

aiopenaiazurellmopenai-compatibleaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aisdk-azure/health.svg)

```
[![Health](https://phpackages.com/badges/aisdk-azure/health.svg)](https://phpackages.com/packages/aisdk-azure)
```

###  Alternatives

[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36863.5k2](/packages/telnyx-telnyx-php)

PHPackages © 2026

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