diff --git a/content/integrations/gateways/daoxe.mdx b/content/integrations/gateways/daoxe.mdx new file mode 100644 index 000000000..2e0ce799a --- /dev/null +++ b/content/integrations/gateways/daoxe.mdx @@ -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"] = "" +``` + +## 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"; + + diff --git a/content/integrations/gateways/meta.json b/content/integrations/gateways/meta.json index ef8f656a0..9f9d3dcb9 100644 --- a/content/integrations/gateways/meta.json +++ b/content/integrations/gateways/meta.json @@ -2,6 +2,7 @@ "title": "Gateways", "pages": [ "anannas", + "daoxe", "helicone", "kong-ai-plugin", "litellm", diff --git a/public/images/integrations/daoxe_icon.png b/public/images/integrations/daoxe_icon.png new file mode 100644 index 000000000..851556f62 Binary files /dev/null and b/public/images/integrations/daoxe_icon.png differ