dij-digital/langfuse-laravel

This is my package langfuse-laravel

v0.1.4 2025-08-11 07:53 UTC

This package is auto-updated.

Last update: 2025-08-11 08:00:36 UTC


README

This package provides a wrapper around the langfuse-php package, allowing you to easily integrate Langfuse into your Laravel applications. It uses as few dependencies as possible.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package supports the following features:

Prompts

  • Get text prompts
  • Get chat prompts
  • Compile text prompts
  • Compile chat prompts
  • Create text prompts
  • Create chat prompts
  • Fallback handling for prompt fetching errors
  • Fallback handling when no prompt is found

Ingestion

  • Create traces
  • Create generations

Requires PHP 8.3 or PHP 8.4 in combination with Laravel 11 or Laravel 12

⚡️ Install the package using Composer:

composer require dij-digital/langfuse-laravel  

How to use this package

Prompt

Add the following env keys to your projects .env file:

LANGFUSE_BASE_URI=https://cloud.langfuse.com
LANGFUSE_PUBLIC_KEY=
LANGFUSE_SECRET_KEY=
use DIJ\Langfuse\Laravel\Facades\Langfuse;

Langfuse::prompt()->text('promptName', 'fallback')->compile(['key' => 'value']);
Langfuse::prompt()->text('promptName', 'fallback')->compile(['key' => 'value']);
Langfuse::prompt()->chat('chatName', ['role' => 'user', 'content' => 'fallback'])->compile(['key' => 'value']);
Langfuse::prompt()->list();
Langfuse::prompt()->create('promptName', 'text', PromptType::TEXT);

Ingestion

use DIJ\Langfuse\Laravel\Facades\Langfuse;

// Creates a trace and a generation visible in Langfuse UI
$traceId = 'trace-id-123';

Langfuse::ingestion()->trace(
    input: 'prompt text',
    output: null,
    traceId: $traceId,
    name: 'name',
    sessionId: null,
    metadata: ['key' => 'value']
);

Langfuse::ingestion()->generation(
    input: 'prompt text',
    output: 'model output',
    traceId: $traceId,
    name: 'name',
    sessionId: null,
    promptName: 'promptName',
    promptVersion: 1,
    model: 'gpt-4o',
    modelParameters: ['temperature' => 0.7],
    metadata: ['key' => 'value']
);

Langfuse Laravel was created by Tycho Engberink and is maintained by DIJ Digital under the MIT license.