๐ข๐ฝ๐ฒ๐ป๐๐ ๐ฃ๐๐ฃ ๐ฆ๐๐ ๐๐๐ถ๐ฑ๐ฒ (๐ฎ๐ฌ๐ฎ๐ฒ)
Add AI to your PHP apps with the official client. This library handles chat, streaming, and images.
Install it with this command: composer require openai-php/client
Set up your client: $client = OpenAI::client(getenv('OPENAI_API_KEY'));
Use these tools for your project:
- Chat completions: Use chat()->create() for text answers.
- Streaming: Use createStreamed() for real-time text.
- Vectors: Use embeddings()->create() for data search.
- Images: Use images()->create() for DALL-E.
- Audio: Use audio()->transcribe() for Whisper.
Handle errors to keep your app stable:
- Catch ErrorException for API issues.
- Catch TransporterException for network issues.
Source: https://dev.to/kalyna_pro/openai-php-sdk-complete-guide-with-code-examples-2026-3cdb