PHPackages                             ikarolaborda/azure-openai-sdk-php - 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. [API Development](/categories/api)
4. /
5. ikarolaborda/azure-openai-sdk-php

ActiveLibrary[API Development](/categories/api)

ikarolaborda/azure-openai-sdk-php
=================================

Azure OpenAI PHP SDK — first-class Azure OpenAI Service support built on top of openai-php/client

v0.2.0(2mo ago)116↓100%MITPHPPHP ^8.2.0CI passing

Since Mar 11Pushed 2mo agoCompare

[ Source](https://github.com/ikarolaborda/azure-openai-sdk-php)[ Packagist](https://packagist.org/packages/ikarolaborda/azure-openai-sdk-php)[ RSS](/packages/ikarolaborda-azure-openai-sdk-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

Azure OpenAI SDK for PHP
========================

[](#azure-openai-sdk-for-php)

A PHP package that brings first-class [Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/ai-services/openai/) support to your applications. Built on top of [openai-php/client](https://github.com/openai-php/client) — the excellent community-maintained PHP client created by [Nuno Maduro](https://github.com/nunomaduro) and contributors.

This package handles Azure-specific deployment-based URL routing, API versioning, and authentication (API keys and Azure AD / Entra ID) so you can work with Azure OpenAI the same way you work with the standard OpenAI API.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
    - [Laravel](#laravel)
    - [Standalone (non-Laravel)](#standalone-non-laravel)
- [Usage](#usage)
    - [Chat Completions](#chat-completions)
    - [Responses API](#responses-api)
    - [Streaming](#streaming)
    - [Embeddings](#embeddings)
    - [Multiple Deployments](#multiple-deployments)
    - [Account-Scoped Operations](#account-scoped-operations)
- [Authentication](#authentication)
    - [API Key](#api-key)
    - [Azure AD / Entra ID Token](#azure-ad--entra-id-token)
    - [Azure AD Token Provider](#azure-ad-token-provider)
- [API Versions](#api-versions)
- [Available Resources](#available-resources)

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

[](#installation)

> **Requires [PHP 8.2+](https://www.php.net/releases/)**

```
composer require ikarolaborda/azure-openai-sdk-php
```

If your project doesn't already have a PSR-18 HTTP client, install one:

```
composer require guzzlehttp/guzzle
```

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

[](#configuration)

### Laravel

[](#laravel)

The package auto-discovers its service provider and facade. Publish the config file:

```
php artisan vendor:publish --tag=azure-openai
```

This creates `config/azure-openai.php`. Then add your credentials to `.env`:

```
AZURE_OPENAI_API_KEY=your-azure-api-key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
AZURE_OPENAI_MODEL_DEPLOYMENT=gpt-4o
AZURE_OPENAI_API_VERSION=2024-10-21
```

Now you can use the facade anywhere in your application:

```
use IkaroLaborda\AzureOpenAI\Facades\AzureOpenAI;

$response = AzureOpenAI::chat()->create([
    'messages' => [
        ['role' => 'user', 'content' => 'Hello!'],
    ],
]);

echo $response->choices[0]->message->content;
```

Or resolve the client from the container:

```
use OpenAI\Client;

$client = app(Client::class);

$response = $client->chat()->create([
    'messages' => [
        ['role' => 'user', 'content' => 'Hello!'],
    ],
]);
```

### Standalone (non-Laravel)

[](#standalone-non-laravel)

Without Laravel, configure the client directly. Set your environment variables and call `client()` with no arguments:

```
use IkaroLaborda\AzureOpenAI\AzureOpenAI;

// Reads from AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT,
// AZURE_OPENAI_MODEL_DEPLOYMENT, and AZURE_OPENAI_API_VERSION
$client = AzureOpenAI::client();
```

Or pass parameters explicitly — any argument takes precedence over its environment variable:

```
$client = AzureOpenAI::client(
    apiKey: 'your-azure-api-key',
    endpoint: 'https://your-resource.openai.azure.com',
    deployment: 'gpt-4o',
    apiVersion: '2024-10-21',
);
```

For full control, use the factory:

```
$client = AzureOpenAI::factory()
    ->withApiKey('your-azure-api-key')
    ->withEndpoint('https://your-resource.openai.azure.com')
    ->withDeployment('gpt-4o')
    ->withApiVersion('2024-10-21')
    ->withHttpClient(new \GuzzleHttp\Client(['timeout' => 120]))
    ->make();
```

If you prefer using the resource name instead of the full endpoint URL:

```
$client = AzureOpenAI::factory()
    ->withApiKey('your-azure-api-key')
    ->withResource('your-resource-name')     // builds https://your-resource-name.openai.azure.com
    ->withDeployment('gpt-4o')
    ->withApiVersion('2024-10-21')
    ->make();
```

Usage
-----

[](#usage)

Because Azure routes requests based on the deployment name in the URL, you don't need to pass a `model` parameter in your calls — it's determined by the deployment you configured.

### Chat Completions

[](#chat-completions)

```
$response = $client->chat()->create([
    'messages' => [
        ['role' => 'system', 'content' => 'You are a helpful assistant.'],
        ['role' => 'user', 'content' => 'What is the capital of France?'],
    ],
]);

echo $response->choices[0]->message->content;
```

### Responses API

[](#responses-api)

The [Responses API](https://platform.openai.com/docs/api-reference/responses) is OpenAI's newest interface for generating model outputs. It works the same way as the Python `client.responses.create()`:

```
$response = $client->responses()->create([
    'input' => 'What is the meaning of life?',
]);

echo $response->outputText;
```

With tools (web search, file search, or custom functions):

```
$response = $client->responses()->create([
    'input' => 'What was the latest news today?',
    'tools' => [
        ['type' => 'web_search_preview'],
    ],
]);

echo $response->outputText;
```

Streamed responses:

```
$stream = $client->responses()->createStreamed([
    'input' => 'Write a short poem about PHP.',
]);

foreach ($stream as $response) {
    if ($response->outputText) {
        echo $response->outputText;
    }
}
```

### Streaming

[](#streaming)

```
$stream = $client->chat()->createStreamed([
    'messages' => [
        ['role' => 'user', 'content' => 'Write a short poem about PHP.'],
    ],
]);

foreach ($stream as $response) {
    echo $response->choices[0]->delta->content;
}
```

### Embeddings

[](#embeddings)

```
$response = $client->embeddings()->create([
    'input' => 'The quick brown fox jumps over the lazy dog.',
]);

$vector = $response->embeddings[0]->embedding; // array of floats
```

### Multiple Deployments

[](#multiple-deployments)

Each client targets a single deployment. If your application uses multiple models, create a client for each:

```
use IkaroLaborda\AzureOpenAI\AzureOpenAI;

// Both clients share the API key and endpoint from env;
// only the deployment differs.
$chatClient = AzureOpenAI::client(deployment: 'gpt-4o');
$embeddingClient = AzureOpenAI::client(deployment: 'text-embedding-3-small');

$chat = $chatClient->chat()->create([
    'messages' => [['role' => 'user', 'content' => 'Summarize this document.']],
]);

$embedding = $embeddingClient->embeddings()->create([
    'input' => 'The quick brown fox jumps over the lazy dog.',
]);
```

### Account-Scoped Operations

[](#account-scoped-operations)

Some Azure OpenAI operations — like listing models or managing files — don't require a deployment. You can omit the deployment for these:

```
$client = AzureOpenAI::factory()
    ->withApiKey('your-azure-api-key')
    ->withEndpoint('https://your-resource.openai.azure.com')
    ->withApiVersion('2024-10-21')
    ->make();

$models = $client->models()->list();
```

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

[](#authentication)

### API Key

[](#api-key)

The most common method. Your key is sent via the `api-key` header:

```
$client = AzureOpenAI::factory()
    ->withApiKey('your-azure-api-key')
    ->withEndpoint('https://your-resource.openai.azure.com')
    ->withDeployment('gpt-4o')
    ->withApiVersion('2024-10-21')
    ->make();
```

### Azure AD / Entra ID Token

[](#azure-ad--entra-id-token)

For production workloads, Azure AD tokens are recommended over API keys:

```
$client = AzureOpenAI::factory()
    ->withAzureAdToken($token)
    ->withEndpoint('https://your-resource.openai.azure.com')
    ->withDeployment('gpt-4o')
    ->withApiVersion('2024-10-21')
    ->make();
```

### Azure AD Token Provider

[](#azure-ad-token-provider)

For long-running processes where tokens expire, pass a callable that fetches a fresh token on each request:

```
$client = AzureOpenAI::factory()
    ->withAzureAdTokenProvider(function () use ($credential) {
        $token = $credential->getToken('https://cognitiveservices.azure.com/.default');

        return $token->token;
    })
    ->withEndpoint('https://your-resource.openai.azure.com')
    ->withDeployment('gpt-4o')
    ->withApiVersion('2024-10-21')
    ->make();
```

API Versions
------------

[](#api-versions)

Azure OpenAI requires an explicit API version on every request. The package provides an enum with known versions:

```
use IkaroLaborda\AzureOpenAI\Enums\AzureApiVersion;

$client = AzureOpenAI::factory()
    ->withApiKey('your-azure-api-key')
    ->withEndpoint('https://your-resource.openai.azure.com')
    ->withDeployment('gpt-4o')
    ->withApiVersion(AzureApiVersion::V2024_10_21->value)
    ->make();
```

Enum CaseValue`V2024_06_01``2024-06-01``V2024_10_21``2024-10-21``V2025_01_01_PREVIEW``2025-01-01-preview``V2025_03_01_PREVIEW``2025-03-01-preview`Available Resources
-------------------

[](#available-resources)

This package gives you access to all resources provided by [openai-php/client](https://github.com/openai-php/client), routed through Azure's deployment-based endpoints. Deployment-scoped resources (chat, completions, embeddings, images, audio, responses) are automatically routed via `/deployments/{deployment}/`. Account-scoped resources (models, files, fine-tuning, assistants, threads, batches, vector stores, moderations) are routed directly under `/openai/`.

For full resource documentation, see the [openai-php/client README](https://github.com/openai-php/client#usage).

---

Built with care by [Ikaro C. Laborda](https://github.com/ikarolaborda). Licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance88

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

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

Every ~0 days

Total

2

Last Release

61d ago

### Community

Maintainers

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

---

Top Contributors

[![ikarolaborda](https://avatars.githubusercontent.com/u/12631361?v=4)](https://github.com/ikarolaborda "ikarolaborda (6 commits)")

---

Tags

phpapiclientlaravelsdkaiopenaiazureazure-openai

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ikarolaborda-azure-openai-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/ikarolaborda-azure-openai-sdk-php/health.svg)](https://phpackages.com/packages/ikarolaborda-azure-openai-sdk-php)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[openai-php/symfony

Symfony Bundle for OpenAI

215715.5k3](/packages/openai-php-symfony)[gemini-api-php/laravel

Gemini API client for Laravel

8915.7k](/packages/gemini-api-php-laravel)

PHPackages © 2026

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