PHP code example of rodiumai / laravel-sdk

1. Go to this page and download the library: Download rodiumai/laravel-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rodiumai / laravel-sdk example snippets


use RodiumAI\Facades\RodiumAI;

$response = RodiumAI::model('openai/gpt-4o')
    ->temperature(0.7)
    ->maxTokens(300)
    ->chat('Explain Rodium AI in two sentences.');

echo $response->content;
echo $response->costRodi(); // RODI cost from usage.cost_rodi

use RodiumAI\RodiumAIClient;

$client = new RodiumAIClient(apiKey: getenv('RODIUMAI_API_KEY'));
$response = $client->chat('Hello!');
echo $response->content;

use RodiumAI\Data\ChatMessage;

$messages = [
    ChatMessage::system('You are a Laravel assistant.'),
    ChatMessage::user('What is a Service Provider?'),
];

$response = RodiumAI::model('openai/gpt-4o')
    ->temperature(0.5)
    ->maxTokens(500)
    ->chat($messages, [
        'tools' => [/* OpenAI tool definitions */],
        'response_format' => ['type' => 'json_object'],
    ]);

echo $response->content;
echo $response->costRodi();

$history = [
    ChatMessage::user('My name is Amina.'),
    ChatMessage::assistant('Nice to meet you, Amina!'),
    ChatMessage::user('What is my name?'),
];
$response = RodiumAI::chat($history);

$b64 = base64_encode(file_get_contents('invoice.png'));

$response = RodiumAI::chat([[
    'role' => 'user',
    'content' => [
        ['type' => 'text', 'text' => 'Extract the total amount.'],
        ['type' => 'image_url', 'image_url' => ['url' => "data:image/png;base64,{$b64}"]],
    ],
]], ['model' => 'openai/gpt-4o']);

$response = RodiumAI::chat('Weather in Lomé?', [
    'model' => 'openai/gpt-4o',
    'tools' => [[
        'type' => 'function',
        'function' => [
            'name' => 'get_weather',
            'parameters' => [
                'type' => 'object',
                'properties' => ['city' => ['type' => 'string']],
                '

$response = RodiumAI::model('rodiumai/smart')->chat('Summarize RODI credits.');
$routing = $response->routing();

foreach (RodiumAI::model('openai/gpt-4o')->stream('Tell a short story.') as $delta) {
    echo $delta;
}

$history = [];

$ask = function (string $userText) use (&$history) {
    $history[] = ChatMessage::user($userText);
    $parts = '';
    foreach (RodiumAI::stream($history) as $delta) {
        echo $delta; // push to UI
        $parts .= $delta;
    }
    $history[] = ChatMessage::assistant($parts);
    return $parts;
};

$ask('Bonjour!');
$ask('Rappelle-moi ma première question.');

return response()->stream(function () {
    foreach (RodiumAI::stream('Hello') as $delta) {
        echo 'data: ' . json_encode(['delta' => $delta]) . "\n\n";
        ob_flush();
        flush();
    }
    echo "data: [DONE]\n\n";
}, 200, ['Content-Type' => 'text/event-stream', 'Cache-Control' => 'no-cache']);

$catalogue = RodiumAI::models();
$catalogue->ids();
$catalogue->chatModels();
$catalogue->byProvider('anthropic');
$catalogue->findById('openai/gpt-4o');

$info = RodiumAI::modelInfo('openai/gpt-4o');
$info->contextWindow;
$info->pricing();

$coding = RodiumAI::codingModels();

$response = RodiumAI::embeddings('Hello world', [
    'model' => 'openai/text-embedding-3-small',
]);

$vector = $response->firstEmbedding();

// Batch
$response = RodiumAI::embeddings(['Sentence A', 'Sentence B'], [
    'model' => 'openai/text-embedding-3-small',
]);

$image = RodiumAI::images([
    'model' => 'openai/gpt-image-1',
    'prompt' => 'A red fox in the snow',
    'size' => '1024x1024',
    'quality' => 'medium',
]);
$b64 = $image->firstB64();

$ref = base64_encode(file_get_contents('product.png'));

$image = RodiumAI::images([
    'model' => 'google/gemini-3.1-flash-image',
    'prompt' => 'Soft white studio background',
    'image' => ['b64_json' => $ref, 'mime_type' => 'image/png'],
]);

$image = RodiumAI::images([
    'model' => 'openai/gpt-image-1',
    'prompt' => 'Replace sky with sunset',
    'image' => ['b64_json' => $sourceB64],
    'mask' => ['b64_json' => $maskB64],
]);

$video = RodiumAI::videos([
    'model' => 'google/veo-3.1-generate-preview',
    'prompt' => 'Ocean waves at golden hour',
    'duration_seconds' => 8,
    'timeout' => 600,
]);

$frame = base64_encode(file_get_contents('storyboard.png'));

$video = RodiumAI::videos([
    'model' => 'google/veo-3.1-generate-preview',
    'prompt' => 'Subtle pulse animation',
    'duration_seconds' => 8,
    'image' => ['b64_json' => $frame, 'mime_type' => 'image/png'],
    'timeout' => 600,
]);

$video = RodiumAI::videos([
    'model' => 'google/veo-3.1-generate-preview',
    'prompt' => 'Smooth morph between frames',
    'image' => ['b64_json' => $startB64],
    'last_frame' => ['b64_json' => $endB64],
    'timeout' => 600,
]);

$transcript = RodiumAI::transcribe('/path/to/audio.mp3', [
    'model' => 'google/gemini-2.5-flash',
    'language' => 'fr',
]);
echo $transcript->text;

$audioBytes = RodiumAI::speech([
    'model' => 'openai/tts-1',
    'input' => 'Hello from RodiumAI',
    'voice' => 'nova',
    'response_format' => 'mp3',
]);
file_put_contents('speech.mp3', $audioBytes);

$response = RodiumAI::messages([
    'model' => 'anthropic/claude-sonnet-4-6',
    'max_tokens' => 1024,
    'system' => 'You are concise.',
    'messages' => [
        ['role' => 'user', 'content' => 'Explain RODI credits.'],
    ],
]);

echo $response->content;

$wallet = RodiumAI::wallet();
echo $wallet->balanceRodi;

$pricing = RodiumAI::pricing();
$pricing->findByModel('openai/gpt-4o');

use RodiumAI\Exceptions\InsufficientCreditsException;
use RodiumAI\Exceptions\RateLimitException;
use RodiumAI\Facades\RodiumAI;

try {
    RodiumAI::chat('Test');
} catch (InsufficientCreditsException $e) {
    logger()->warning('Insufficient RODI', ['code' => $e->errorCode()]);
} catch (RateLimitException $e) {
    sleep($e->retryAfter() ?? 30);
}
bash
php artisan vendor:publish --tag=rodiumai-config
bash
composer install
composer test                 # PHPUnit (mocked HTTP)
export RODIUMAI_API_KEY="rd_sk_..."
php bin/smoke-test.php        # Live API walkthrough