Last reviewed: November 18, 2026 (Asia/Shanghai).
Give each CometAPI usage metric a fixed label schema, calculate its series budget per scraped target, and test the limit before rollout. Keep request IDs, customer IDs, and arbitrary model strings out of routine metric labels. Use small approved groups for monitoring, while retaining exact identifiers and usage evidence in the accounting records that support reconciliation.
Prometheus instrumentation guidance explains the cost: every distinct label set creates another time series consuming memory, CPU, disk, and network resources. Adding a label can therefore expand observability overhead without changing the number of paid model calls.
This guide is for platform engineers instrumenting a server-side CometAPI adapter. It covers the metrics the application emits; it does not assume CometAPI provides a Prometheus exporter. The budgets and acceptance checks below are proposed designs with synthetic numbers. No paid model request or production telemetry experiment was performed.
Decide which CometAPI details belong in metrics
Start with the decisions a dashboard must support: which workload is growing, whether attempts succeed, how token volume changes, and whether latency meets the service objective. Each metric needs only the dimensions required for its own question.
CometAPI’s chat-completion reference
documents completion identifiers, a response model that can include a version suffix, and a usage object. It also documents final streaming usage when stream_options.include_usage is enabled. Those response fields are inputs to the application’s instrumentation; their presence does not mean every field should become a label.
Use an explicit mapping at the adapter boundary:
| Detail | Monitoring treatment | Exact evidence retained elsewhere |
|---|---|---|
| Workload | Approved workload group, including an other bucket | Authorized workload and owner references |
| Requested and returned model | A small configured model_group | Both exact model identifiers |
| Attempt outcome | A fixed enumeration such as success, error, or unknown | Attempt identity and detailed outcome |
| Usage | Numeric token increments with a bounded token-kind label | Original usage categories and their units |
| Completion, request, or customer ID | Excluded from routine labels | Necessary opaque correlation references |
Resolve groups from trusted configuration. A caller-supplied workload string must not create a new label value automatically. Count unknown mappings in a bounded diagnostic metric and review them; recording each unknown raw value as another label recreates the problem.
Keep prompts, generated text, API keys, URLs with resource IDs, and raw error messages out of these labels. Hashing a unique identifier preserves its uniqueness, so it does not reduce cardinality. Exact model versions can remain available in the durable record while several approved versions share one monitoring group.
For streaming, count usage once when accepted final usage arrives. Intermediate text chunks are not separate usage observations. If the stream ends without usage, record the evidence gap and retain the unresolved attempt. The site’s guide to cost records independent of trace sampling covers the separate accounting path.
Calculate a ceiling for each metric family
For one target and one simple counter, the product of allowed label counts gives an upper bound on combinations. It is a planning ceiling: some combinations may never occur, while client-library auxiliary metrics and target labels require additional inventory.
Consider an illustrative schema with three workload groups, four model groups, three outcomes, and two token kinds. The workload and model counts already include their catch-all buckets. Use different label sets for different questions:
| Application metric | Labels | Maximum series per target |
|---|---|---|
cometapi_attempts_total | workload, model_group, outcome | 3 × 4 × 3 = 36 |
cometapi_tokens_total | workload, model_group, kind | 3 × 4 × 2 = 24 |
cometapi_attempt_duration_seconds as a classic histogram | workload, model_group, plus bucket boundary | 3 × 4 × 13 = 156 |
| Total for these three families | As defined above | 216 |
The histogram assumes ten finite bucket boundaries, the implicit +Inf bucket, _sum, and _count: thirteen series per workload/model combination. Prometheus’s histogram reference
documents separate classic bucket, sum, and count series. This calculation excludes optional auxiliary series such as _created, runtime metrics, and other exporters; inspect the actual exposition before approving the target’s full ceiling.
Eight targets exposing the same complete schema produce up to 1,728 application series at one collecting Prometheus server. Target identity distinguishes the copies. Additional environments, target revisions, or collectors can add their own footprint; write down the collection and billing scope before multiplying again.
Adding a 10,000-value customer label to all three families would allow 2.16 million combinations per target. That is a hypothetical Cartesian ceiling, not a forecast that every combination will exist. It demonstrates why a label requires an explicit operational benefit and a bounded value set.
For simple float series, 1,728 series scraped every 15 seconds imply approximately 9,953,280 samples per day, assuming each appears in every successful scrape. This excludes additional metrics and protocol-specific extras. Use the calculation to compare configurations, then measure actual ingestion.
Prometheus now recommends native histograms where the pipeline supports them. A native histogram uses one composite series per label set, so the classic thirteen-series multiplier does not apply. Its samples contain bucket data and still consume resources. Verify client, scraper, remote storage, and query support, and check whether classic and native forms are both being ingested during migration.
Enforce the schema before the scrape
Normalize labels before creating metric children in the application. That prevents arbitrary values from filling the process’s own metric registry. Give each family an owner, approved label names, allowed values, bucket layout, expected ceiling, and a review trigger for expansion.
Scrape filtering provides a second boundary. The current Prometheus configuration reference says metric relabeling runs immediately before ingestion. This illustrative fragment drops a fictional legacy counter and its creation-time series, then sets a per-target sample limit:
scrape_configs:
- job_name: cometapi-adapter
scrape_interval: 15s
sample_limit: 1000
static_configs:
- targets: ["adapter.internal:9100"]
metric_relabel_configs:
- source_labels: [__name__]
regex: cometapi_request_detail(_total|_created)
action: drop
Replace the target and inventory the entire endpoint before choosing the limit. The example’s 1,000 allows room beyond the 216 application series, but it is not a measured safe limit for any deployment. The drop rule removes matching samples from local ingestion; it cannot undo the application’s cost of constructing and serving them.
sample_limit applies after metric relabeling. Exceeding it makes the entire scrape fail. It does not retain the first 1,000 samples, and it does not cap the number of distinct series created over time. A target can expose fewer than 1,000 samples on every scrape while continuously rotating their labels.
The same reference warns that labeldrop and labelkeep must preserve unique labeling. Removing request_id from several independent request counters does not aggregate their values. It can collapse separate samples onto the same identity. Fix the instrumentation to increment one shared counter per approved label set; during containment, dropping the affected family is a clearer choice when its information is available through the required accounting path.
Detect a failed scrape and a growing label population
After a successful scrape, inspect the currently queryable application series:
count by (__name__) ({job="cometapi-adapter", __name__=~"cometapi_.+"})
Prometheus’s aggregation reference
defines count as counting vector elements. This query counts series across the selected targets at the evaluation time; it does not sum attempts or tokens. Compare its family totals with the schema, target count, and auxiliary metrics actually enabled.
Watch the collection boundary as well:
up{job="cometapi-adapter"} == 0
The official jobs and instances reference
defines up=0 for a failed scrape. It also documents scrape_samples_scraped, scrape_samples_post_metric_relabeling, and the approximate new-series count scrape_series_added. Inspect these per target, and configure missing-target detection against the expected inventory: a removed target may disappear rather than produce a current up=0 sample.
A stable instantaneous count can hide churn. Deploy-generated values or unique IDs that change every interval create successive identities even when each scrape has few samples. Monitor new-series behavior over a representative deployment and workload cycle. A slower scrape interval reduces observation frequency; it does not fix an unbounded label schema.
If a limit trips, mark the affected monitoring interval incomplete and inspect the target error. Keep billing reconciliation on its durable evidence path. A dashboard that loses series cannot establish reduced CometAPI consumption.
Prove the limit with synthetic traffic
Use a fake CometAPI response adapter and a disposable metrics registry. Keep real credentials out of this fixture. Then run an isolated scraper with the intended configuration. These are acceptance requirements, not reported test results:
| Exercise | Required observation |
|---|---|
| Generate 10,000 unique request and customer IDs within one approved group | IDs never appear as labels; the series count stops growing after the expected children exist |
| Exercise every allowed group and outcome | Family counts remain within the reviewed ceiling, including auxiliary series |
| Return many unrecognized model strings | They map to the existing catch-all group; detailed evidence remains available separately |
| Deliver streaming chunks followed by one accepted usage record | One usage contribution; chunk count does not multiply token increments |
| End a stream before usage arrives | A visible evidence gap; no fabricated zero usage |
| Expose more than the configured post-relabel sample limit | The isolated scrape fails and monitoring marks the gap |
| Rotate label values while staying below the per-scrape limit | New-series evidence reveals churn and the schema check rejects those values |
| Drop the legacy family | Remaining telemetry stays usable; required accounting records remain available |
Retain the metric declaration revision, target inventory, exposition sample, scrape error or success, observed family counts, and accounting completeness result. Roll out one adapter first, through a representative workload and deployment cycle, before expanding the schema across the fleet.
Approve the observability spend separately
Translate the measured series, samples, stored volume, and query load into the actual telemetry backend’s meters. A self-managed installation has infrastructure costs; a managed backend may charge by different units. No universal dollar value follows from the series count alone.
Keep the model-usage subtotal and monitoring overhead separately visible. If telemetry is shared, the site’s gateway cost-pool allocation guide explains how to distribute a reconciled overhead pool without counting it twice. Token volume is not automatically a good proxy for metric overhead: a low-token workload with unique labels can create substantial churn.
Choose one CometAPI adapter, inventory its metric families, and calculate their ceilings. Approve expansion only after bounded labels, complete scrape monitoring, and the synthetic checks pass. For a subsequent bounded route check, Start with CometAPI and compare the captured response evidence with the emitted metrics.
Sources checked
Six primary public references returned HTTP 200 during live research on November 18, 2026, UTC and Asia/Shanghai:
- Prometheus: Instrumentation — label-set resource costs and reducing unnecessary dimensions.
- Prometheus: Histograms and summaries — classic bucket expansion, native composite series, and current histogram guidance.
- Prometheus: Configuration — metric relabeling, whole-scrape failure on sample-limit excess, and uniqueness after removing labels.
- Prometheus: Operators
—
countand grouping semantics for the inspection query. - Prometheus: Jobs and instances
— target labels,
up, scrape sample counts, and approximate new-series measurements. - CometAPI: Create a chat completion — response identifiers, returned model versions, usage fields, and final streaming usage.
These currently served official references support an evergreen instrumentation task. No page-specific revision date was visible in the retrieved material. Match configuration and histogram behavior to the Prometheus version actually deployed. The grouping policy, numerical budgets, and rollout checks are recommendations derived from the documented interfaces.