Grafana Cloud

Rules API

Use rules to provide persistent instructions that guide Assistant behavior across conversations. Rules let you customize how Assistant responds, enforce standards, and apply organization-wide context.

Rules have two scopes:

  • Tenant rules apply to all users in the organization. Use tenant rules when you manage rules through the HTTP API, because they affect all Assistant conversations across the organization.
  • User rules apply only to the identity that created them. When a service account creates a user rule, that rule applies only to conversations started by the same service account. You can’t create user rules on behalf of other users.

Each identity can create up to 100 rules.

Examples use the base URL and service account token described in Grafana Assistant HTTP API reference.

Create a rule

Create a new user-scoped or tenant-scoped rule.

Endpoint

POST /rules

Permissions

Rule scopeRequired permission
usergrafana-assistant-app.rules.user:create
tenantgrafana-assistant-app.rules.tenant:create

Request

Send a JSON request body.

FieldRequiredDescription
scopeYesRule scope: user or tenant.
nameYesDisplay name for the rule.
ruleContentYesThe instruction text included in Assistant conversations.
enabledYesWhether the rule is active.
priorityYesPriority order. Lower values have higher priority.
applicationsYesApplications the rule applies to. Defaults to ["all"] when empty.
descriptionNoA short description of the rule.

Application values

The applications field controls which Assistant products use the rule.

ValueProduct
assistantAssistant
loopInvestigations
infrastructure_memoryInfrastructure memories
allAll applications
JSON
{
  "scope": "tenant",
  "name": "Use metric naming conventions",
  "ruleContent": "When suggesting PromQL queries, always use the naming convention <namespace>_<subsystem>_<name>_<unit> for metric names.",
  "enabled": true,
  "priority": 0,
  "applications": ["assistant"]
}

Response

JSON
{
  "status": "success",
  "data": {
    "id": "a3b1c2d4-5678-9012-abcd-ef3456789012",
    "created": "2025-11-15T08:30:00Z",
    "modified": "2025-11-15T08:30:00Z",
    "createdBy": "sa-5594@serviceaccount.grafana",
    "updatedBy": "sa-5594@serviceaccount.grafana",
    "name": "Use metric naming conventions",
    "ruleContent": "When suggesting PromQL queries, always use the naming convention <namespace>_<subsystem>_<name>_<unit> for metric names.",
    "enabled": true,
    "priority": 0,
    "scope": "tenant",
    "applications": ["assistant"]
  }
}

Examples

Bash
curl -X POST "${ASSISTANT_API_URL}/rules" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${SERVICE_ACCOUNT_TOKEN}" \
  -d '{
    "scope": "tenant",
    "name": "Use metric naming conventions",
    "ruleContent": "When suggesting PromQL queries, always use the naming convention <namespace>_<subsystem>_<name>_<unit> for metric names.",
    "enabled": true,
    "priority": 0,
    "applications": ["assistant"]
  }'

Errors

Status codeCondition
400 Bad RequestRule limit exceeded. Each user can create a maximum of 100 rules. Delete unused rules before creating new ones.

List rules

Retrieve rules with optional filtering and pagination.

Endpoint

GET /rules

Permissions

Rule scopeRequired permission
usergrafana-assistant-app.rules.user:read
tenantgrafana-assistant-app.rules.tenant:read

Request

ParameterRequiredDescription
scopeNoFilter by scope: user or tenant.
enabled_onlyNoWhen true, return only enabled rules.
limitNoMaximum number of rules to return. Range: 1-100. Default: 20.
offsetNoPagination offset. Default: 0.

Response

JSON
{
  "status": "success",
  "data": {
    "rules": [
      {
        "id": "a3b1c2d4-5678-9012-abcd-ef3456789012",
        "created": "2025-11-15T08:30:00Z",
        "modified": "2025-11-15T08:30:00Z",
        "createdBy": "sa-5594@serviceaccount.grafana",
        "updatedBy": "sa-5594@serviceaccount.grafana",
        "name": "Use metric naming conventions",
        "ruleContent": "When suggesting PromQL queries, always use the naming convention <namespace>_<subsystem>_<name>_<unit> for metric names.",
        "enabled": true,
        "priority": 0,
        "scope": "tenant",
        "applications": ["assistant"]
      }
    ],
    "pagination": {
      "total": 1,
      "limit": 20,
      "offset": 0
    }
  }
}

Examples

Bash
curl -X GET "${ASSISTANT_API_URL}/rules?scope=tenant&enabled_only=true&limit=10" \
  -H "Authorization: Bearer ${SERVICE_ACCOUNT_TOKEN}"

Get a rule

Retrieve a single rule by ID.

Endpoint

GET /rules/{id}

Permissions

Rule scopeRequired permission
usergrafana-assistant-app.rules.user:read
tenantgrafana-assistant-app.rules.tenant:read

Request

ParameterRequiredDescription
idYesThe rule ID returned when you create a rule.

Response

JSON
{
  "status": "success",
  "data": {
    "id": "a3b1c2d4-5678-9012-abcd-ef3456789012",
    "created": "2025-11-15T08:30:00Z",
    "modified": "2025-11-15T08:30:00Z",
    "createdBy": "sa-5594@serviceaccount.grafana",
    "updatedBy": "sa-5594@serviceaccount.grafana",
    "name": "Use metric naming conventions",
    "ruleContent": "When suggesting PromQL queries, always use the naming convention <namespace>_<subsystem>_<name>_<unit> for metric names.",
    "enabled": true,
    "priority": 0,
    "scope": "tenant",
    "applications": ["assistant"]
  }
}

Examples

Bash
RULE_ID="a3b1c2d4-5678-9012-abcd-ef3456789012"

curl -X GET "${ASSISTANT_API_URL}/rules/${RULE_ID}" \
  -H "Authorization: Bearer ${SERVICE_ACCOUNT_TOKEN}"

Update a rule

Update an existing rule. Only the fields you include in the request body are changed, except scope which is always required.

Endpoint

PUT /rules/{id}

Permissions

Rule scopeRequired permission
usergrafana-assistant-app.rules.user:write
tenantgrafana-assistant-app.rules.tenant:write

To change a rule’s scope, the service account needs write permissions for both scopes.

Request

ParameterRequiredDescription
idYesThe rule ID.

Send a JSON request body with the fields to update.

FieldRequiredDescription
scopeYesThe desired scope. Set to the current value to keep the scope unchanged, or set a different value to transition between user and tenant.
nameNoUpdated display name.
ruleContentNoUpdated instruction text.
descriptionNoUpdated description.
enabledNoWhether the rule is active.
priorityNoUpdated priority order.
applicationsNoUpdated application list.

Response

The response contains the full updated rule.

JSON
{
  "status": "success",
  "data": {
    "id": "a3b1c2d4-5678-9012-abcd-ef3456789012",
    "created": "2025-11-15T08:30:00Z",
    "modified": "2025-11-20T14:15:00Z",
    "createdBy": "sa-5594@serviceaccount.grafana",
    "updatedBy": "sa-5594@serviceaccount.grafana",
    "name": "Use metric naming conventions",
    "ruleContent": "When suggesting PromQL queries, always use the naming convention <namespace>_<subsystem>_<name>_<unit> for metric names.",
    "enabled": false,
    "priority": 0,
    "scope": "tenant",
    "applications": ["assistant"]
  }
}

Examples

Disable a rule:

Bash
RULE_ID="a3b1c2d4-5678-9012-abcd-ef3456789012"

curl -X PUT "${ASSISTANT_API_URL}/rules/${RULE_ID}" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${SERVICE_ACCOUNT_TOKEN}" \
  -d '{
    "scope": "tenant",
    "enabled": false
  }'

Delete a rule

Permanently delete a rule.

Endpoint

DELETE /rules/{id}

Permissions

Rule scopeRequired permission
usergrafana-assistant-app.rules.user:delete
tenantgrafana-assistant-app.rules.tenant:delete

Request

ParameterRequiredDescription
idYesThe rule ID.

Response

A successful deletion returns HTTP 204 with no response body.

Examples

Bash
RULE_ID="a3b1c2d4-5678-9012-abcd-ef3456789012"

curl -X DELETE "${ASSISTANT_API_URL}/rules/${RULE_ID}" \
  -H "Authorization: Bearer ${SERVICE_ACCOUNT_TOKEN}"