AIプロバイダをPHPアプリケーションに統合したことがあるなら、そのプロセスはおそらくご存知でしょう。OpenAI SDKを取り込みます。その後、クライアントが画像生成を要求するので、StabilityAIを追加します——異なるSDK、異なるリクエスト形式、異なるエラーハンドリング。次に、音声認識を要求するので、Deepgramを導入します——また別の統合。あっという間に、それぞれ異なる特徴、レスポンス形式、リトライロジックを持つ3つの独立したAPI統合をメンテナンスすることに。
Prismaはこれを修正します.一つのパッケージ。一つのAPI。25以上のプロバイダー。テキスト、画像、オーディオ、ビデオ.
composer require aimeos/prisma
Prismaとは何ですか?
Prisma軽量でMITライセンスのPHPパッケージで、4つのメディアドメインのAIプロバイダーと連携するための統一インターフェースを提供しています。フレームワークの結合はありません。Guzzleが下で動いており、PHP 8.2以降とクリーンなフラットAPIです。
ここに核心的な考え方があります——すべてのプロバイダは同じインターフェースを通じて動作します:
use Aimeos\Prisma\Prisma;
// Generate text with OpenAI
$text = Prisma::text()
->using('openai', ['api_key' => '...'])
->write('Summarize the benefits of renewable energy')
->text();
// Generate an image with StabilityAI
$image = Prisma::image()
->using('stabilityai', ['api_key' => '...'])
->imagine('a mountain landscape at sunset')
->binary();
// Transcribe audio with Deepgram
$transcript = Prisma::audio()
->using('deepgram', ['api_key' => '...'])
->transcribe($audioFile)
->text();
// Describe a video with Gemini
$description = Prisma::video()
->using('gemini', ['api_key' => '...'])
->describe($videoFile)
->text();
同じパターンがどこにでも見られます:Prisma::{domain}()->using(provider, config)->{method}(). 1つの文字列を変更してプロバイダを切り替えます。アプリケーションコードはそのままです。
実践でこれが重要な理由
製品リストツールを作成していると想像してください。次のことが必要です:
- 画像から製品の説明文を生成
- 説明文から構造化データ(名前、価格、カテゴリ)を抽出
- 欠落しているマーケティング画像を生成
Prismaを使用しないと、それは3つの異なるSDK統合です。Prismaを使用すると:
use Aimeos\Prisma\Prisma;
use Aimeos\Prisma\Schema\Schema;
// 1. Describe a product image
$description = Prisma::image()
->using('openai', ['api_key' => '...'])
->describe($productPhoto)
->text();
// 2. Extract structured data
$schema = Schema::for('product', [
'name' => Schema::string()->required(),
'price' => Schema::number(),
'category' => Schema::string()->enum(['electronics', 'clothing', 'food', 'other']),
]);
$product = Prisma::text()
->using('gemini', ['api_key' => '...'])
->structured("Extract product info from: {$description}", $schema)
->structured();
// ['name' => 'Wireless Headphones', 'price' => 79.99, 'category' => 'electronics']
// 3. Generate a product image
$image = Prisma::image()
->using('stabilityai', ['api_key' => '...'])
->imagine("Professional illustration of {$product['name']}")
->binary();
3つのプロバイダー、3つのメディアタイプ、一貫したAPI。そして明日、GeminiをAnthropicに交換したいなら、一行を変更するだけでよい。
プロバイダーの機能を実行時に確認することもできます:
$provider = Prisma::image()->using('clipdrop', ['api_key' => '...']);
if ($provider->has('upscale')) {
$image = $provider->upscale($lowResImage)->binary();
}
// Or throw if the capability is missing
$provider->ensure('upscale'); // throws NotImplementedException if not supported
0.4の新機能
バージョン0.4は、テキスト生成、構造化出力、ツール呼び出し、多くの追加機能を含むメジャーリリースです。以下に追加された内容があります.
14のプロバイダー間のテキスト生成
Thewrite()このメソッドは、OpenAI、Anthropic、Gemini、Bedrock、Mistral、Groq、Cohere、Deepseek、Alibaba、xAI、Perplexity、OpenRouter、Ollama、およびDeepseekにテキスト生成をサポートしてPrismaに導入します。すべての多モーダル — プロンプトと一緒に画像、音声、または文書を渡すことができます。
use Aimeos\Prisma\Base\File;
$response = Prisma::text()
->using('anthropic', ['api_key' => '...'])
->withSystemPrompt('You are a helpful assistant')
->write('Describe this image', [File::from('photo.jpg')]);
echo $response->text();
構造化された出力
LLMから流暢なスキーマビルダーを使用してタイプ付きJSONレスポンスを取得します。Prismaは各プロバイダのネイティブ構造化出力APIを使用します—プロンプトエンジニアリングのハックは不要です:
use Aimeos\Prisma\Schema\Schema;
$schema = Schema::for('event', [
'title' => Schema::string()->required(),
'date' => Schema::string()->format('date')->required(),
'attendees' => Schema::array()->items(Schema::string()),
'location' => Schema::object([
'city' => Schema::string()->required(),
'country' => Schema::string(),
]),
]);
$response = Prisma::text()
->using('openai', ['api_key' => '...'])
->structured('Parse: Team meetup on June 15 in Berlin with Alice and Bob', $schema);
$event = $response->structured();
// [
// 'title' => 'Team meetup',
// 'date' => '2026-06-15',
// 'attendees' => ['Alice', 'Bob'],
// 'location' => ['city' => 'Berlin', 'country' => 'Germany'],
// ]
スキーマビルダーは文字列、整数、数値、ブーリアン、配列、オブジェクト、列挙型(PHPのBackedEnumを含む)、ネストされたオブジェクトをサポートしますrequired()、nullable()、min()/max()、正規表現pattern()、その他も含めます。生のJSONスキーマ配列もSchema::fromArray()を介して渡すことができます.
ツール呼び出しは自動実行されます
面白い部分に出会います。Prismaは自動実行ループを備えた完全なエージェントツール呼び出しをサポートしています。ツールを定義し、モデルがそれらを呼び出し、Prismaがハンドラを実行して結果をフィードバックする——すべて自動的に:
use Aimeos\Prisma\Tools;
use Aimeos\Prisma\Schema\Schema;
$searchTool = Tools::make(
'search_products',
'Search the product database',
Schema::for('search', [
'query' => Schema::string()->description('Search query')->required(),
'limit' => Schema::integer()->description('Max results')->min(1)->max(50),
]),
function(array $args): string {
$results = ProductSearch::query($args['query'], $args['limit'] ?? 10);
return json_encode($results);
}
);
$response = Prisma::text()
->using('openai', ['api_key' => '...'])
->withTools([$searchTool])
->withMaxSteps(5)
->write('Find me the top 3 wireless headphones under $100');
echo $response->text();
// The model searched, got results, and wrote a summary
ツールループ中に何が起こったかを確認できます:
foreach ($response->steps() as $step) {
echo $step->name(); // 'search_products'
echo $step->arguments(); // ['query' => 'wireless headphones', 'limit' => 3]
echo $step->result(); // '[ ... search results ... ]'
}
ツールもサポートしています:
-
各ツールの呼び出し制限:
Tools::make(...)->max(3)— ツールは最大3回まで呼び出せます -
カスタムエラーハンドラ:
->failed(fn($e, $args) => 'Fallback message')— 例外を優雅に捕捉 -
並列実行:
->concurrent()— ツールが並列で実行されますpcntl_fork - デコレータ:ロギングやキャッシング、または任意のカスタム挙動でツールをラップします
-
ツールの選択:
->withToolChoice(Provider::REQ)を使用を強制
プロバイダツール
一部のプロバイダはウェブ検索やコード実行などのサーバーサイドツールを提供しています。Prismaもこれらを標準化します
use Aimeos\Prisma\Tools;
$response = Prisma::text()
->using('anthropic', ['api_key' => '...'])
->withTools([
Tools::provider('web_search'),
Tools::provider('code_execution'),
])
->write('Search for the latest PHP version and verify it');
利用可能なプロバイダツールにはweb_search,code_execution,file_search,web_fetch,image_generation、そしてdocument_library— それぞれがそれをサポートするプロバイダにマッピングされます。同じリクエスト内でカスタムおよびプロバイダツールを組み合わせることができます。
フレームワークツールアダプタ
Laravel AI または Symfony のためのツールは既に構築済みですか?直接再利用してください:
// Laravel AI / Prism tools
$tool = Tools::laravel(new MyLaravelTool());
// Symfony #[AsTool] classes
$tool = Tools::symfony(MySymfonyTool::class);
費用計画を考える
それに対応しているモデルには拡張推論を有効にします。Prismaはトークン数を各プロバイダーのネイティブ形式に自動的にマッピングします:
$response = Prisma::text()
->using('anthropic', ['api_key' => '...'])
->withThinkingBudget(5000)
->withMaxTokens(4096)
->write('Solve this step by step: ...');
// Access the model's reasoning
$thinking = $response->meta()['thinking'] ?? null;
引用
プロバイダーでサポートされている(Anthropic、OpenAI、Gemini、Perplexity、xAI)の正規化された引用オブジェクト:
foreach ($response->citations() as $citation) {
$citation->title(); // source title
$citation->url(); // source URL
$citation->text(); // output text that cites this source
$citation->source(); // verbatim quote from the source
}
レートリミットとリトライ処理
// Automatic retry with exponential backoff
$response = Prisma::text()
->using('openai', ['api_key' => '...'])
->withClientRetry(3, fn($attempt, $resp) => 100 * pow(2, $attempt))
->write('...');
// Inspect rate limit headers
$limit = $response->rateLimit();
$limit->remaining(); // requests left
$limit->retryAfter(); // seconds until reset
プロバイダーのカバレッジ
0.4でテキストプロバイダーにサポートされているものは以下の通り:
| プロバイダ | 構造化 | 翻訳 | 書き込み | 出典 | カスタムツール | プロバイダツール | 思考予算 |
|---|---|---|---|---|---|---|---|
| Alibaba | はい | はい | - | はい | はい | - | |
| アンソプティック | はい | はい | はい | はい | はい | はい | |
| ベドロック | はい | はい | - | はい | はい | ||
| コアハイ | はい | はい | - | はい | - | ||
| Deepseek | はい | はい | - | はい | - | ||
| DeepL | はい | ||||||
| Gemini | はい | はい | はい | はい | はい | はい | |
| はい | |||||||
| Groq | はい | はい | - | はい | - | ||
| Mistral | はい | はい | - | はい | はい | - | |
| Ollama | ベータ | ベータ | - | はい | - | ||
| OpenAI | はい | はい | はい | はい | はい | はい | |
| Openrouter | はい | はい | - | はい | はい | - | |
| Perplexity | ベータ | ベータ | はい | はい | - | ||
| xAI | ベータ | ベータ | はい | はい | はい | はい |
はただのテキストです。Prismaはまた、9オーディオプロバイダー(話す、転写、デミックス、ノイズ除去、リボーカー、説明)、14画像プロバイダー(想像、インペイント、アップスケール、ベクタライズ、背景除去、さらに多くのもの)、およびビデオ説明をGeminiを通じて提供します.
スタートアップ
composer require aimeos/prisma
最小限の例:
<?php
use Aimeos\Prisma\Prisma;
// Text
echo Prisma::text()
->using('openai', ['api_key' => getenv('OPENAI_API_KEY')])
->write('What makes PHP great?')
->text();
// Image
$binary = Prisma::image()
->using('openai', ['api_key' => getenv('OPENAI_API_KEY')])
->imagine('a PHP elephant wearing sunglasses')
->binary();
file_put_contents('elephant.png', $binary);
サービスプロバイダがなく、設定ファイルがなく、フレームワークの依存関係もない。ただし、requireして使用するだけ.
PrismaはMITライセンスでオープンソースです。詳細はこちらをご覧ください:
- ドキュメント:https://php-prisma.org
- GitHub: https://github.com/aimeos/prisma
PHPでAIプロバイダーと統合的に作業する方法を探しているなら——特にテキストだけではなく——試してみてください。フィードバック、問題報告、スターログはすべて歓迎します.
Prismaが好きなら、Githubリポジトリに星を付けてください :-)










