Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions content/integrations/gateways/daoxe.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
title: "Trace DaoXE with Langfuse"
sidebarTitle: DaoXE
logo: /images/integrations/daoxe_icon.png
description: "Learn how to integrate Langfuse with DaoXE using the OpenAI SDK drop-in."
---

# DaoXE Integration

In this guide, we'll show you how to integrate [Langfuse](/) with [DaoXE](https://daoxe.com).

> **What is DaoXE?** [DaoXE](https://daoxe.com) is a multi-model, multi-protocol API gateway. It exposes OpenAI-compatible Chat Completions and Responses endpoints, Anthropic Messages (Claude protocol) paths, and image-compatible endpoints where available, so apps can route multiple providers through one account without rewriting client code.

> **What is Langfuse?** [Langfuse](/) is an open source AI engineering platform that helps teams trace LLM calls, monitor performance, and debug issues in their AI applications.

Since DaoXE's Chat Completions surface uses the OpenAI API schema, we can utilize Langfuse's native integration with the OpenAI SDK, available in both [Python](/integrations/model-providers/openai-py) and [TypeScript](/integrations/model-providers/openai-js).

## Get started

```bash
pip install langfuse openai
```

```python
import os

# Set your Langfuse API keys
LANGFUSE_SECRET_KEY = "sk-lf-..."
LANGFUSE_PUBLIC_KEY = "pk-lf-..."
# 🇪🇺 EU region
LANGFUSE_BASE_URL = "https://cloud.langfuse.com"
# Other Langfuse data regions include 🇺🇸 US: https://us.cloud.langfuse.com, 🇯🇵 Japan: https://jp.cloud.langfuse.com and ⚕️ HIPAA: https://hipaa.cloud.langfuse.com

# Set your DaoXE API key
os.environ["DAOXE_API_KEY"] = "<YOUR_DAOXE_API_KEY>"
```

## Example 1: Simple LLM Call

Since DaoXE provides an OpenAI-compatible Chat Completions API, we can use the [Langfuse OpenAI SDK wrapper](/integrations/model-providers/openai-py) to automatically log DaoXE calls as generations in Langfuse.

- The `base_url` is set to DaoXE's OpenAI-compatible endpoint: `https://daoxe.com/v1`.
- Replace `"YOUR_ACCOUNT_MODEL_ID"` with a model ID from your DaoXE account catalog (IDs are account-scoped; do not hardcode a public model list).
- The API key is read from the `DAOXE_API_KEY` environment variable.

```python
# Import the Langfuse OpenAI SDK wrapper
from langfuse.openai import openai

# Create an OpenAI client with DaoXE's base URL
client = openai.OpenAI(
api_key=os.environ["DAOXE_API_KEY"],
base_url="https://daoxe.com/v1",
)

# Make a chat completion request
response = client.chat.completions.create(
model="YOUR_ACCOUNT_MODEL_ID",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a fun fact about API gateways."},
],
name="daoxe-fun-fact-request", # Optional: Name of the generation in Langfuse
)

# Print the assistant's reply
print(response.choices[0].message.content)
```

## Example 2: Nested LLM Calls

By using the `@observe()` decorator, we can capture execution details of any Python function, including nested LLM calls, inputs, outputs, and execution times. This provides in-depth observability with minimal code changes.

- The `@observe()` decorator captures inputs, outputs, and execution details of the functions.
- Nested functions `summarize_text` and `analyze_sentiment` are also decorated, creating a hierarchy of traces.
- Each LLM call within the functions is logged, providing a detailed trace of the execution flow.

```python
from langfuse import observe
from langfuse.openai import openai

# Create an OpenAI client with DaoXE's base URL
client = openai.OpenAI(
api_key=os.environ["DAOXE_API_KEY"],
base_url="https://daoxe.com/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="YOUR_ACCOUNT_MODEL_ID",
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="YOUR_ACCOUNT_MODEL_ID",
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 = (
"Multi-protocol API gateways let teams keep one client shape while comparing "
"providers on quality, latency, and cost."
)
analyze_text(text_to_analyze)
```

## Multi-protocol note

This page traces DaoXE through the **OpenAI Chat Completions** path because that is what the Langfuse OpenAI SDK wrapper instruments.

DaoXE also exposes other protocol surfaces for non-OpenAI clients (for example OpenAI Responses and Anthropic Messages / Claude protocol). Those paths can still be observed in Langfuse via the [Python SDK](/docs/observability/get-started) or [OpenTelemetry](/integrations/native/opentelemetry) if your application emits spans around those calls.

## Availability

DaoXE is **not available in mainland China**. Use the current account catalog and pricing page for live model IDs and availability.

## Disclosure

This integration page was contributed by a DaoXE maintainer. Examples repository: [seven7763/DaoXE-AI](https://github.com/seven7763/DaoXE-AI).

import LearnMore from "@/components-mdx/integration-learn-more.mdx";

<LearnMore />
1 change: 1 addition & 0 deletions content/integrations/gateways/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"title": "Gateways",
"pages": [
"anannas",
"daoxe",
"helicone",
"kong-ai-plugin",
"litellm",
Expand Down
Binary file added public/images/integrations/daoxe_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.