Introducing a new way to review your PRs.

Read the announcement

keephq / keep

The open-source AIOps and alert management platform

View on GitHub

22 documents · Updated Nov 23, 2026

docs / api-route-domains

API route domains

The Keep API is the client-facing boundary for alert operations, integrations, automation, topology, tenant settings, and product views. It groups routes by product resource and turns authenticated requests into domain actions or queries with typed data returned to the web application and external clients. It is the route-focused child of API and background runtime.

API composition

The API creates one FastAPI application and mounts each product area under a stable path prefix. Route handlers receive the request context, enforce the required access scope, call the owning domain service or data layer, and return a response model or a small status result.

The request path moves from a client through identity checks and a route domain before it reaches stored data or a domain service.

flowchart LR
    Client[Web app or external client] --> API[FastAPI application]
    API --> Identity[Identity and scope check]
    Identity --> Route[Route domain]
    Route --> Logic[Domain service, store, or provider]
    Logic --> Result[Typed resource or operation result]
    Result --> Client
    Inbound[Alert event] --> Route
    Route --> Processing[Alert and workflow processing]

Route registration

keep/…/api.py is the route map. It exposes core product resources such as /alerts, /incidents, /providers, /workflows, /settings, /topology, and /dashboard. It also exposes support paths for health, status, metrics, authentication administration, real-time client auth, expression checks, and provider images. The dynamic /{entity_name}/facets path serves facet operations for alerts, incidents, and workflows.

The route modules stay separate by resource. This lets a client view a resource through one domain while related work remains in another domain. For example, an incident can expose its linked alerts while workflow execution remains under /workflows.

References: keep/…/api.py• L265-333 keep/…/facets.py• L17-23

Tenant request context

Most product routes resolve an AuthenticatedEntity before they run. This entity supplies the tenant ID and user identity that scope reads, writes, and audit data. The route then passes the tenant ID to the domain boundary instead of taking it from the client request.

Access scopes follow the resource action, such as read:alert, write:incident, or execute:workflows. The identity manager also applies resource-level limits for objects such as presets, incidents, and workflows where needed.

References: keep/…/authenticatedentity.py• L7-31 keep/…/alerts.py• L94-104 keep/…/incidents.py• L91-107 keep/…/preset.py• L215-228

Domain route groups

The route groups reflect the main product resources that clients manage. Each group combines list and query views with the commands that change the same resource.

Alert and incident operations

Alerts are the incoming or observed signals that clients search, inspect, enrich, assign, dismiss, and view as history. Incidents are higher-level groups of related alerts that clients create, update, merge, split, assign, comment on, and report on. The two domains are linked because alert queries can include incident data and incident views return linked alerts.

Resource domainMain client capabilityContract focus
AlertsQuery current alerts, inspect fingerprint history, receive events, update enrichment, and read audit or error dataAlertDto, query and enrichment request models
IncidentsList and filter incidents, manage their state, link alerts, merge or split incidents, and read reportsIncidentDto, incident commands, and paginated results
FacetsDiscover and query filter fields for alerts, incidents, and workflowsEntity name plus facet request and response data

The alert event paths form the external intake surface for provider or webhook clients. The normal resource paths serve product reads and user actions. The event path can hand work to alert processing rather than keeping the sender coupled to the full processing sequence.

References: keep/…/alerts.py• L195-250 keep/…/alerts.py• L253-334 keep/…/alerts.py• L599-704 keep/…/incidents.py• L91-203 keep/…/incidents.py• L349-575 keep/…/alert.py• L48-119 keep/…/incident.py• L42-107

Integration resources

Providers represent external systems that send data to Keep or receive actions from Keep. The provider routes let clients discover available integrations, install and update tenant configurations, test access, inspect alert or provider logs, query provider schemas, and send alerts or other actions through an installed provider. Actions are reusable operations that clients can install and manage. Provider images and Pusher auth support the product experience around those integrations.

Resource domainMain client capability
ProvidersDiscover, install, configure, test, validate scopes, inspect health, pull or push provider data, and manage webhooks
ActionsList, upload, update, and remove tenant actions
Provider imagesUpload, list, and serve tenant-specific integration images
Real-time client authAuthorize a tenant's private Pusher channel

Provider route logic crosses into the provider factory and provider service. This keeps provider-specific behavior behind a common client-facing resource shape while still allowing each provider to expose its own schema and methods.

References: keep/…/providers.py• L68-110 keep/…/providers.py• L237-320 keep/…/providers.py• L367-519 keep/…/actions.py• L15-96 keep/…/provider_images.py• L21-132 keep/…/pusher.py• L11-44

Workflow and enrichment resources

Workflows define automated responses to alert or incident events. Their routes support authoring, raw YAML import and export, template discovery, querying, test and manual runs, version and execution views, enablement, and workflow secrets. Rules and enrichment routes support the conditions and data changes that shape alert and incident behavior.

Resource domainMain client capability
WorkflowsCreate or update definitions, query metadata and templates, run or test workflows, inspect versions and runs, enable or disable workflows, and manage workflow secrets
RulesDefine time-based conditions that create or resolve incidents and view rule activity
DeduplicationsDefine the fields and rules used to group repeated alerts
Mapping rulesMap incoming data to target fields and inspect enrichment executions
Extraction rulesExtract fields from alerts and inspect rule executions
Maintenance rulesDefine time windows that affect alert handling
CEL validationCheck a CEL expression and return the invalid character range when parsing fails

The route layer does not decide workflow steps or provider actions. It validates request shapes and permissions, then hands definitions or events to the workflow store and manager. Workflow secrets use the tenant's secret manager, while enrichment and maintenance routes follow the same boundary: the API exposes resource commands while their effects occur in alert processing or related domain services.

References: keep/…/workflows.py• L178-312 keep/…/workflows.py• L357-451 keep/…/workflows.py• L486-595 keep/…/workflows.py• L611-792 keep/…/workflows.py• L795-1073 keep/…/workflows.py• L1076-1323 keep/…/rules.py• L22-66 keep/…/deduplications.py• L16-142 keep/…/mapping.py• L28-230 keep/…/extraction.py• L25-180 keep/…/maintenance.py• L18-119 keep/…/cel.py• L14-39

Topology and presentation resources

Topology represents applications, services, and dependencies so clients can view service relationships and maintain them when provider data is incomplete. Presets, dashboards, tags, and metrics shape how clients browse alerts and incidents and how they present operational results.

Resource domainMain client capability
TopologyRead, import, pull, create, update, and delete applications, services, and dependencies
PresetsSave alert views with filters, columns, tags, and visibility settings
DashboardsStore dashboard layouts and retrieve metric widgets for a time range
TagsRead tenant tags used by saved views
MetricsExport tenant alert, incident, and workflow counts for Prometheus

These resources are presentation-facing but still use the same tenant boundary. A preset or dashboard changes how a tenant sees operational data; it does not replace the alert, incident, or workflow resource that supplies that data.

References: keep/…/topology.py• L43-180 keep/…/preset.py• L201-236 keep/…/preset.py• L239-318 keep/…/dashboard.py• L25-180 keep/…/tags.py• L10-17 keep/…/metrics.py• L55-150 keep/…/provider.py• L14-59

Tenant administration and platform surfaces

Settings routes expose tenant webhook details, SMTP settings, API keys, SSO settings, and tenant configuration. The nested authentication routes manage users, groups, roles, and permissions through the selected identity manager. Health, status, whoami, and metrics paths give clients and operators small platform-level views without becoming product resource domains.

The webhook settings response connects tenant configuration to alert intake by returning the event URL, an API key, and the alert schema. This makes the settings surface part of the client onboarding flow rather than a separate alert implementation.

References: keep/…/settings.py• L39-100 keep/…/settings.py• L103-155 keep/…/settings.py• L246-437 keep/…/users.py• L18-167 keep/…/roles.py• L13-66 keep/…/groups.py• L14-73 keep/…/permissions.py• L15-71 keep/…/healthcheck.py• L6-14 keep/…/status.py• L8-20 keep/…/whoami.py• L12-24

Request and response contracts

FastAPI uses typed request models at the boundary for the resources that need stable schemas. These models turn JSON, query values, form data, and uploaded YAML or files into domain inputs. Response models turn stored or computed values into the shapes expected by the web client and external integrations.

Request models

Request models describe commands and query controls rather than database records. Alert and incident commands carry user actions such as dismissal, enrichment, status changes, merge, and split. Workflow requests can carry a raw definition or an event payload for a run, either as JSON or uploaded YAML. Resource settings use focused models for providers, SMTP, dashboards, topology, rules, and maintenance windows.

Query requests use QueryDto for CEL filters, paging, and sort options. The same query idea appears in alert and workflow search, while incident routes add incident-specific filters such as status, severity, assignee, and affected service.

References: keep/…/query.py• L5-16 keep/…/alert.py• L63-64 keep/…/incident.py• L22-70 keep/…/workflow.py• L127-139 keep/…/dashboard.py• L25-40 keep/…/rules.py• L22-39 keep/…/maintenance.py• L7-10 keep/…/workflows.py• L315-354 keep/…/workflows.py• L582-608

Response models

Response models separate client contracts from internal records. AlertDto exposes normalized alert state and enrichment fields. IncidentDto adds incident state, counts, services, rule links, and related alert access. WorkflowDTO combines definition data with provider metadata and recent execution state. Provider and topology DTOs expose integration and service-relationship data in forms suitable for product screens.

List endpoints often return a collection directly. Search and execution endpoints use a paginated result with count, limit, offset, and result items. Command endpoints may return the changed resource, an operation ID, or a small status message when the client only needs confirmation.

References: keep/…/alert.py• L75-119 keep/…/incident.py• L63-107 keep/…/workflow.py• L25-47 keep/…/workflow.py• L95-149 keep/…/provider.py• L10-59 keep/…/incidents.py• L91-144 keep/…/workflows.py• L611-650 keep/…/workflows.py• L977-1145

Business-logic boundaries

The API route layer is an adapter between clients and Keep's domain systems. It owns transport concerns such as path and query parsing, request validation, authentication dependencies, status codes, and response shaping. It should not become the owner of alert correlation, workflow execution, provider behavior, or identity policy.

Domain ownership

The main ownership boundaries are visible in the calls made by each route group:

API concernOwning boundary
Alert search and alert stateAlert core and enrichment services
Incident lifecycleIncident business logic and incident report services
Provider setup and provider methodsProvider service and provider factory
Workflow definitions and runsWorkflow store and workflow manager
Workflow secretsSecret manager selected for the tenant
Topology relationshipsTopology service
Tenant identity administrationIdentity manager selected for the tenant
Secret-backed settingsSecret manager selected for the tenant

Some older or small resource routes still perform simple persistence work in the route module. The important contract is that the route remains the client boundary and keeps tenant filtering and request-to-model conversion visible, while complex product behavior stays in its domain owner.

References: keep/…/alerts.py• L21-80 keep/…/incidents.py• L19-85 keep/…/providers.py• L16-37 keep/…/workflows.py• L24-68 keep/…/workflows.py• L795-855 keep/…/workflows.py• L1207-1323 keep/…/topology.py• L23-36 keep/…/users.py• L58-107 keep/…/settings.py• L84-139

Operation outcomes

A successful read returns the resource or a paginated view. A successful command returns the changed resource when the client needs the new state, or a confirmation and operation identifier when the work continues outside the request. Invalid input is commonly reported as a 400 response, a missing tenant-scoped resource as 404, and a denied scope or resource permission as 403. Domain-specific failures can also become conflict or dependency errors when a resource cannot be changed in its current state.

The API has a final exception handler for unexpected failures. It returns a 500 response with a trace ID so the client can report the failure and an operator can connect it to server logs.

References: keep/…/incidents.py• L423-456 keep/…/incidents.py• L459-539 keep/…/extraction.py• L114-160 keep/…/mapping.py• L126-197 keep/…/workflows.py• L376-451 keep/…/api.py• L343-355

Client resource flows

The same route domains support two broad client flows: read and operate on existing product resources, or submit an event or command that changes state and may start downstream processing.

Resource read flow

A client first sends a tenant-scoped request with its access credentials. The route parses filters or identifiers, asks the resource owner for data, applies the response contract, and returns a view that can include related records such as incident links, provider metadata, or workflow execution state.

This flow keeps search controls close to the resource. Alert and workflow queries accept CEL and paging. Incident queries add incident state and service filters. Presets and dashboards then reuse the resulting operational data for saved views and summary widgets. Workflow clients can also read a definition revision, its execution list, or one execution with logs and results.

References: keep/…/alerts.py• L195-250 keep/…/incidents.py• L125-203 keep/…/workflows.py• L195-296 keep/…/workflows.py• L874-1145 keep/…/preset.py• L205-236 keep/…/dashboard.py• L148-180

Resource command flow

When a client changes a resource, the route checks the write scope and tenant, validates the command, and passes it to the owning boundary. The owner persists the change or starts domain processing. The route then returns the new resource state or a result that identifies the accepted operation.

Workflow commands can create or update a raw definition, toggle its enabled state, start a manual or test run, or manage tenant-scoped secrets. Alert events and workflow runs are the main cases where the request boundary can lead to later work. The route accepts a normalized event or workflow definition and passes it to the processing system. Details of queues, workers, and event subscribers belong on the sibling page Asynchronous jobs and event processing.

References: keep/…/alerts.py• L599-704 keep/…/workflows.py• L357-579 keep/…/workflows.py• L611-716 keep/…/workflows.py• L795-855 keep/…/workflows.py• L1148-1323 keep/…/incidents.py• L380-420 keep/…/providers.py• L470-519

Change checklist

When these files or sections are changed, remember to consider these:

  • Route prefixes and tags in keep/…/api.py must stay aligned with the client paths and generated API description.
  • A new tenant resource must carry its tenant filter through the route and the domain or persistence boundary. Do not rely on a client-supplied tenant ID.
  • Changes to request fields must be checked against the matching DTO, UI request shape, and any YAML or webhook producer that sends the data.
  • Changes to AlertDto, IncidentDto, or WorkflowDTO can affect search results, incident links, workflow screens, and downstream event processing at the same time.
  • Workflow YAML changes must preserve parsing, revision, provider metadata, and the event shape used by manual and test runs.
  • Workflow changes must keep provisioned-workflow restrictions and the separate execute:workflows and write:workflows permissions aligned with client actions.
  • Changes to scope names must stay aligned with route dependencies and the identity manager's resource permissions.
  • Changes to accepted operation results must preserve IDs used by the UI for workflow runs, enrichment events, and incident commands.
  • Changes to workflow secret routes must preserve the tenant/workflow secret key and the read/write secret scope boundary.
  • Changes to provider route inputs must preserve the provider factory contract and the secret key used to load tenant provider configuration.

Important failure modes

TriggerConsequenceGuard
A route uses the wrong or missing access scopeA valid client is denied, or a protected action becomes too openMatch each route dependency to the resource action and verify the identity manager scope list
Tenant filtering is omitted from a resource queryOne tenant can see or change another tenant's dataDerive the tenant from AuthenticatedEntity and pass it into every resource lookup
CEL input cannot be parsedAlert, incident, or workflow search fails instead of returning a useful resultConvert the parse error to a 400 response and keep the expression in the error detail
A provider configuration or required scope is invalidProvider install, update, test, or alert delivery failsValidate through the provider service and return its status rather than treating the provider as ready
A referenced incident, alert, workflow, or rule is missingThe command cannot be applied and can produce an incorrect client stateCheck the tenant-scoped resource before the domain command and return 404
A workflow is provisioned and a client tries to update or toggle itThe workflow remains protected and the client receives 403Reject changes to provisioned workflows before storing the new definition or state
A workflow definition or manual event has an invalid shapeThe run is rejected or cannot produce a meaningful execution recordParse the definition and normalize the event before handing it to the workflow manager
A workflow secret name is empty or cannot be read from the secret managerSecret writes fail, or a client sees an empty secret resultTrim and validate names on write, use the tenant-scoped secret manager, and keep secret scopes separate
Pusher is disabled or the client requests another tenant channelReal-time updates do not connectRequire the configured Pusher client and allow only the authenticated tenant channel
An unexpected route exception escapes normal handlingThe client receives a generic failure while operators need a trace linkUse the API exception handler response and its trace ID

Key files

FileWhy to read it
keep/…/api.pyShows the application entry point, route prefixes, cross-cutting middleware, and platform exception behavior
keep/…/alerts.pyShows the alert query, event intake, enrichment, assignment, and history boundary
keep/…/incidents.pyShows incident lifecycle commands and the link between incidents and alerts
keep/…/providers.pyShows how client integration operations cross into provider services and factories
keep/…/workflows.pyShows workflow definition, template, manual run, test run, version, execution, enablement, and secret routes
keep/…/topology.pyShows application, service, and dependency resource operations
keep/…/settings.pyShows tenant webhook onboarding and secret-backed settings and API keys
keep/…/alert.pyDefines the normalized alert contract returned to clients
keep/…/incident.pyDefines the incident input and output contract and its alert relationship
keep/…/workflow.pyDefines workflow, execution, version, and run result contracts
keep/…/authenticatedentity.pyDefines the tenant and user context used by protected routes