Langfuse
Langfuse provides observability and analytics for LLM applications. Since SIRAYA Model Router uses the OpenAI API schema, you can utilize Langfuse's native integration with the OpenAI SDK to automatically trace and monitor your SIRAYA Model Router API calls.
Installation
Configuration
Set up your environment variables. The Langfuse SDK and the OpenAI client read them from the process environment:
# Your Langfuse API keys
export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_PUBLIC_KEY="pk-lf-..."
# EU region
export LANGFUSE_BASE_URL="https://cloud.langfuse.com"
# US region
# export LANGFUSE_BASE_URL="https://us.cloud.langfuse.com"
# Your SIRAYA Model Router API key (read by the OpenAI client)
export OPENAI_API_KEY="<API_KEY>"
Simple LLM Call
Since SIRAYA Model Router provides an OpenAI-compatible API, you can use the Langfuse OpenAI SDK wrapper to automatically log SIRAYA Model Router calls as generations in Langfuse:
# Import the Langfuse OpenAI SDK wrapper
from langfuse.openai import openai
# Create an OpenAI client with SIRAYA Model Router's base URL
client = openai.OpenAI(
base_url="https://llm.siraya.ai/v1"
)
# Make a chat completion request
response = client.chat.completions.create(
model="gpt-5.4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a fun fact about space."}
],
name="fun-fact-request" # Optional: Name of the generation in Langfuse
)
# Print the assistant's reply
print(response.choices[0].message.content)
Advanced Tracing with Nested Calls
Use the @observe() decorator to capture execution details of functions with nested LLM calls:
from langfuse import observe
from langfuse.openai import openai
# Create an OpenAI client with SIRAYA Model Router's base URL
client = openai.OpenAI(
base_url="https://llm.siraya.ai/v1",
)
@observe() # This decorator enables tracing of the function
def analyze_text(text: str):
# First LLM call: Summarize the text
summary_response = summarize_text(text)
summary = summary_response.choices[0].message.content
# Second LLM call: Analyze the sentiment of the summary
sentiment_response = analyze_sentiment(summary)
sentiment = sentiment_response.choices[0].message.content
return {
"summary": summary,
"sentiment": sentiment
}
@observe() # Nested function to be traced
def summarize_text(text: str):
return client.chat.completions.create(
model="gpt-5.4",
messages=[
{"role": "system", "content": "You summarize texts in a concise manner."},
{"role": "user", "content": f"Summarize the following text:\n{text}"}
],
name="summarize-text"
)
@observe() # Nested function to be traced
def analyze_sentiment(summary: str):
return client.chat.completions.create(
model="gpt-5.4",
messages=[
{"role": "system", "content": "You analyze the sentiment of texts."},
{"role": "user", "content": f"Analyze the sentiment of the following summary:\n{summary}"}
],
name="analyze-sentiment"
)
# Example usage
text_to_analyze = "SIRAYA Model Router's unified API has significantly advanced the field of AI development, setting new standards for model accessibility."
result = analyze_text(text_to_analyze)
print(result)