dij-digital/langfuse-php

A langfuse wrapper for PHP

dev-master 2025-06-25 13:59 UTC

This package is auto-updated.

Last update: 2025-06-25 13:59:51 UTC


README

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

It supports the following features:

  • Getting a text prompt
  • Getting a chat prompt
  • Compiling a text prompt
  • Compiling a chat prompt
  • Create a text prompt
  • Create a chat prompt
  • Fallbacks for prompt fetching when an error occurs
  • Fallbacks for prompt fetching when no prompt is found

Requires PHP 8.4

⚡️ Install the package using Composer:

composer require dij-digital/langfuse-php  

🤙 Modern codebase , refactoring and static analysis in one command

composer codestyle  

🚀 Run the entire test suite:

composer test  

How to use this package

use DIJ\Langfuse\PHP;
use DIJ\Langfuse\PHP\Transporters\HttpTransporter;  
use GuzzleHttp\Client;

$langfuse = new Langfuse(new HttpTransporter(new Client([  
  'base_uri' => 'https://cloud.langfuse.com', //choose as needed
    'auth' => ['PUBLIC_KEY', 'SECRET_KEY'],  //generate a set in your project
])));

$langfuse->prompt()->text('promptName')->compile(['key' => 'value']);
$langfuse->prompt()->text('promptName')->compile(['key' => 'value']);
$langfuse->prompt()->chat('chatName')->compile(['key' => 'value']);
$langfuse->prompt()->list();
$langfuse->prompt()->create('promptName', 'text', PromptType::TEXT);

Langfuse PHP was created by Tycho Engberink under the MIT license.