DEVUP Docs
Back to Dashboard

Integrations

Laravel

The Laravel AI SDK (laravel/ai) is Laravel's official package for AI features. Its openai-compatible driver connects it to DEVUP AI, so agents, streaming, tools, structured output and embeddings run on DEVUP AI models.

Requirements

Install the Laravel AI SDK

bash
composer require laravel/ai
bash
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
bash
php artisan migrate

vendor:publish creates config/ai.php; the migration adds the tables the SDK uses to store agent conversations.

Add DEVUP AI as an OpenAI-compatible provider

Add your key to .env:

bash
DEVUP_API_KEY=your-key

Then add this entry under 'providers' in config/ai.php:

php
'devupai' => [
    'driver' => 'openai-compatible',
    'url' => 'https://api.devupai.com/v1',
    'key' => env('DEVUP_API_KEY'),
    'models' => [
        'text' => ['default' => 'deepseek-ai/DeepSeek-V4-Pro'],
        'embeddings' => ['default' => 'BAAI/bge-m3'],
    ],
],

Provider options

OptionValueWhy
driveropenai-compatibleUses the SDK's driver for OpenAI-compatible APIs.
urlhttps://api.devupai.com/v1Sends requests to DEVUP AI. Required.
keyenv('DEVUP_API_KEY')Sent as a bearer token.
models.text.defaultdeepseek-ai/DeepSeek-V4-ProThe model agents use when you do not pass one.
models.embeddings.defaultBAAI/bge-m3OpenAI-compatible providers need a default embeddings model.

Prompt an agent

php
use function Laravel\Ai\agent;

$response = agent()->prompt('Reply with exactly: Salam DEVUP', provider: 'devupai');

echo $response->text, PHP_EOL;

Output: Salam DEVUP

Stream responses in Laravel

php
use Laravel\Ai\Streaming\Events\TextDelta;

foreach (agent()->stream('Count from 1 to 5, separated by spaces.', provider: 'devupai') as $event) {
    if ($event instanceof TextDelta) {
        echo $event->delta;
    }
}
echo PHP_EOL;

Output: 1 2 3 4 5

Return agent()->stream(...) from a route and Laravel sends it to the browser as server-sent events.

Tool calling with the Laravel AI SDK

A tool implements the Tool contract: a description, a JSON schema for its arguments, and a handle method. php artisan make:tool generates one in app/Ai/Tools.

php
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Ai\Contracts\Tool;
use Laravel\Ai\Tools\Request;

class GetOrderStatus implements Tool
{
    public function description(): string
    {
        return 'Look up the delivery status of an order by its ID.';
    }

    public function handle(Request $request): string
    {
        return 'Order ' . $request['order_id'] . ' has shipped. Tracking number: DZ-4471.';
    }

    public function schema(JsonSchema $schema): array
    {
        return [
            'order_id' => $schema->string()->required(),
        ];
    }
}

$answer = agent(tools: [new GetOrderStatus])->prompt('What is the status of order A-100?', provider: 'devupai');

echo $answer->text, PHP_EOL;

The tracking number DZ-4471 only exists in the tool, so seeing it in the reply shows the tool ran.

Structured output

php
$capital = agent(schema: fn (JsonSchema $schema) => [
    'city' => $schema->string()->required(),
    'country' => $schema->string()->required(),
])->prompt('Which city is the capital of Algeria?', provider: 'devupai');

echo $capital['city'], ', ', $capital['country'], PHP_EOL;

Output: Algiers, Algeria

Prefer descriptive field names such as city over name. See Structured Outputs.

Create embeddings in Laravel

php
use Laravel\Ai\Embeddings;

$vectors = Embeddings::for(['Salam DEVUP'])->generate('devupai', 'BAAI/bge-m3');

echo count($vectors->embeddings[0]), PHP_EOL;

Output: 1024

BAAI/bge-m3 returns 1024-dimensional vectors. See Embeddings.

Choosing models

Use exact catalog IDs in config/ai.php or pass model: to prompt. Tool calling needs a model whose catalog entry supports it. See Models and Tool Calling.

Troubleshooting

  • Authentication error (401)Check that DEVUP_API_KEY is set and that the devupai provider reads it with env('DEVUP_API_KEY').
  • openai-php/laravel will not install on Laravel 13On a new Laravel 13 app, Composer installs Guzzle 8, while openai-php/laravel 0.21 requires Guzzle 7, so Composer cannot resolve it. The Laravel AI SDK has no such requirement.
  • cURL error 60 on WindowsPHP on Windows ships without CA certificates. Download cacert.pem from https://curl.se/ca/cacert.pem and set curl.cainfo and openssl.cafile to its path in php.ini. Keep SSL verification on. See PHP Integration.
  • A structured field comes back as an identifierWith a JSON-schema response format, a field called name can be filled with an identifier instead of a value. Use a descriptive key such as city.

FAQ

Does the Laravel AI SDK work with DEVUP AI?

Yes. Add a provider with the openai-compatible driver, url https://api.devupai.com/v1 and your DEVUP AI key, then pass provider: 'devupai' when you prompt.

Which Laravel and PHP versions are supported?

The Laravel AI SDK supports Laravel 12 and 13 and requires PHP 8.3 or newer.

How is Laravel usage billed on DEVUP AI?

Every request is a regular DEVUP AI API call, metered in Algerian Dinar on your account.

Can I use openai-php/laravel instead?

On a new Laravel 13 app it does not install: openai-php/laravel 0.21 requires Guzzle 7, and Laravel 13 installs Guzzle 8. The Laravel AI SDK has no such requirement.

Why does the provider need a default embeddings model?

OpenAI-compatible providers have no known models, so the Laravel AI SDK needs models.embeddings.default to create embeddings. BAAI/bge-m3 is a good default.

Can I stream agent responses to the browser?

Yes. Return agent()->stream(...) from a route and Laravel sends it as server-sent events.

Related integrations

  • PHP: openai-php/client in any PHP project.
  • OpenAI SDK: OpenAI SDKs pointed at DEVUP AI.
  • Vercel AI SDK: Streaming chat UIs in TypeScript.
  • Python: The official OpenAI Python SDK on DEVUP AI.