Get expert guidance in a few days with a Laravel code review

Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel

Last updated on by

Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel image

Larapanda is a Laravel SDK for Lightpanda, a headless browser written in Zig. The package handles runtime resolution between CLI binary and Docker, profile-based instance management, typed fetch results, and optional adapters for the Laravel AI SDK and MCP server.

Profile-Based Instance Management

Configuration is organized into named instance profiles. Each profile can override the global defaults for runtime mode, binary path, and Docker settings — making it straightforward to maintain separate profiles for general fetching, crawling, and AI tool sessions.

// config/larapanda.php
'instances' => [
'default' => [],
'crawler' => [
'runtime' => 'cli',
'binary_path' => '/absolute/path/to/lightpanda',
],
'mcp' => [
'runtime' => 'docker',
],
],

Selecting a profile at call time uses the manager interface:

use Ferdiunal\Larapanda\Contracts\LarapandaManagerInterface;
 
$manager = app(LarapandaManagerInterface::class);
 
$defaultClient = $manager->instance('default');
$crawlerClient = $manager->instance('crawler');

Runtime Resolution

The auto runtime prefers CLI execution when a valid binary_path is configured and the binary is executable, and falls back to Docker otherwise. You can also pin a profile to cli or docker explicitly.

Typed Fetch Results

fetchRequest() returns a FetchResult with strict accessors tied to the selected dump format. Calling a mismatched accessor throws UnexpectedFetchOutputFormatException rather than silently returning garbage data.

use Ferdiunal\Larapanda\Enums\FetchDumpFormat;
 
$result = $client->fetchRequest('https://example.com')
->withOptions(
dump: FetchDumpFormat::Markdown,
obeyRobots: true,
waitMs: 2000,
)
->run();
 
$markdown = $result->asMarkdown();
 
// Semantic tree formats
$treeResult = $client->fetchRequest('https://example.com')
->withOptions(dump: FetchDumpFormat::SemanticTree)
->run();
 
$tree = $treeResult->asSemanticTree(); // array<string, mixed>

Proxy support is available per-request:

$result = $client->fetchRequest('https://example.com')
->withOptions(
dump: FetchDumpFormat::Markdown,
httpProxy: 'http://127.0.0.1:3000',
proxyBearerToken: 'MY-TOKEN',
)
->run();

Laravel AI SDK Integration

Larapanda exposes Lightpanda as tools for the Laravel AI SDK. The adapter is session-aware — passing the same session_id across tool calls keeps the browser session open between steps, which matters for multi-step browsing tasks.

composer require laravel/ai laravel/mcp
use Ferdiunal\Larapanda\Integrations\Ai\LarapandaAiTools;
use Illuminate\Support\Facades\AI;
 
$response = AI::provider('openai')
->model('gpt-5-mini')
->prompt('Open laravel.com and return the main headings.')
->tools(app(LarapandaAiTools::class)->make())
->text();

Tool names use the configured prefix (default lightpanda_): lightpanda_markdown, lightpanda_semantic_tree, lightpanda_click, and so on. You can restrict which tools the model sees via config:

'integrations' => [
'ai' => [
'exposed_tools' => ['goto', 'markdown', 'semantic_tree'],
],
],

MCP Server Adapter

For applications using the Laravel MCP server, Larapanda provides an adapter that registers Lightpanda tools with Laravel's container, applies profile-based runtime resolution, and shares the session pool and proxy policy with the AI SDK adapter.

// routes/ai.php
use Ferdiunal\Larapanda\Integrations\Mcp\LarapandaMcpServer;
 
LarapandaMcpServer::registerLocal(name: 'lightpanda');

Session lifetime and pool size are controlled from config:

'integrations' => [
'mcp' => [
'session_ttl_seconds' => 300,
'max_sessions' => 32,
'obey_robots' => true,
],
],

You can find the source and full documentation on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
SerpApi logo

SerpApi

Access real-time search engine results through a simple API—no more scraping headaches! Use it for AI applications, SEO tools, product research, travel information, and more

SerpApi
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

The latest

View all →
Generate HTML Password Rules Attribute in Laravel 13.9.0 image

Generate HTML Password Rules Attribute in Laravel 13.9.0

Read article
DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell image

DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell

Read article
Model-Based Scheduling for Laravel with Cadence image

Model-Based Scheduling for Laravel with Cadence

Read article
Laravel's AI SDK adds sub-agents image

Laravel's AI SDK adds sub-agents

Read article
Laravel Introduces First-Party Passkey Authentication Support image

Laravel Introduces First-Party Passkey Authentication Support

Read article
Scrollbar Styling and Container Size Utilities in Tailwind CSS v4.3.0 image

Scrollbar Styling and Container Size Utilities in Tailwind CSS v4.3.0

Read article