aisdk/openai-compatible
Composer 安装命令:
composer require aisdk/openai-compatible
包简介
Shared OpenAI-compatible chat-completions wire format (request builder, response/stream parsers) for the PHP AI SDK.
README 文档
README
Shared OpenAI-compatible chat-completions wire adapter for the PHP AI SDK. Reusable by any provider that speaks the OpenAI /chat/completions REST/SSE protocol.
Installation
composer require aisdk/openai-compatible
What This Package Does
This package provides the shared wire-format bridge between core portable contracts (AiSdk\*) and the OpenAI-compatible chat-completions shape. 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) - Message conversion (
ChatMessageConverter) - Tool conversion (
ChatToolConverter) - Usage normalization (
ChatUsage) - Finish reason mapping (
MapsFinishReason)
It does not own:
- Provider authentication
- Model catalogs
- Provider-specific quirks or fallback behavior
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);
Provider Integration
To build a provider on top of this package:
- Depend on
aisdk/coreandaisdk/openai-compatible. - Create a provider class extending
BaseProvider. - Create a text model extending
BaseModelthat callsChatRequestBuilder::build(),ChatResponseParser::parse(), andChatStreamParser::parse(). - Add provider-specific auth, base URL, headers, and model catalog.
- Apply any provider-specific adaptations (e.g., structured output downgrades) after calling
ChatRequestBuilder::build().
Testing
composer test
Links
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-30