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

ActiveLibrary[API Development](/categories/api)

aisdk/openai-compatible
=======================

Shared OpenAI-compatible Chat Completions and Responses API wire helpers for the PHP AI SDK.

v0.8.1(1mo ago)0640↓50%20MITPHPPHP ^8.3CI passing

Since Jun 30Pushed 4w agoCompare

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

READMEChangelog (10)Dependencies (12)Versions (15)Used By (20)

aisdk/openai-compatible
=======================

[](#aisdkopenai-compatible)

[![GitHub Workflow Status](https://camo.githubusercontent.com/3ec59ac12586bcb44a10b7a920c9aba8bafea21ac511becf46d41f7919fb1b4f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706870616973646b2f6f70656e61692d636f6d70617469626c652f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/phpaisdk/openai-compatible/actions)[![Total Downloads](https://camo.githubusercontent.com/596ebe21be2a8e0a7a5fd327bee80f98b8b2d3bc15a302f4eb8027a9a9347841/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616973646b2f6f70656e61692d636f6d70617469626c65)](https://packagist.org/packages/aisdk/openai-compatible)[![Latest Version](https://camo.githubusercontent.com/ee18819a6f9efcff66bc87879aec1d001615dee41020c5fc74694a5a69d95415/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616973646b2f6f70656e61692d636f6d70617469626c65)](https://packagist.org/packages/aisdk/openai-compatible)[![License](https://camo.githubusercontent.com/a8c1b8f00904dee32604c23038d515ceabe414aff8ecec9ae9c80100f32ed2f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616973646b2f6f70656e61692d636f6d70617469626c65)](https://packagist.org/packages/aisdk/openai-compatible)[![Why PHP in 2026](https://camo.githubusercontent.com/d2b9305e630caf7daae4ca023de39ece0b885c37461629d42961533f00868b76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5768795f5048502d696e5f323032362d3741383645383f7374796c653d666c61742d737175617265266c6162656c436f6c6f723d313831383162)](https://whyphp.dev)

---

Shared OpenAI-compatible wire adapter for the PHP AI SDK. Reusable by any provider that speaks OpenAI-compatible Chat Completions, Responses, embedding, image generation, speech generation, or transcription APIs.

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

[](#installation)

```
composer require aisdk/openai-compatible
```

What This Package Does
----------------------

[](#what-this-package-does)

This package provides the shared wire-format bridge between core portable contracts (`AiSdk\*`) and OpenAI-compatible provider shapes. It is used by providers like Groq, xAI, OpenRouter, and others that implement the OpenAI-compatible API.

It owns:

- Request body building (`ChatRequestBuilder`)
- Response parsing (`ChatResponseParser`)
- SSE stream parsing (`ChatStreamParser`)
- Responses request body building (`ResponsesRequestBuilder`)
- Responses request profiles (`ResponsesRequestProfile`)
- Responses response parsing (`ResponsesResponseParser`)
- Responses SSE stream parsing (`ResponsesStreamParser`)
- Embedding request body building (`EmbeddingRequestBuilder`)
- Embedding response parsing (`EmbeddingResponseParser`)
- Image request body building (`ImageRequestBuilder`)
- Image response parsing (`ImageResponseParser`)
- Speech request body building (`SpeechRequestBuilder`)
- Speech response parsing (`SpeechResponseParser`)
- Multipart transcription request building (`TranscriptionRequestBuilder`)
- Transcription response parsing (`TranscriptionResponseParser`)
- Message conversion (`ChatMessageConverter`)
- Tool conversion (`ChatToolConverter`)
- Usage normalization (`ChatUsage`)
- Finish reason mapping (`MapsFinishReason`)

It does **not** own:

- Provider authentication
- Model inventories
- Provider-specific quirks or fallback behavior

Usage
-----

[](#usage)

This package is consumed by provider packages, not directly by end users. A provider that speaks OpenAI-compatible chat completions uses it like this:

```
use AiSdk\OpenAICompatible\ChatRequestBuilder;
use AiSdk\OpenAICompatible\ChatResponseParser;
use AiSdk\OpenAICompatible\ChatStreamParser;

$body = ChatRequestBuilder::build($modelId, $providerName, $request, stream: false);
$payload = $this->runner()->postJson($url, $body, $headers, $providerName);
$response = ChatResponseParser::parse($payload, $providerName);
```

For Responses endpoints, use the separate Responses wire helpers rather than adapting a Chat Completions body:

```
use AiSdk\OpenAICompatible\ResponsesRequestBuilder;
use AiSdk\OpenAICompatible\ResponsesResponseParser;

$body = ResponsesRequestBuilder::build($modelId, $providerName, $request, stream: false);
$payload = $this->runner()->postJson($url, $body, $headers, $providerName);
$response = ResponsesResponseParser::parse($payload, $providerName);
```

For streaming, pass parsed SSE events to `ResponsesStreamParser::parse()` in the same way Chat Completions providers use `ChatStreamParser`.

`ResponsesRequestProfile` lets a provider declare safe endpoint differences such as its output-token field or reasoning parameter path. Unsupported portable features fail at request construction instead of being sent optimistically. Providers can still pass endpoint-specific fields through `providerOptions($providerName, [...])`.

For embedding endpoints:

```
use AiSdk\OpenAICompatible\EmbeddingRequestBuilder;
use AiSdk\OpenAICompatible\EmbeddingResponseParser;

$body = EmbeddingRequestBuilder::build($modelId, $providerName, $request);
$payload = $this->runner()->postJson($url, $body, $headers, $providerName);
$response = EmbeddingResponseParser::parse($payload, $providerName);
```

Providers can configure the dimensions field name or omit it, and can disable the default `encoding_format: float` field when their endpoint uses a different wire shape. Provider-namespaced options and `raw` values are applied after portable fields.

For image generation endpoints:

```
use AiSdk\OpenAICompatible\ImageRequestBuilder;
use AiSdk\OpenAICompatible\ImageResponseParser;

$body = ImageRequestBuilder::build($modelId, $providerName, $request);
$payload = $this->runner()->postJson($url, $body, $headers, $providerName);
$response = ImageResponseParser::parse($payload, $providerName);
```

For speech generation endpoints:

```
use AiSdk\OpenAICompatible\SpeechRequestBuilder;
use AiSdk\OpenAICompatible\SpeechResponseParser;

$body = SpeechRequestBuilder::build($modelId, $providerName, $request);
$response = $this->runner()->postRaw($url, $body, $headers, $providerName);
$parsed = SpeechResponseParser::parse($response, $providerName, 'audio/mpeg');
```

For OpenAI-compatible transcription endpoints:

```
use AiSdk\OpenAICompatible\TranscriptionRequestBuilder;
use AiSdk\OpenAICompatible\TranscriptionResponseParser;

$multipart = TranscriptionRequestBuilder::build($modelId, $providerName, $request);
$httpRequest = $requestFactory->createRequest('POST', $url)
    ->withHeader('Content-Type', 'multipart/form-data; boundary='.$multipart['boundary'])
    ->withBody($streamFactory->createStream($multipart['body']));
$response = $runner->sendRequest($httpRequest, $providerName);
$parsed = TranscriptionResponseParser::parse($response, $providerName);
```

Provider Integration
--------------------

[](#provider-integration)

To build a provider on top of this package:

1. Depend on `aisdk/core` and `aisdk/openai-compatible`.
2. Create a provider class extending `BaseProvider` and implement protected capability hooks such as `textModel()` or `embeddingModel()`.
3. Expose only `Provider::model('model-id')` from the public facade, delegating to the provider instance's `model()` method.
4. Create a text model extending `BaseModel` and select either the Chat Completions helpers or the Responses helpers for the provider endpoint. Both paths support text, tools, structured output, reasoning, streaming, normalized usage, and provider-namespaced options; multimodal content is used only when the provider advertises the corresponding core capability.
5. Add provider-specific auth, base URL, headers, and adapter capabilities.
6. Apply any provider-specific adaptations (e.g., structured output downgrades) after calling `ChatRequestBuilder::build()`.

For embeddings, create a model implementing `EmbeddingModelInterface`, call `EmbeddingRequestBuilder::build()`, then parse the provider payload with `EmbeddingResponseParser::parse()`. For image generation, create an image model implementing `ImageModelInterface`, call `ImageRequestBuilder::build()`, then parse the provider payload with `ImageResponseParser::parse()`. For speech generation, create a speech model implementing `SpeechModelInterface`, call `SpeechRequestBuilder::build()`, then parse the raw audio response with `SpeechResponseParser::parse()`. For transcription, implement `TranscriptionModelInterface`, send the multipart body from `TranscriptionRequestBuilder`, then normalize the response with `TranscriptionResponseParser`. Provider packages still own authentication, endpoint paths, adapter capabilities, and public facades. Model IDs should pass through as opaque provider values instead of being maintained as a package-owned inventory.

Testing
-------

[](#testing)

```
composer test
```

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

[](#documentation)

- [PHP AI SDK documentation](https://phpaisdk.com/docs)
- [OpenAI-compatible documentation](https://phpaisdk.com/docs/advanced/openai-compatible-package)

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

46

—

FairBetter than 92% of packages

Maintenance94

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity46

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 ~1 days

Total

14

Last Release

31d 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 (20 commits)")

---

Tags

aillmchat-completionsopenai-compatibleresponses-apiaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[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.

47394.5k5](/packages/deepseek-php-deepseek-php-client)[wordpress/php-ai-client

A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.

26554.3k26](/packages/wordpress-php-ai-client)[mozex/anthropic-laravel

Laravel integration for the Anthropic API: facade, config publishing, install command, testing fakes, messages, streaming, tool use, thinking, and batches.

76364.8k1](/packages/mozex-anthropic-laravel)[mozex/anthropic-php

PHP client for the Anthropic API: messages, streaming, tool use, thinking, web search, code execution, batches, and more.

48614.7k20](/packages/mozex-anthropic-php)[neuron-core/neuron-laravel

Official Neuron AI Laravel SDK.

11747.5k1](/packages/neuron-core-neuron-laravel)[wordpress/wp-ai-client

An AI client and API for WordPress to communicate with any generative AI models of various capabilities using a uniform API.

12625.3k3](/packages/wordpress-wp-ai-client)

PHPackages © 2026

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