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 TracingGateway automatically logs all requests when usage tracking is enabledCentralized tracing for all requests through the gateway
Client-side TracingUse OpenAI SDK with MLflow autologCombining LLM traces with your agent or application traces

When both are used together with a traceparent header, the gateway creates a linked span under the agent's trace for end-to-end visibility. See Distributed Tracing for details.

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