PHPackages                             mtyrtov/langfuse-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mtyrtov/langfuse-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mtyrtov/langfuse-php
====================

Langfuse SDK

v0.0.4(1y ago)2138[1 PRs](https://github.com/mtyrtov/langfuse-php/pulls)MITPHPPHP &gt;=8.1

Since May 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mtyrtov/langfuse-php)[ Packagist](https://packagist.org/packages/mtyrtov/langfuse-php)[ RSS](/packages/mtyrtov-langfuse-php/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (7)Versions (6)Used By (0)

Langfuse PHP SDK
================

[](#langfuse-php-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/afb7e9c152c575febdfcf97478189eafadbc8c51673cffba8e6cc49946f16ada/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d747972746f762f6c616e67667573652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mtyrtov/langfuse-php)[![Total Downloads](https://camo.githubusercontent.com/1b54b18ba91c567b2b1f75a1a580dfb33baedd9c023c8b42c502d309b244cc20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d747972746f762f6c616e67667573652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mtyrtov/langfuse-php)[![PHP Version Require](https://camo.githubusercontent.com/5cd817fd2289814379fef15672a784130f2ba4ad1042cd891c9be4376c85b30f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d747972746f762f6c616e67667573652d7068703f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mtyrtov/langfuse-php)[![License](https://camo.githubusercontent.com/3a0e5203ae6cf2de7e8d79a9ee9399363c825f4cba7dc7f6e6a7755095ee1475/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d747972746f762f6c616e67667573652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mtyrtov/langfuse-php)

A PHP SDK for interacting with the Langfuse API. This package provides tools for tracing, scores, annotation queues, dataset runs and prompt management to enable comprehensive LLM observability.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1

Installation
------------

[](#installation)

```
composer require mtyrtov/langfuse-php:dev-master
```

Quick Start
-----------

[](#quick-start)

```
use Langfuse\LangfuseClient;
use Langfuse\LangfuseProfiler;

require_once "vendor/autoload.php";

# Initialize the client
$client = new LangfuseClient(
    'your-public-key',
    'your-secret-key',
    'https://your-langfuse-host.com' # Optional, defaults to http://127.0.0.1:3000
);

$profiler = new LangfuseProfiler($client);
```

Core Features
-------------

[](#core-features)

### Tracing

[](#tracing)

Traces represent full user sessions or requests in your application.

```
# Create a trace
$trace = $profiler->trace('user-query')
    ->setSessionId() // Automatically generates a session ID
    ->setUserId('user-123');

# Set input and output
$trace->setInput('Hello, how are you?');
$trace->setOutput("I'm fine, thank you!");
```

### Spans

[](#spans)

Spans represent logical sections within a trace, such as specific processing steps.

```
# Create a span within a trace
$classificationSpan = $trace->span('classification');

# End the span when the operation is complete
$classificationSpan->end();
```

### Generations

[](#generations)

Generations track individual LLM calls and their results.

```
# Create a generation within a span
$generation = $classificationSpan->generation('model-call')
    ->withModel('gpt-4.1-mini')
    ->withModelParameters(['temperature' => 0])
    ->setInput(['role' => 'user', 'content' => 'Hello there'])
    ->setOutput('AI response here');
```

### Flushing Data

[](#flushing-data)

Ensure all data is sent to Langfuse before your application terminates.

```
$result = $profiler->flush();
```

Laravel
-------

[](#laravel)

```
class LangfuseProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(LangfuseClient::class, function ($app) {
            return new LangfuseClient(
                # Your variables from .env
                config('services.langfuse.public_key'),
                config('services.langfuse.secret_key'),
                config('services.langfuse.base_uri')
            );
        });

        $this->app->singleton(LangfuseProfiler::class, function ($app) {
            return new LangfuseProfiler($app->make(LangfuseClient::class));
        });
    }

    public function boot(): void
    {
        //
    }
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Working with Multiple Generations

[](#working-with-multiple-generations)

```
# Create multiple generations within a span
$generation1 = $trace->span('classification')->generation('generation-1')
    ->setModel('gpt-4.1-mini')
    ->setModelParameters(['temperature' => 0.5])
    ->setPrompt($prompt)
    ->setInput($messages)
    ->setOutput('RESULT_1');

$generation2 = $trace->span('classification')->generation('generation-2')
    ->setModel('gpt-4.1-nano')
    ->setModelParameters(['temperature' => 0])
    ->setPrompt($prompt)
    ->setInput($messages)
    ->setOutput('RESULT_2');
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance48

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

4

Last Release

386d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17882fa8931f8682aa359e598fded0e7840b9abbc0e1ba9ee91759c809a14055?d=identicon)[mtyrtov](/maintainers/mtyrtov)

---

Top Contributors

[![mtyrtov](https://avatars.githubusercontent.com/u/39631083?v=4)](https://github.com/mtyrtov "mtyrtov (16 commits)")

---

Tags

ailangfusellmphpsdk

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mtyrtov-langfuse-php/health.svg)

```
[![Health](https://phpackages.com/badges/mtyrtov-langfuse-php/health.svg)](https://phpackages.com/packages/mtyrtov-langfuse-php)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[shetabit/multipay

PHP Payment Gateway Integration Package

293361.0k4](/packages/shetabit-multipay)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

5.1k5.2k](/packages/shlinkio-shlink)[firefly-iii/data-importer

Firefly III Data Import Tool.

8045.8k](/packages/firefly-iii-data-importer)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
