Langfuse
Using OneRouter with Langfuse
Langfuse provides observability and analytics for LLM applications. Since OneRouter uses the OpenAI API schema, you can utilize Langfuse's native integration with the OpenAI SDK to automatically trace and monitor your OneRouter API calls.
Installation
pip install langfuse openaiConfiguration
Set up your environment variables:
import os
# Set your Langfuse API keys
LANGFUSE_SECRET_KEY="sk-lf-..."
LANGFUSE_PUBLIC_KEY="pk-lf-..."
# EU region
LANGFUSE_HOST="https://cloud.langfuse.com"
# US region
# LANGFUSE_HOST="https://us.cloud.langfuse.com"
# Set your OneRouter API key
os.environ["OPENAI_API_KEY"] = "${API_KEY}"Simple LLM Call
Since OneRouter provides an OpenAI-compatible API, you can use the Langfuse OpenAI SDK wrapper to automatically log OneRouter calls as generations in Langfuse:
Advanced Tracing with Nested Calls
Use the @observe() decorator to capture execution details of functions with nested LLM calls:
Last updated