PHPackages                             dij-digital/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. [Localization &amp; i18n](/categories/localization)
4. /
5. dij-digital/langfuse-php

ActiveLibrary[Localization &amp; i18n](/categories/localization)

dij-digital/langfuse-php
========================

A langfuse wrapper for PHP

v0.2.0(2mo ago)93.2k↓30%1[13 PRs](https://github.com/DIJ-digital/langfuse-php/pulls)1MITPHPPHP ^8.3|^8.4CI passing

Since Jun 30Pushed 2mo agoCompare

[ Source](https://github.com/DIJ-digital/langfuse-php)[ Packagist](https://packagist.org/packages/dij-digital/langfuse-php)[ RSS](/packages/dij-digital-langfuse-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (26)Used By (1)

Langfuse PHP - A PHP Client for Langfuse API
--------------------------------------------

[](#langfuse-php---a-php-client-for-langfuse-api)

This package provides a wrapper around the [Langfuse](https://langfuse.com) API, allowing you to easily integrate Langfuse into your PHP applications. It uses as few dependencies as possible.

### This package supports the following features:

[](#this-package-supports-the-following-features)

#### Prompts

[](#prompts)

- Get text prompts
- Get chat prompts
- Compile text prompts
- Compile chat prompts
- Create text prompts
- Create chat prompts
- List prompts (auto-paginated)
- Update prompt labels
- Fallback handling for prompt fetching errors
- Fallback handling when no prompt is found

#### Ingestion

[](#ingestion)

- Create and update traces
- Create and update spans (with nesting)
- Create and update generations
- Automatic `traceId` and `parentObservationId` threading
- Sends directly to the [Langfuse v2 ingestion API](https://api.reference.langfuse.com/#POST/api/public/ingestion)

#### Scores

[](#scores)

- Create scores
- Get scores
- List scores
- Delete scores
- V2 API support for scores

> **Requires [PHP 8.3](https://php.net/releases/) or [PHP 8.4](https://php.net/releases/)**

Install the package using **Composer**:

```
composer require dij-digital/langfuse-php
```

### How to use this package

[](#how-to-use-this-package)

#### Setup

[](#setup)

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

$langfuse = new Langfuse(
    transporter: new HttpTransporter(new Client([
        'base_uri' => 'https://cloud.langfuse.com',
        'auth' => ['PUBLIC_KEY', 'SECRET_KEY'],
    ])),
    environment: 'production', // optional, defaults to 'default'
);
```

#### Prompts

[](#prompts-1)

```
// Get and compile prompts
$langfuse->prompt()->text(promptName: 'promptName')->compile(params: ['key' => 'value']);
$langfuse->prompt()->chat(promptName: 'chatName')->compile(params: ['key' => 'value']);

// List all prompts (returns a Generator that auto-paginates)
foreach ($langfuse->prompt()->list() as $prompt) {
    echo $prompt->name;
}

// Create a prompt
$langfuse->prompt()->create(promptName: 'promptName', prompt: 'text', type: PromptType::TEXT);

// Update prompt labels
$langfuse->prompt()->update(promptName: 'promptName', version: 1, labels: ['production']);
```

#### Ingestion

[](#ingestion-1)

Every call to `trace()`, `span()`, or `generation()` immediately sends a request to the Langfuse ingestion API. No buffering, no flushing required.

```
$ingestion = $langfuse->ingestion();
```

##### Trace

[](#trace)

A trace is the root of an observation tree.

```
$trace = $ingestion->trace(
    name: 'my-workflow',
    userId: 'user-456',
    input: 'user question',
);

// Update the trace (sends immediately)
$trace->update(
    output: 'final answer',
    metadata: ['duration_ms' => 1234],
);
```

##### Span

[](#span)

Spans group related work within a trace. Create them from a `Trace` or another `Span` -- `traceId` and `parentObservationId` are set automatically.

```
// Create a span from the trace
$span = $trace->span(name: 'web-search-batch');

// Nest a child span under the parent span
$childSpan = $span->span(name: 'single-search');

// Update spans when work is done
$childSpan->update(output: ['results' => 3], endTime: date('c'));
$span->update(output: ['total' => 3], endTime: date('c'));
```

##### Generation

[](#generation)

Generations represent LLM calls. Create them from a `Trace` or `Span` -- context IDs are threaded automatically.

```
// Generation on a trace
$gen = $trace->generation(
    input: ['messages' => [['role' => 'user', 'content' => 'Hello']]],
    output: 'Hi there!',
    name: 'llm-call',
    model: 'gpt-4o',
    modelParameters: ['temperature' => 0.7],
    promptName: 'my-prompt',
    promptVersion: 1,
);

// Generation nested under a span
$gen = $span->generation(
    input: 'summarize this',
    output: 'summary text',
    name: 'summarize-call',
    model: 'gpt-4o',
);

// Update a generation after the LLM responds
$gen->update(
    output: 'updated response',
    metadata: ['tokens' => 150],
);
```

##### Full example

[](#full-example)

```
$ingestion = $langfuse->ingestion();

$trace = $ingestion->trace(
    name: 'handle-request',
    userId: 'user-789',
    input: 'What is the weather?',
);

$span = $trace->span(name: 'search-batch');

    $child = $span->span(name: 'weather-api-call');
    $child->update(output: ['temp' => 22], endTime: date('c'));

    $span->generation(
        input: 'Summarize weather data',
        output: 'It is 22 degrees and sunny.',
        name: 'summarize',
        model: 'gpt-4o',
    );

$span->update(output: ['answer' => 'It is 22 degrees.'], endTime: date('c'));
$trace->update(output: 'It is 22 degrees and sunny.');
```

#### Scores

[](#scores-1)

```
use DIJ\Langfuse\PHP;
use DIJ\Langfuse\PHP\Enums\ScoreDataType;

// Create a score
$score = $langfuse->score()->create(
    traceId: 'trace-id-123',
    name: 'accuracy',
    value: 0.95,
    dataType: ScoreDataType::NUMERIC,
    comment: 'High accuracy score'
);

// Get a specific score (using v2 API)
$score = $langfuse->score()->get('score-id-123');

// List scores with filters (using v2 API)
$scores = $langfuse->score()->list(
    traceId: 'trace-id-123',
    dataType: ScoreDataType::NUMERIC,
    limit: 10
);

// Delete a score
$langfuse->score()->delete('score-id-123');
```

### Architecture

[](#architecture)

```
Langfuse(transporter, environment?)
├── prompt()                → Prompt
│                                 ├── text()     → TextPromptResponse|FallbackPrompt
│                                 ├── chat()     → ChatPromptResponse|FallbackPrompt
│                                 ├── list()     → Generator
│                                 ├── create()   → TextPromptResponse|ChatPromptResponse
│                                 └── update()   → TextPromptResponse|ChatPromptResponse
├── ingestion()             → Ingestion
│                             ├── trace()      → Trace
│                             │                   ├── update()
│                             │                   ├── span()       → Span
│                             │                   └── generation() → Generation
│                             ├── span()       → Span
│                             │                   ├── update()
│                             │                   ├── span()       → Span
│                             │                   └── generation() → Generation
│                             └── generation() → Generation
│                                                 └── update()
└── score()                 → Score
                              ├── create()
                              ├── get()
                              ├── list()
                              └── delete()

```

Each `trace()`, `span()`, `generation()`, and `update()` call sends a request to the Langfuse `POST /api/public/ingestion` endpoint immediately. **Langfuse PHP** was created by **[Tycho Engberink](https://github.com/tychoengberinkDIJ)** and is maintained by **[DIJ Digital](https://dij.digital)** under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance83

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.1% 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 ~58 days

Total

5

Last Release

89d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ab892324187874b808c0bd037ff12f74fcb3257f0cf8d9723bbd30768d482ac?d=identicon)[DIJ](/maintainers/DIJ)

---

Top Contributors

[![tychoengberinkDIJ](https://avatars.githubusercontent.com/u/122891499?v=4)](https://github.com/tychoengberinkDIJ "tychoengberinkDIJ (90 commits)")[![jesse-bos](https://avatars.githubusercontent.com/u/131663982?v=4)](https://github.com/jesse-bos "jesse-bos (10 commits)")[![jesse-bos-dij](https://avatars.githubusercontent.com/u/169130613?v=4)](https://github.com/jesse-bos-dij "jesse-bos-dij (7 commits)")

---

Tags

phplangfuse

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[stichoza/google-translate-php

Free Google Translate API PHP Package

2.0k7.6M124](/packages/stichoza-google-translate-php)[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[pharaonic/laravel-locations

Laravel - Countries\[States/Cities, Currency, Phone Code, Languages, Capital\] &amp; Continents &amp; Timezones.

102.4k1](/packages/pharaonic-laravel-locations)

PHPackages © 2026

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