PHP code example of anilcancakir / laravel-ai-sdk-plus

1. Go to this page and download the library: Download anilcancakir/laravel-ai-sdk-plus 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/ */

    

anilcancakir / laravel-ai-sdk-plus example snippets


class DesignAgent extends Agent
{
    use Skillable;

    public function skills(): iterable
    {
        return ['wind-ui'];
    }
}

use Laravel\Ai\Attributes\Thinking;

#[Thinking]                        // Enable with defaults
#[Thinking(effort: 'low')]         // Reasoning effort (OpenAI, Gemini, OpenAI-Compatible)
#[Thinking(budgetTokens: 10000)]   // Token budget (Anthropic, Gemini)
#[Thinking(effort: 'high', budgetTokens: 16000)] // Both

// config/ai.php
'providers' => [
    'my-provider' => [
        'driver' => 'openai-compatible',
        'key' => env('MY_PROVIDER_API_KEY'),
        'url' => 'https://api.my-provider.com/v1',
        'models' => [
            'default' => 'gpt-4o',
            'image' => 'image-model',
        ],
    ],
],

use Laravel\Ai\Ai;

$response = Ai::textProvider('my-provider')
    ->prompt('Explain quantum computing in one sentence.');

use Laravel\Ai\Image;

// Basic image generation
$response = Image::of('A cat wearing a top hat')->generate('my-provider');

// Access the generated image
$response->firstImage()->image; // Base64 content
$response->firstImage()->mime;  // e.g. 'image/png'

// Save to disk
$response->store('images', 'public');

// With size and quality options
Image::of('A futuristic cityscape')
    ->landscape()
    ->quality('high')
    ->generate('my-provider');

// With reference image attachments
use Laravel\Ai\Files\Image as ImageFile;

Image::of('Make this image more vibrant')
    ->attachments([
        ImageFile::fromPath('/path/to/reference.jpg'),
    ])
    ->generate('my-provider');

// config/ai.php
'default_for_images' => 'my-provider',

// Then simply:
Image::of('A mountain at dawn')->generate();