Skip to content

Create



POST /api/v1/slo/add

Overview

Creates a monitor-based or metric-based SLO and its detection configuration.

Before Calling and Usage Steps

The current API Key requires monitor.sloCfgManage; saving a metric-based SLO additionally requires query permission for the target metric namespace. SLO management permission alone is not sufficient to pass this prerequisite check. You can only operate within the workspace that the Key belongs to; obtain the SLO UUID in the path from content.data[].uuid of Get SLO List (usually prefixed with monitor_), not the Rule UUID of the associated monitor or metricQueryInfo.sloId.

For metric-based SLOs, availability is calculated from good/total; do not mix business percentages directly as counts. Each DQL statement should be aggregated into a single comparable numeric value, and the actual data and permissions of the query must be verified first. PromQL allows aggregations such as sum(...); this API uniformly normalizes promqlType to instant queries. Monitor-based SLOs reference SLI monitors to calculate deductions and generate SLO results; after groupBy is configured, calculations are performed separately by the project/env/service dimensions. If no alert policy is configured, there is no notification association for that policy, and a successful save does not guarantee that notifications have been sent.

Creation, modification, and enable/disable operations are committed at the end of the local transaction; on failure, the system attempts to restore the remote schedule and cache, and the remote compensation may also fail, so an HTTP failure does not mean that no changes occurred in any system. After a network timeout or 500, first call Get SLO Details to verify the configuration and status, and if necessary ask the administrator to verify the schedule before retrying. A successful save does not mean detection results have been produced; wait for the detection interval and check the actual data. Creation is not idempotent: duplicate names are rejected, but when the request result is unknown, you should still search by name first. The creation response does not include complete tagInfo or alertPolicyInfos; after saving, read the details to verify the associations.

Do not submit server-side fields such as metricResultValidAfter/metricResultStoppedAt/metricQueryInfo; undisclosed Body fields are first rejected by the route declaration with a generic 406 parameter error.

Request Headers

Parameter Name Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the workspace.
Example: <DF-API-KEY>
How to obtain or fill in: Obtain an OpenAPI Key with this operation permission from the API Key management of the target workspace.

Body Request Parameters

Parameter Name Type Required Description
metricQueries.total object Total query object; must contain dql and cannot provide only editor.
Example: {"dql": "M::http_requests:(SUM(`total`))"}
How to obtain or fill in: Construct from the target measurement and the corresponding business fields.
metricQueries.total.dql string Required non-empty query string, up to 65536 characters. When queryType=dql, only a single-output SELECT or a valid eval expression on M metrics in the current workspace is supported; SHOW/other execution functions, cross-workspace metrics, and DQL built-in windows are not supported. The caller should first aggregate into a single comparable numeric value and verify the result to avoid multiple series produced by GROUP BY. When queryType=promql, this field is still named dql and accepts valid PromQL.
Example: M::http_requests:(SUM(`total`))
How to obtain or fill in: Determined by the language of the metric query and the business fields.
metricQueries.total.queryType string Optional dql/promql, defaults to dql; determines the parsing and execution language of the dql string.
Example: dql
How to obtain or fill in: Determined by the language of the metric query and the business fields.
metricQueries.total.promqlType string Can only appear when queryType=promql; input instantQuery/rangeQuery, but saving and execution are uniformly instantQuery, and passing rangeQuery cannot require range results. This key is rejected in the DQL branch.
Example: instantQuery
How to obtain or fill in: Determined by the language of the metric query and the business fields.
metricQueries.total.editor object Optional echo object, defaults to {}; stores editor state and does not participate in query execution comparison. On modification, the query object is replaced as a whole.
Example: {}
How to obtain or fill in: Determined by the language of the metric query and the business fields.
metricQueries.good object Success-count query object; must contain dql and cannot provide only editor.
Example: {"dql": "M::http_requests:(SUM(`good`))"}
How to obtain or fill in: Construct from the target measurement and the corresponding business fields.
metricQueries.good.dql string Required non-empty query string, up to 65536 characters. When queryType=dql, only a single-output SELECT or a valid eval expression on M metrics in the current workspace is supported; SHOW/other execution functions, cross-workspace metrics, and DQL built-in windows are not supported. The caller should first aggregate into a single comparable numeric value and verify the result to avoid multiple series produced by GROUP BY. When queryType=promql, this field is still named dql and accepts valid PromQL.
Example: M::http_requests:(SUM(`good`))
How to obtain or fill in: Determined by the language of the metric query and the business fields.
metricQueries.good.queryType string Optional dql/promql, defaults to dql; determines the parsing and execution language of the dql string.
Example: dql
How to obtain or fill in: Determined by the language of the metric query and the business fields.
metricQueries.good.promqlType string Can only appear when queryType=promql; input instantQuery/rangeQuery, but saving and execution are uniformly instantQuery, and passing rangeQuery cannot require range results. This key is rejected in the DQL branch.
Example: instantQuery
How to obtain or fill in: Determined by the language of the metric query and the business fields.
metricQueries.good.editor object Optional echo object, defaults to {}; stores editor state and does not participate in query execution comparison. On modification, the query object is replaced as a whole.
Example: {}
How to obtain or fill in: Determined by the language of the metric query and the business fields.
sliUUIDs[*] string Single string item; the array must not contain objects/arrays/null.
Example: rul_example
How to obtain or fill in: Obtain content.data[].uuid from Monitor List; you can use search to find by name. Verify that the monitor is in the same workspace, not deleted, and can be used as an SLI.
alertPolicyUUIDs[*] string Single string item; the array must not contain objects/arrays/null.
Example: altpl_example
How to obtain or fill in: Obtain valid policy UUIDs in the current workspace from Alert Policy List.
tags[*] string Single string item; the array must not contain objects/arrays/null.
Example: production
How to obtain or fill in: Select tag names whose scope includes monitor or all from Tag List; a new name can also be passed.
groupBy[*] string Single string item; the array must not contain objects/arrays/null. Only project/env/service.
Example: service
How to obtain or fill in: Select collected project/env/service dimensions, and ensure that the source monitor events/service data contain the corresponding fields.
status integer Optional 0 enabled/2 disabled; creation defaults to 0, omission on modification preserves the value; null is not allowed.
Null allowed: False
Optional values: [0, 2]
Example: 0
How to obtain or fill in: Choose according to whether detection should start immediately.
sliType string Creation defaults to monitor, optional monitor/metric; cannot be switched after creation, omission on modification preserves the value, and any passed value must match the original.
Null allowed: False
Optional values: ['monitor', 'metric']
Example: monitor
How to obtain or fill in: Choose calculation by an existing monitor or by metric queries.
checkRange integer Statistical window in seconds, only 604800/2592000; creation defaults to 604800 when omitted, omission on modification preserves the value. Historical configurations such as the old 90 days must be explicitly changed to a supported value before saving.
Null allowed: False
Optional values: [604800, 2592000]
Example: 604800
How to obtain or fill in: Choose 7 days or 30 days according to the SLO statistical requirements.
metricQueries object Metric-based only; required on creation, omission on modification preserves the value, and when present total/good are replaced as a whole; partial patches or null are not accepted. The object must contain exactly total and good; each item supports dql/queryType/editor and promqlType for PromQL, and other execution options are not accepted. The two items should measure the total and success counts over the same business scope/time unit to ensure comparability; the API does not verify business correctness on the customer's behalf when saving.
Null allowed: False
Example: {"total": {"dql": "M::http_requests:(SUM(`total`))"}, "good": {"dql": "M::http_requests:(SUM(`good`))"}}
How to obtain or fill in: Determine the total and success count fields from metric data, and first use Query Data to verify each query value and collection scope.
name string Y Required on creation, string, up to 256 characters, and active SLOs in the same workspace cannot have duplicate names; the caller should use a non-empty name. Omission on modification is allowed, but the submitted value must exactly match the original name.
Null allowed: False
Maximum length: 256
Example: 支付服务可用性
How to obtain or fill in: The caller assigns a name for the SLO; read the details before modification.
interval string Y Required on creation, 5m or 10m; omission on modification preserves the value; not the same concept as the checkRange statistical window.
Null allowed: False
Optional values: ['5m', '10m']
Example: 5m
How to obtain or fill in: Choose the detection interval as needed.
goal float Y Required numeric value on creation, 0<goal<100; on modification can only be omitted or passed with the original value. For example, 99.9 means 99.9%, not 0.999.
Null allowed: False
Greater than: 0
Less than: 100
Example: 99.9
How to obtain or fill in: Set the expected target based on the business SLA, in percent.
minGoal float Y Required numeric value on creation, 0<minGoal<goal<100; on modification can only be omitted or passed with the original value. Values below minGoal are critical, and values reaching minGoal but below goal are warning.
Null allowed: False
Greater than: 0
Less than: 100
Example: 99.5
How to obtain or fill in: Set based on the minimum tolerable availability, in percent.
sliUUIDs array Must be non-empty when creating a monitor-based SLO; omission on modification preserves the references, [] clears the references (which may leave the SLO with no valid SLI; confirm first); fully replaced and deduplicated, order not guaranteed. For metric-based SLOs, omit or use [], and it must not be non-empty. Only rules in the same workspace that are active with type=trigger or the legacy empty type should be used as SLIs; the current save does not individually reject invalid/cross-workspace UUIDs, so success does not prove every item is computable. null is not allowed.
Null allowed: False
Example: ["rul_example"]
How to obtain or fill in: Obtain content.data[].uuid from Monitor List; you can use search to find by name. Verify that the monitor is in the same workspace, not deleted, and can be used as an SLI.
describe string Optional string, up to 3000 characters; creation defaults to an empty string when omitted, omission on modification preserves the value, an empty string clears it; null is not allowed.
Null allowed: False
Empty string allowed: True
Maximum length: 3000
Example: 支付服务生产环境SLO
How to obtain or fill in: The caller fills in usage/maintenance notes.
alertPolicyUUIDs array Optional array; omission on creation means no association, omission on modification preserves the value, [] removes all associations; when passed, fully replaced and deduplicated, and unknown/deleted/cross-workspace policies are rejected. Notification targets or alertOpt cannot be configured directly through this API.
Null allowed: False
Example: ["altpl_example"]
How to obtain or fill in: Obtain valid policy UUIDs in the current workspace from Alert Policy List.
tags array Name array, each up to 128 characters, case-sensitive; new names are created with the monitor scope. Omission on creation means no tags, omission on modification preserves the value, [] clears it; fully replaced and deduplicated. If an existing tag with the same name does not support monitor, a 400 is returned; null is not allowed.
Null allowed: False
Example: ["production"]
How to obtain or fill in: Select tag names whose scope includes monitor or all from Tag List; a new name can also be passed.
groupBy array Supported for monitor-based SLOs only; only project/env/service are allowed in the array and must not repeat, order is preserved. Creation defaults to [], omission on modification preserves the value, [] cancels grouping; for metric-based SLOs, omit or use [].
Null allowed: False
Example: ["service"]
How to obtain or fill in: Select collected project/env/service dimensions, and ensure that the source monitor events/service data contain the corresponding fields.
ignoreBadGroupEvents boolean Can only be passed for monitor-based SLOs, defaults to true; it is only saved and used in calculation when groupBy is non-empty. Omission on modification preserves the value; when a group is newly added and no original value exists, it is true; canceling groupBy removes this configuration. For metric-based SLOs, it is rejected even if false is passed.
Null allowed: False
Example: true
How to obtain or fill in: When groupBy is present, choose according to whether to ignore events from abnormal groups.

Additional Parameter Notes

The SLI UUID comes from the Rule uuid in the Monitor List; alerts are associated with alert policies through alertPolicyUUIDs, and the policy then controls notifications. Do not submit alertOpt/alertTarget from older documentation; these fields are not exposed by this entry point.

Request Example

curl --request POST 'https://openapi.guance.com/api/v1/slo/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"name":"支付服务可用性","interval":"5m","goal":99.9,"minGoal":99.5,"sliUUIDs":["rul_example"]}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content.id integer or null Database row ID; the creation response is generated before commit and may be null; use uuid as the business identifier.
content.uuid string SLO UUID, used by subsequent details, modification, enable/disable, and deletion.
content.workspaceUUID string Target workspace UUID.
content.name string SLO name.
content.type string Fixed as slo.
content.score integer Resource sorting weight, not the SLO availability percentage.
content.status integer 0 enabled/2 disabled.
content.creator string UUID of the creating Key resource or a legacy account identifier.
content.updator string Most recent updater; may be empty on creation.
content.createAt integer Creation time, Unix seconds.
content.updateAt integer Last update time, Unix seconds; may be -1 if never updated.
content.deleteAt integer Deletion time; -1 for normal active records.
content.config object Saved SLO calculation configuration; does not include the direct notification target configuration alertOpt.
content.config.sliType string monitor or metric; returns monitor when missing in legacy configurations.
content.config.checkRange integer Statistical window in seconds, 604800 or 2592000.
content.config.goal number Expected target percentage.
content.config.minGoal number Minimum target percentage.
content.config.interval string 5m or 10m.
content.config.describe string Usage description.
content.config.groupBy array<string> Grouping dimension array for monitor-based SLOs; empty for metric-based SLOs.
content.config.groupBy[] string One of project/env/service.
content.config.ignoreBadGroupEvents boolean Returned only when grouping dimensions exist; whether to ignore events from abnormal groups.
content.config.sli_infos array<object> or object Present when SLI summaries are loaded this time; usually an array of objects for monitor-based SLOs, and currently {} on creation for metric-based SLOs; may be omitted on modification when sliUUIDs is not submitted. Do not treat this field as the complete list of referenced UUIDs.
content.config.sli_infos[].id string Rule UUID of the valid SLI monitor actually matched in the current workspace.
content.config.sli_infos[].name string or null SLI monitor name.
content.config.sli_infos[].status integer Associated monitor status, possibly 0 or 2; non-existent references are not included in the summary.
content.config.metricResultValidAfter integer or null Metric-based only: lower bound from which this statistical period takes effect, Unix milliseconds. Reset on creation, window change/query execution, and switching from disabled to enabled; only changing editor does not reset it.
content.config.metricResultStoppedAt integer or null Metric-based only: time when calculation stopped, Unix milliseconds; null at runtime, recorded when disabled.
content.metricQueryInfo object Metric-based only: query result location information, not the raw business metric value.
content.metricQueryInfo.measurement string Fixed as slo_metric.
content.metricQueryInfo.sloId string UUID of the actual detection Rule, used to query slo_metric.slo_id; different from content.uuid.
content.metricQueryInfo.validAfter integer or null Same as config.metricResultValidAfter.
content.metricQueryInfo.stoppedAt integer or null Same as config.metricResultStoppedAt.
content.declaration object Common declaration for the current workspace.
content.config.metricQueries.total.dql string Normalized execution query.
content.config.metricQueries.total.queryType string dql or promql.
content.config.metricQueries.total.promqlType string Returned only for PromQL, fixed as instantQuery.
content.config.metricQueries.total.editor object Caller editor echo data.
content.config.metricQueries.total.editor.Custom field JSON Dynamic editor state passed by the caller; not interpreted as a server-side execution option.
content.config.metricQueries.good.dql string Normalized execution query.
content.config.metricQueries.good.queryType string dql or promql.
content.config.metricQueries.good.promqlType string Returned only for PromQL, fixed as instantQuery.
content.config.metricQueries.good.editor object Caller editor echo data.
content.config.metricQueries.good.editor.Custom field JSON Dynamic editor state passed by the caller; not interpreted as a server-side execution option.
content.config.metricQueries object Metric-based only; complete normalized configuration of total and good.
content.config.metricQueries.total object Total query configuration.
content.config.metricQueries.good object Success-count query configuration.
{
  "code": 200,
  "content": {
    "id": null,
    "uuid": "monitor_example",
    "workspaceUUID": "wksp_example",
    "name": "支付服务可用性",
    "type": "slo",
    "score": 0,
    "status": 0,
    "creator": "wsak_example",
    "updator": "",
    "createAt": 1785427200,
    "updateAt": -1,
    "deleteAt": -1,
    "config": {
      "goal": 99.9,
      "minGoal": 99.5,
      "interval": "5m",
      "checkRange": 604800,
      "sliType": "monitor",
      "describe": "支付服务生产环境SLO",
      "groupBy": [],
      "sli_infos": [
        {
          "id": "rul_example",
          "name": "支付接口成功率",
          "status": 0
        }
      ]
    },
    "declaration": {},
    "errorCode": "",
    "message": "",
    "success": true,
    "traceId": "TRACE-EXAMPLE"
  }
}

Wait, the original JSON has top-level code, content, errorCode, message, success, traceId. Let me keep structure exactly. I wrote it correctly.

Now the second curl example and JSON.

curl --request POST '<Endpoint>/api/v1/slo/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"name":"支付指标成功率","sliType":"metric","goal":99.9,"minGoal":99.5,"interval":"5m","metricQueries":{"total":{"dql":"M::http_requests:(SUM(`total`))"},"good":{"dql":"M::http_requests:(SUM(`good`))"}}}'
{
  "code": 200,
  "content": {
    ...
  }
}

Error Responses

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed Request field missing, or field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError Request JSON syntax is invalid Request JSON format error Correct the JSON according to content.reason, line, column.
400 ft.JsonFormatError JSON top level is not an object Some json file format error Submit a JSON object.
400 ft.ParamsValidateError Business combination of disclosed fields such as metric queries/period/dimensions is invalid Parameter validation failed: {} Correct according to the parameter constraints of the two types, preserving the original name, target, and type; do not submit server-side fields.
400 ft.SloNameRepeat An active SLO in this workspace already uses this name SLO name already exists, please re-enter First use the list to find existing objects; if updating, use the original uuid to modify.
406 ft.SloMinGoalGreaterThanGoal minGoal is greater than or equal to goal minGoal must be less than goal, current minGoal: 99.9 goal: 99.9 Ensure 0<minGoal<goal<100.
400 ft.InvalidAlertPolicyUUID alertPolicyUUIDs contains a policy that is not valid in this workspace Invalid alert policy UUID Re-obtain from the alert policy list of the current workspace.
400 ft.TagScopeMismatch An existing tag with the same name has a scope that does not include monitor or all production: ['scene'] -> monitor Choose a tag usable for monitoring; do not directly reuse a same-name tag from another dedicated scope.
406 ft.ExceedMaxCharacterLimit Tag name exceeds 128 characters {} exceeds the maximum character length limit Shorten the tag name while keeping it recognizable.
400 ft.FiledCreateTrigger Creation scheduling returns without a task ID Failed to create trigger configuration, please retry First verify the SLO and residual tasks, then fix the schedule/retry.
400 ft.OuterFuncFailed Remote scheduling service returns failure External function call failed (some branches use the downstream message) Check message and traceId, ask the administrator to verify scheduling availability and the current configuration state, then retry.
400 ft.SameSetTraggerExists Remote scheduling service reports that the same trigger configuration already exists A trigger with the same configuration already exists First verify this SLO and the remote schedule, handle residual/duplicate configurations, then submit again.
500 ft.InternalServerError Database/cache, task queue, invalid array members, or unhandled downstream exceptions; failure may also have remote changes Internal error First check the target SLO configuration and current scheduling state; for deletion failures, also verify the deleted state, and do not blindly repeat creation or batch overwrite.
403 ft.ForbiddenQuery A metric-based query passes the namespace permission check but the current Key has no metric query permission You do not have {} permission Grant the Key role the query permission for the target metric, verify the query with the same Key first, then save.

Feedback

Is this page helpful?