Skip to content

Metrics

Report counters, gauges and timings, then query time-series aggregates (p50/p99/sum/avg) — StatsD/Prometheus-style metrics.

1. Overview

Base path: https://api.infrai.cc/v1/metrics
Auth header: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/metrics capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/metrics/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. Methods (3)

2.1metrics.report

POST /v1/metrics/report

Report one or more metric points.

Parameters

NameTypeRequiredDescription
namestring
Required
Metric name.
pattern: ^[a-zA-Z][a-zA-Z0-9_.-]{0,127}$
valuenumber
Required
Numeric metric value.
tagsRecord<string, string>OptionalKey/value tags for grouping.

Returns

{ ok: boolean }
NameTypeDescription
acceptedinteger | booleanNumber of items accepted for processing
≥ 0
metric_idstringIdentifier of the ingested metric point (metrics.report only)

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/metrics/report \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "example", "value": 1.0, "type": "counter"}'

2.2metrics.batch

POST /v1/metrics/batch

Report indicator data points in batches

Parameters

NameTypeRequiredDescription
pointsMetricPoint[]
Required
Array of indicator data points
≥ 1 item
idempotency_keystringOptionalIdempotent keys, used to avoid repeated writes

Returns

MetricBatchResult
NameTypeDescription
acceptedinteger | booleanNumber of items accepted for processing
≥ 0
metric_idstringIdentifier of the ingested metric point (metrics.report only)

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/metrics/batch \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"points": [{"name": "example", "value": 1.0, "type": "counter"}]}'

2.3metrics.query

GET /v1/metrics/query

Query indicator time series

Parameters

NameTypeRequiredDescription
namestring
Required
Indicator name
pattern: ^[a-zA-Z][a-zA-Z0-9_.-]{0,127}$
agg"p50" | "p99" | "sum" | "avg" | "count"
Required
Aggregation method: p50/p99/sum/avg/count
tagsRecord<string, string>OptionalFilter by tag
windowstringOptionalAggregation time window, such as 5m, 1h
sincestringOptionalstart time
format: date-time
untilstringOptionalend time
format: date-time

Returns

MetricSeries
NameTypeDescription
namestring | nullHuman-readable name for this resource
agg"p50" | "p99" | "sum" | "avg" | "count" | nullAggregation function (sum, avg, max, min)
pointsobject[]Metric data points
points[].tsstring-
format: date-time
points[].valuenumber-

Example

One-time prep (each example is assumed to be complete):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/metrics/query?name=example&agg=p50 \
  -H "Authorization: Bearer $INFRAI_API_KEY"

3. All capabilities

Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.

metrics.batchPOST /v1/metrics/batch

Report a batch of metric data points.

Parameters (2)
NameTypeRequiredDescription
pointsobject[]RequiredMetric data points
≥ 1 item
idempotency_keystring | nullOptionalDedup key for the whole batch (route is idempotent:true).
metrics.queryGET /v1/metrics/query

Query a metric time series with aggregation.

Parameters (9)
NameTypeRequiredDescription
namestringRequiredHuman-readable name for this resource
pattern: ^[a-zA-Z][a-zA-Z0-9_.-]{0,127}$
agg"p50" | "p99" | "sum" | "avg" | "count"RequiredAggregation function (sum, avg, max, min)
tagsobject | nullOptionalFilter to points matching these tags. Encode each entry in the query string as tag.<key>=<value>, for example tag.region=cn.
windowstring | nullOptionalBucket size, e.g. '1m', '5m', '1h'.
stepstring | nullOptionalAlias for window; bucket size such as '60', '5m', '1h', or '1d'.
sincestring | nullOptionalISO 8601 date when the current tier or state became effective
format: date-time
untilstring | nullOptionalISO 8601 date/time for the end of the query range
format: date-time
fromstring | nullOptionalAlias for since.
format: date-time
tostring | nullOptionalAlias for until.
format: date-time
metrics.reportPOST /v1/metrics/report

Report a single metric point (counter, gauge, timing, or distribution) with tags and idempotency.

Parameters (6)
NameTypeRequiredDescription
namestringRequiredHuman-readable name for this resource
pattern: ^[a-zA-Z][a-zA-Z0-9_.-]{0,127}$
valuenumberRequiredValue of the DNS record or configuration
type"counter" | "gauge" | "timing" | "distribution"RequiredType discriminator for this resource
tagsobject | nullOptionalTags for categorization and filtering
timestampstring | nullOptionalUnix timestamp of the data point
format: date-time
idempotency_keystring | nullOptionalDedup key (route is idempotent:true).

4. End-to-end example

A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.

A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.

python
#!/usr/bin/env python3
"""Infrai · metrics — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) metrics.report — POST /v1/metrics/report · Report a single metric point (counter, gauge, timing, or distribution) with tags and idempotency.
r1 = show("metrics.report", infrai("POST", "/v1/metrics/report", {"name":"example","value":1,"type":"counter"}))

# 2) metrics.batch — POST /v1/metrics/batch · Report a batch of metric data points.
r2 = show("metrics.batch", infrai("POST", "/v1/metrics/batch", {"points":[{"name":"example","value":1,"type":"counter"}]}))

# 3) metrics.query — GET /v1/metrics/query · Query a metric time series with aggregation.
r3 = show("metrics.query", infrai("GET", "/v1/metrics/query"))

5. Developer guides

Move from endpoint details to complete workflows, production patterns and troubleshooting guides verified against the live API.

Metrics developer guides