Webhooks
- This feature is still experimental and may change in future releases.
- The file backend doesn't support webhooks. Only the SQL backend supports webhooks.
- Only OSS MLflow supports webhooks. Databricks or other managed MLflow services may not support this feature.
Overview
MLflow webhooks enable real-time notifications when specific events occur in the Model Registry. When you register a model, create a new version, or modify tags and aliases, MLflow can automatically send HTTP POST requests to your specified endpoints. This enables seamless integration with CI/CD pipelines, notification systems, and other external services.
Key Features
- Real-time notifications for Model Registry events
- HMAC signature verification for secure webhook delivery
- Multiple event types including model creation, versioning, and tagging
- Built-in testing to verify webhook connectivity
Supported Events
MLflow webhooks support the following Model Registry events:
Event | Description | Payload Schema |
---|---|---|
registered_model.created | Triggered when a new registered model is created | RegisteredModelCreatedPayload |
model_version.created | Triggered when a new model version is created | ModelVersionCreatedPayload |
model_version_tag.set | Triggered when a tag is set on a model version | ModelVersionTagSetPayload |
model_version_tag.deleted | Triggered when a tag is deleted from a model version | ModelVersionTagDeletedPayload |
model_version_alias.created | Triggered when an alias is created for a model version | ModelVersionAliasCreatedPayload |
model_version_alias.deleted | Triggered when an alias is deleted from a model version | ModelVersionAliasDeletedPayload |
Quick Start
Creating a Webhook
from mlflow import MlflowClient
client = MlflowClient()
# Create a webhook for model version creation events
webhook = client.create_webhook(
name="model-version-notifier",
url="https://your-app.com/webhook",
events=["model_version.created"],
description="Notifies when new model versions are created",
secret="your-secret-key", # Optional: for HMAC signature verification
)
print(f"Created webhook: {webhook.webhook_id}")
Testing a Webhook
Before putting your webhook into production, test it with example payloads using MlflowClient.test_webhook()
:
# Test the webhook with an example payload
result = client.test_webhook(webhook.webhook_id)
if result.success:
print(f"Webhook test successful! Status code: {result.response_status}")
else:
print(f"Webhook test failed. Status: {result.response_status}")
if result.error_message:
print(f"Error: {result.error_message}")
You can also test specific event types:
# Test with a specific event type
result = client.test_webhook(webhook.webhook_id, event="model_version.created")
When you call test_webhook()
, MLflow sends example payloads to your webhook URL. These test payloads have the same structure as real event payloads. Click on the payload schema links in the table above to see the exact structure and examples for each event type.
Testing Multi-Event Webhooks
If your webhook is subscribed to multiple events, test_webhook()
behavior depends on whether you specify an event:
- Without specifying an event: MLflow uses the first event from the webhook's event list
- With a specific event: MLflow uses the specified event (must be in the webhook's event list)
# Create webhook with multiple events
webhook = client.create_webhook(
name="multi-event-webhook",
url="https://your-domain.com/webhook",
events=[
"registered_model.created",
"model_version.created",
"model_version_tag.set",
],
secret="your-secret-key",
)
# Test with first event (registered_model.created)
result = client.test_webhook(webhook.webhook_id)
# Test with specific event
result = client.test_webhook(
webhook.webhook_id,
event=("model_version_tag.set"),
)
Webhook Management
Listing Webhooks
Use MlflowClient.list_webhooks()
to retrieve webhooks. This method returns paginated results:
# List webhooks with pagination
webhooks = client.list_webhooks(max_results=10)
for webhook in webhooks:
print(f"{webhook.name}: {webhook.url} (Status: {webhook.status})")
print(f" Events: {', '.join(webhook.events)}")
# Continue to next page if available
if webhooks.next_page_token:
next_page = client.list_webhooks(
max_results=10, page_token=webhooks.next_page_token
)
To retrieve all webhooks across multiple pages:
# Retrieve all webhooks across pages
all_webhooks = []
page_token = None
while True:
page = client.list_webhooks(max_results=100, page_token=page_token)
all_webhooks.extend(page)
if not page.next_page_token:
break
page_token = page.next_page_token
print(f"Total webhooks: {len(all_webhooks)}")
Getting a Specific Webhook
Use MlflowClient.get_webhook()
to retrieve details of a specific webhook:
# Get a specific webhook by ID
webhook = client.get_webhook(webhook_id)
print(f"Name: {webhook.name}")
print(f"URL: {webhook.url}")
print(f"Status: {webhook.status}")
print(f"Events: {webhook.events}")