Download the PHP package uodev/langfuse-logger without Composer
On this page you can find all versions of the php package uodev/langfuse-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download uodev/langfuse-logger
More information about uodev/langfuse-logger
Files in uodev/langfuse-logger
Package langfuse-logger
Short Description A lightweight PHP logger for Langfuse to track LLM API calls (OpenAI, Claude, Gemini, Grok) with token usage analytics
License MIT
Homepage https://github.com/uodev/langfuse-logger-php
Informations about the package langfuse-logger
Langfuse Logger for PHP
A lightweight PHP library to log your LLM API calls to Langfuse for observability and analytics.
Supported Providers
| Provider | Class | Models |
|---|---|---|
| OpenAI | OpenAIProvider |
GPT-4, GPT-4o, o1, o3-mini, etc. |
| Anthropic | AnthropicProvider |
Claude 3.5 Sonnet, Claude 3 Opus, etc. |
GoogleProvider |
Gemini 1.5 Pro, Gemini 2.0, etc. | |
| xAI | XAIProvider |
Grok-2, Grok-2 mini, etc. |
Installation
Quick Start
Provider Examples
OpenAI
Anthropic (Claude)
Google (Gemini)
xAI (Grok)
Requirements
- PHP >= 7.4
- ext-curl
- ext-json
Features
- Multi-Provider Support: OpenAI, Anthropic, Google, xAI out of the box
- Token Parsing: Automatically parses cached input tokens and reasoning tokens
- Cost Tracking: Reports real input (non-cached) and cached input separately
- Extensible: Implement
ProviderInterfaceto add custom providers - Type Safe: Strict types and interfaces throughout
Configuration
Get your Langfuse credentials from Langfuse Cloud or your self-hosted instance.
| Parameter | Description |
|---|---|
baseUrl |
Langfuse API URL (e.g., https://cloud.langfuse.com) |
publicKey |
Your Langfuse public key (pk-lf-...) |
secretKey |
Your Langfuse secret key (sk-lf-...) |
Custom Provider
Implement the ProviderInterface to add support for other LLM providers:
Full Example
See the example.php file for complete working examples.
API Reference
LangfuseLogger
setUserId($userId): self
Set the user ID for tracking. Returns self for method chaining.
setSessionId($sessionId): self
Set the session ID for grouping related traces. Returns self for method chaining.
log(ProviderInterface $provider, string $model, array $messages, array $response, array $metadata = []): bool
Log an LLM API call to Langfuse.
| Parameter | Type | Description |
|---|---|---|
$provider |
ProviderInterface | Provider instance (e.g., new OpenAIProvider()) |
$model |
string | Model name (e.g., gpt-4o, claude-3-5-sonnet) |
$messages |
array | The messages array sent to the API |
$response |
array | The decoded response from the API |
$metadata |
array | Optional additional metadata |
Returns true on success, false on failure.
License
MIT License - see the LICENSE file for details.
Development
Contributing
Contributions are welcome! Please make sure tests pass before submitting a Pull Request.
Links
All versions of langfuse-logger with dependencies
ext-curl Version *
ext-json Version *