Skip to main content

Tracing MLflow AI Gateway

MLflow AI Gateway is a unified, centralized interface for accessing multiple LLM providers. It simplifies API key management, provides a consistent API across providers, and enables seamless switching between models from OpenAI, Anthropic, Google, and other providers.

Since MLflow AI Gateway exposes an OpenAI-compatible API, you can use MLflow's automatic tracing integrations to capture detailed traces of your LLM interactions.

MLflow AI Gateway Tracing

Integration Options

There are two ways to trace LLM calls through MLflow AI Gateway:

ApproachDescriptionBest For
Server-side Tracing (Coming Soon)Gateway automatically logs all requestsCentralized tracing for all requests through the gateway
Client-side TracingUse OpenAI SDK with MLflow autologCombining LLM traces with your agent or application traces
Coming Soon

Server-side tracing for MLflow AI Gateway is not available yet. Stay tuned for updates!

Prerequisite

Start MLflow Server with AI Gateway

To start MLflow server with AI Gateway, you need to install the mlflow[genai] package.

bash
pip install mlflow[genai]

Then start the MLflow server as usual, no additional configuration is needed.

bash
mlflow server

Create Endpoint

Create an endpoint in MLflow AI Gateway to route requests to your LLM provider. See the AI Gateway Quickstart for detailed setup instructions.

Query Gateway

You can trace LLM calls through MLflow AI Gateway using any of the following approaches:

Since MLflow AI Gateway exposes an OpenAI-compatible API, you can use MLflow's OpenAI automatic tracing integration to trace calls.

python
import mlflow
from openai import OpenAI

# Enable auto-tracing for OpenAI
mlflow.openai.autolog()

# Set MLflow tracking URI and experiment
mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("MLflow AI Gateway")

# Point OpenAI client to MLflow AI Gateway
client = OpenAI(
base_url="http://localhost:5000/gateway/openai/v1",
api_key="dummy", # API key not needed, configured server-side
)

response = client.chat.completions.create(
model="my-endpoint", messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

View Traces in MLflow UI

Open the MLflow UI at http://localhost:5000 (or your custom MLflow server URL) to see the traces from your MLflow AI Gateway calls.

Next Steps