Metrics
sfp server API reference for Metrics: 8 endpoints.
/sfp/api/metrics/ingestIngest a batch of sfpowerscripts metrics events into VictoriaMetrics.
Note: Only application tokens (CI/CD pipelines) can actually ingest metrics. User tokens are silently accepted but not processed to simplify client-side logic.
Metric Types:
count: Counter for discrete events (value auto-set to 1). Use for builds, deployments, failures.guage: Point-in-time measurement. Use for pool sizes, queue depths.timers: Duration measurement. Use for build time, deploy duration.
Naming Convention: Use dot notation (e.g., sfpowerscripts.build.duration). Dots are automatically normalized for storage and querying.
Deduplication: Metrics with identical name and tags are deduplicated within 5-minute windows.
Retention: Metrics are retained for 12 months by default.
Authorization
access-token In: header
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
curl -X POST "https://example.com/sfp/api/metrics/ingest" \ -H "Content-Type: application/json" \ -d '{ "events": [ { "metric": "sfpowerscripts.build.duration", "type": "timers", "value": 45000, "timestamp": 1734019200000, "tags": { "package": "core-package", "org": "dev-sandbox" } }, { "metric": "sfpowerscripts.build.completed", "type": "count", "timestamp": 1734019200000, "tags": { "package": "core-package", "status": "success" } }, { "metric": "sfpowerscripts.pool.available", "type": "guage", "value": 5, "timestamp": 1734019200000, "tags": { "pool": "ci-pool" } } ] }'{ "accepted": 10, "message": "Metrics accepted"}/sfp/api/metrics/queryExecute an instant query against VictoriaMetrics using MetricsQL/PromQL syntax.
Query Examples:
sfpowerscripts.build.duration- Get latest valuesum(sfpowerscripts.build.completed)- Aggregate countssfpowerscripts.build.duration{package="core"}- Filter by tagrate(sfpowerscripts.build.completed[1h])- Calculate rate over 1 hour
See MetricsQL documentation for full syntax.
Authorization
access-token In: header
Query Parameters
MetricsQL / PromQL query expression
Evaluation timestamp (RFC3339 or unix seconds)
Query timeout (duration), forwarded to VictoriaMetrics
Response Body
application/json
curl -X GET "https://example.com/sfp/api/metrics/query?query=sum%28rate%28sfp_build_duration_seconds%5B5m%5D%29%29"{ "result": {}}/sfp/api/metrics/api/v1/queryExecute an instant query against VictoriaMetrics using MetricsQL/PromQL syntax.
Query Examples:
sfpowerscripts.build.duration- Get latest valuesum(sfpowerscripts.build.completed)- Aggregate countssfpowerscripts.build.duration{package="core"}- Filter by tagrate(sfpowerscripts.build.completed[1h])- Calculate rate over 1 hour
See MetricsQL documentation for full syntax.
Authorization
access-token In: header
Query Parameters
MetricsQL / PromQL query expression
Evaluation timestamp (RFC3339 or unix seconds)
Query timeout (duration), forwarded to VictoriaMetrics
Response Body
application/json
curl -X GET "https://example.com/sfp/api/metrics/api/v1/query?query=sum%28rate%28sfp_build_duration_seconds%5B5m%5D%29%29"{ "result": {}}/sfp/api/metrics/query_rangeExecute a range query to get metrics over a time period with specified resolution.
Use Cases:
- Generate time-series data for charts
- Analyze trends over time
- Calculate aggregates across time windows
Parameters:
start/end: Time range (RFC3339 or Unix seconds)step: Resolution (e.g.,30s,1m,5m,1h)
Example: Query build durations over the last 24 hours with 1-hour resolution.
Authorization
access-token In: header
Query Parameters
MetricsQL / PromQL query expression
Range start (RFC3339 or unix seconds)
Range end (RFC3339 or unix seconds)
Step / resolution (duration, e.g. 30s, 1m)
Query timeout (duration), forwarded to VictoriaMetrics
Response Body
application/json
curl -X GET "https://example.com/sfp/api/metrics/query_range?query=sum%28rate%28sfp_build_duration_seconds%5B5m%5D%29%29&start=1734015600&end=1734019200&step=30s"{ "result": {}}/sfp/api/metrics/api/v1/query_rangeExecute a range query to get metrics over a time period with specified resolution.
Use Cases:
- Generate time-series data for charts
- Analyze trends over time
- Calculate aggregates across time windows
Parameters:
start/end: Time range (RFC3339 or Unix seconds)step: Resolution (e.g.,30s,1m,5m,1h)
Example: Query build durations over the last 24 hours with 1-hour resolution.
Authorization
access-token In: header
Query Parameters
MetricsQL / PromQL query expression
Range start (RFC3339 or unix seconds)
Range end (RFC3339 or unix seconds)
Step / resolution (duration, e.g. 30s, 1m)
Query timeout (duration), forwarded to VictoriaMetrics
Response Body
application/json
curl -X GET "https://example.com/sfp/api/metrics/api/v1/query_range?query=sum%28rate%28sfp_build_duration_seconds%5B5m%5D%29%29&start=1734015600&end=1734019200&step=30s"{ "result": {}}/sfp/api/metrics/label/{name}/valuesGet all distinct values for a specific label/tag across metrics.
Common Labels:
package: Package namesorg: Org aliasespipeline: Pipeline identifierssfp_metric_type: Metric type (count, guage, timers)__name__: Metric names
Use Cases:
- Populate filter dropdowns in dashboards
- Discover available dimensions for queries
Authorization
access-token In: header
Path Parameters
Query Parameters
Optional start time (RFC3339 or unix seconds)
Optional end time (RFC3339 or unix seconds)
Optional match[] selectors (repeatable)
Response Body
application/json
curl -X GET "https://example.com/sfp/api/metrics/label/string/values"{ "result": {}}/sfp/api/metrics/api/v1/label/{name}/valuesGet all distinct values for a specific label/tag across metrics.
Common Labels:
package: Package namesorg: Org aliasespipeline: Pipeline identifierssfp_metric_type: Metric type (count, guage, timers)__name__: Metric names
Use Cases:
- Populate filter dropdowns in dashboards
- Discover available dimensions for queries
Authorization
access-token In: header
Path Parameters
Query Parameters
Optional start time (RFC3339 or unix seconds)
Optional end time (RFC3339 or unix seconds)
Optional match[] selectors (repeatable)
Response Body
application/json
curl -X GET "https://example.com/sfp/api/metrics/api/v1/label/string/values"{ "result": {}}/sfp/api/metrics/ai-usageAggregate the AI usage recorded by the opencode metrics lane for one repository.
Returns distinct AI sessions, prompt counts (completed + failed), token totals (input/output/reasoning/cache), model turns, total time spent, and provider-reported cost over the requested window (default 30 days).
Sourced from the per-prompt usage records the engine emits for every AI feature run (cascade merge assist, architecture analysis, version assist, AI reports, …).
Authorization
access-token In: header
Query Parameters
Repository identifier (e.g. flxbl-io/sf-core or org/project/repo)
Aggregation window in days (default 30, max 90 — matches the log store retention)
30Response Body
application/json
curl -X GET "https://example.com/sfp/api/metrics/ai-usage?repositoryIdentifier=flxbl-io%2Fsf-core"{ "repositoryIdentifier": "string", "windowDays": 0, "sessions": 0, "prompts": 0, "promptsFailed": 0, "tokens": { "input": 0, "output": 0, "reasoning": 0, "cacheRead": 0, "cacheWrite": 0 }, "turns": 0, "durationMs": 0, "cost": 0}