Meridian PHP SDK
Integrate Meridian into your Laravel, Symfony, or vanilla PHP application using the official OpenAI PHP client. Drop-in compatible with zero vendor lock-in.
Installation
Install the official openai-php/client package via Composer. Meridian is fully compatible — just point the base URI at our endpoint.
composer require openai-php/clientQuick Start
Configure the client with your Meridian API key and base URI. The client behaves identically to the OpenAI PHP SDK — all methods, streaming, and error handling work out of the box.
<?php
use OpenAI\Client;
$client = OpenAI::factory()
->withApiKey('sk-meridian-xxxxxxxxxxxxxxxx')
->withBaseUri('https://meridian.getnimbus.net/api')
->withHttpClient(new \GuzzleHttp\Client([
'timeout' => 30,
]))
->make();
// Your Meridian client is ready
$response = $client->chat()->create([
'model' => 'meridian-pro',
'messages' => [
['role' => 'user', 'content' => 'Hello from PHP!'],
],
]);
echo $response->choices[0]->message->content;Streaming Responses
Use createStreamed() for real-time token delivery. Ideal for chat interfaces and long-form generation.
<?php
$stream = $client->chat()->createStreamed([
'model' => 'meridian-pro',
'messages' => [
['role' => 'user', 'content' => 'Write a haiku about code'],
],
]);
foreach ($stream as $chunk) {
if ($delta = $chunk->choices[0]->delta->content ?? null) {
echo $delta;
ob_flush();
flush();
}
}Error Handling
Wrap API calls in try/catch blocks. The SDK throws typed exceptions for rate limits, authentication failures, and server errors.
<?php
try {
$response = $client->chat()->create([
'model' => 'meridian-pro',
'messages' => [
['role' => 'user', 'content' => 'Hello'],
],
]);
} catch (\OpenAI\Exceptions\ErrorException $e) {
error_log('Meridian API error: ' . $e->getMessage());
// Handle rate limits, auth failures, etc.
} catch (\Exception $e) {
error_log('General error: ' . $e->getMessage());
}Framework Integration
Laravel
Bind the client as a singleton in AppServiceProvider. Use app(MeridianClient::class) or dependency injection throughout your application.
Symfony
Register the client as a service in services.yaml. Autowire it into controllers and commands. Configure the base URI and API key via environment variables.