dij-digital / langfuse-php
A langfuse wrapper for PHP
v0.1.4
2025-08-08 12:18 UTC
Requires
- php: ^8.3|^8.4
- guzzlehttp/guzzle: ^7.9
Requires (Dev)
- laravel/pint: ^1.22.1
- peckphp/peck: ^0.1.3
- pestphp/pest: ^3.8.0
- pestphp/pest-plugin-type-coverage: ^3.5.0
- phpstan/phpstan: ^2.1.16
- rector/rector: ^2.0.16
- symfony/var-dumper: ^7.2.6
This package is auto-updated.
Last update: 2025-08-08 12:23:40 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.
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
⚡️ Install the package using Composer:
composer require dij-digital/langfuse-php
How to use this package
Prompt
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: 'promptName')->compile(params: ['key' => 'value']); $langfuse->prompt()->text(promptName: 'promptName')->compile(params: ['key' => 'value']); $langfuse->prompt()->chat(promptName: 'chatName')->compile(params: ['key' => 'value']); $langfuse->prompt()->list(); $langfuse->prompt()->create(promptName: 'promptName', prompt: 'text', type: PromptType::TEXT);
Ingestion
use DIJ\Langfuse\PHP; // 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 PHP was created by Tycho Engberink and is maintained by DIJ Digital under the MIT license.