PHPackages                             dayemsiddiqui/langfuse-sdk - 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. dayemsiddiqui/langfuse-sdk

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

dayemsiddiqui/langfuse-sdk
==========================

Laravel Langfuse SDK

v1.1.0(12mo ago)0717[4 PRs](https://github.com/dayemsiddiqui/langfuse-sdk/pulls)MITPHPPHP ^8.2CI passing

Since Jul 7Pushed 2mo agoCompare

[ Source](https://github.com/dayemsiddiqui/langfuse-sdk)[ Packagist](https://packagist.org/packages/dayemsiddiqui/langfuse-sdk)[ Docs](https://github.com/dayemsiddiqui/langfuse-sdk)[ GitHub Sponsors]()[ RSS](/packages/dayemsiddiqui-langfuse-sdk/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (13)Versions (8)Used By (0)

Laravel Langfuse SDK
====================

[](#laravel-langfuse-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ea96f314e9de8737c929ea236eb4bd57a989320069bb03e3eeff475f1fd1b0ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646179656d73696464697175692f6c616e67667573652d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dayemsiddiqui/langfuse-sdk)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0c90894fd31b0c6ce7d00c4595f37491eff450a1400cecfa3e72ce183f08aae7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646179656d73696464697175692f6c616e67667573652d73646b2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/dayemsiddiqui/langfuse-sdk/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/5e1ca6ebb8aff4c7f279240d7af19bb4ceab61fb36804de724d37be7621e2a3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646179656d73696464697175692f6c616e67667573652d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dayemsiddiqui/langfuse-sdk)

A simple Laravel package for working with [Langfuse](https://langfuse.com) prompts. Fetch, compile, and test AI prompts with ease.

---

🚀 Quick Start
-------------

[](#-quick-start)

1. **Install:**

```
composer require dayemsiddiqui/langfuse-sdk
```

2. **Add your API keys to `.env**:

```
LANGFUSE_PUBLIC_KEY=your_public_key_here
LANGFUSE_SECRET_KEY=your_secret_key_here
LANGFUSE_HOST=https://cloud.langfuse.com
```

3. **Use in your code:**

```
use dayemsiddiqui\Langfuse\Langfuse;

$langfuse = new Langfuse();

// Get a raw prompt
echo $langfuse->getPrompt('welcome')->raw();

// Compile a prompt with variables
echo $langfuse->getPrompt('greeting')->compile(['name' => 'Alice']);
```

---

✨ Features
----------

[](#-features)

- **Fetch prompts** from Langfuse by name
- **Compile prompts** with variables (e.g. `{{name}}`)
- **Detailed error messages** for missing variables
- **Elegant testing** with `LangfuseFake::fake()` (see below)

---

🧑‍💻 Usage
---------

[](#‍-usage)

### Get a Prompt

[](#get-a-prompt)

```
$prompt = $langfuse->getPrompt('welcome')->raw();
// "Hello {{name}}"
```

### Compile a Prompt

[](#compile-a-prompt)

```
$compiled = $langfuse->getPrompt('greeting')->compile(['name' => 'Alice']);
// "Hello Alice!"
```

### Handle Missing Variables

[](#handle-missing-variables)

If you try to compile a prompt and dont provide all the required variables in a prompt you will get a MissingPromptVariablesException

```
try {
    $langfuse->getPrompt('profile')->compile(['name' => 'John']);
} catch (\dayemsiddiqui\Langfuse\Exceptions\MissingPromptVariablesException $e) {
    echo $e->getMessage();
}
```

---

🧪 Testing (Just like Queue::fake())
-----------------------------------

[](#-testing-just-like-queuefake)

Testing your code is easy and elegant!

### 1. Fake Langfuse in your tests

[](#1-fake-langfuse-in-your-tests)

```
use dayemsiddiqui\Langfuse\Testing\LangfuseFake;
use dayemsiddiqui\Langfuse\Langfuse;

LangfuseFake::fake([
    'greeting' => 'Hello {{name}}!',
    'farewell' => 'Goodbye {{name}}!'
]);

$langfuse = app(Langfuse::class);

// This will use the fake prompt, no HTTP requests!
echo $langfuse->getPrompt('greeting')->compile(['name' => 'Test']); // "Hello Test!"
```

### 2. Make assertions

[](#2-make-assertions)

```
LangfuseFake::getFake()->assertPromptRequested('greeting');
LangfuseFake::getFake()->assertPromptRequestedTimes('greeting', 1);
LangfuseFake::getFake()->assertNoPromptsRequested();
```

### 3. Chainable API

[](#3-chainable-api)

```
LangfuseFake::fake()
    ->addPrompt('foo', 'Foo {{bar}}')
    ->addPrompt('baz', 'Baz {{qux}}')
    ->throwOnMissing();
```

### 4. Use the trait for auto-setup

[](#4-use-the-trait-for-auto-setup)

```
use dayemsiddiqui\Langfuse\Testing\WithLangfuseFake;

uses(WithLangfuseFake::class);

it('fakes prompts', function () {
    $fake = $this->getLangfuseFake();
    $fake->addPrompt('test', 'Test prompt');
    $langfuse = app(Langfuse::class);
    expect($langfuse->getPrompt('test')->raw())->toBe('Test prompt');
});
```

---

📚 API Reference (Short)
-----------------------

[](#-api-reference-short)

- `getPrompt($name)` → returns a PromptBuilder
- `PromptBuilder->raw()` → get raw prompt
- `PromptBuilder->compile($vars)` → compile with variables
- `LangfuseFake::fake([...])` → fake prompts in tests
- `LangfuseFake::getFake()->assertPromptRequested($name)` → assert prompt was used

---

📝 Advanced
----------

[](#-advanced)

- **Dependency Injection:** Works with Laravel's container, so you can type-hint `Langfuse` in your services.
- **Custom Exception:** Get missing variables, provided variables, prompt name/content from the exception.
- **Supports both `{{name}}` and `{{ name }}` syntax.**

---

🛠️ Development
--------------

[](#️-development)

- Run tests: `composer run test`
- Format code: `composer format`
- Static analysis: `composer analyse`

---

🤝 Contributing &amp; License
----------------------------

[](#-contributing--license)

- PRs welcome! See [CONTRIBUTING](CONTRIBUTING.md).
- MIT License. See [LICENSE.md](LICENSE.md).

---

🙏 Credits
---------

[](#-credits)

- [Dayem Siddiqui](https://github.com/dayemsiddiqui)
- [All Contributors](../../contributors)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance70

Regular maintenance activity

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~0 days

Total

2

Last Release

362d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a37dcf1a991bcf0e1fbb1936f94b6dbf22477b6f4532466042a666889d8bacfa?d=identicon)[dayemsiddiqui](/maintainers/dayemsiddiqui)

---

Top Contributors

[![dayemsiddiqui](https://avatars.githubusercontent.com/u/9693176?v=4)](https://github.com/dayemsiddiqui "dayemsiddiqui (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

laravellangfuse sdkDayem Siddiqui

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/dayemsiddiqui-langfuse-sdk/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M101](/packages/dedoc-scramble)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[elegantly/laravel-translator

All on one translations management for Laravel

6333.1k](/packages/elegantly-laravel-translator)

PHPackages © 2026

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