Skip to content

Public trace, evaluation and evaluator API

Last updated: 2026-11-27T14:39:27-03:00 (UTC-3)

Application spans over OTLP · Traces and the span store · Query language · Evaluation results · Prompt clients

The console reads traces, results and evaluators with a session. Code outside the console (a CI job, an external evaluator, a notebook) reads them with a key of a team. With public_trace_api a key reads its team’s traces and spans, its evaluation results and its evaluators, and keeps evaluators as code from CI. The key never names a team: it reaches its own team only, and every read filters by that team (and its current organization) before it counts, pages or builds a tree.

features:
span_store: true # required
public_trace_api: true # tenant flag; under plan entitlements the team's plan must include it
evaluation_results: true # for GET /v1/evaluations

Then create keys with the scopes each job needs, on the team it works for:

Scope Allows Endpoints
traces:read Read traces and spans GET /v1/traces, GET /v1/traces/{trace_id}
evaluations:read Read evaluation results, also attached to traces (fields=evaluations) GET /v1/evaluations
evaluators:read Read evaluators GET /v1/evaluators, GET /v1/evaluators/{name}
evaluators:write Save and publish evaluators (also reads them) POST /v1/evaluators, PUT /v1/evaluators/{name}, POST /v1/evaluators/{name}/publish
reviews:read Read the team’s review queues, their items and comment threads GET /v1/review-queues, GET /v1/review-queues/{id}, GET /v1/review-queues/{id}/items, GET /v1/comments
reviews:write Add items, review them as one more annotator, comment (also reads) POST /v1/review-queues/{id}/items, POST /v1/review-queues/{id}/next, POST /v1/review-queues/{id}/annotations, POST /v1/comments
scores:write Write results (already available) POST /v1/scores
traces:write Send application spans, and nothing else POST /v1/traces (OTLP ingest)

Keep reading and writing apart: an exporter’s traces:write key gets 403 on every read here, and a reader cannot ingest. Every call counts in the key’s requests-per-minute policies. A key is never a content reader: no message content, judge reasoning, tool names, price entries or console identities leave through this API.

Terminal window
# The last 15 minutes of provider attempts, cursor by cursor
curl -sS "https://gateway.example.com/v1/traces?scope=spans&from=-15m&q=span.kind:provider_attempt&limit=100" \
-H "Authorization: Bearer <key with traces:read>"

GET /v1/traces takes:

Parameter Default Meaning
scope traces traces (one row per trace) or spans
q none A query of the query language: span.kind:app issue:invalid_tokens, origin:app model:gpt-4o-mini, session:c-1042. Evaluation terms need evaluations:read; full-text terms are not available to keys
from, to the last 24 hours RFC 3339 times; from also takes a negative duration (-15m, -2h). At most 92 days apart
limit 50 1 to 200
cursor none next_cursor of the previous page
fields core,cost core (always), cost (with usage_valuation), evaluations (needs evaluations:read), attributes (spans only)

The answer has data, has_more and next_cursor. A read of 100,000 spans is 500 pages of 200; each page is one indexed query, so it never times out.

GET /v1/traces/{trace_id} returns the team’s spans of one trace (at most 2,000, truncated says when there are more), the trace summary and app_totals (the application’s own model spans the gateway did not serve, see cost). fields: core, cost and attributes by default; evaluations adds the trace’s results, each also on the span it judged. fields=core,cost returns no attributes.

Terminal window
curl -sS "https://gateway.example.com/v1/evaluations?q=name:helpfulness%20assessment:fail&limit=50" \
-H "Authorization: Bearer <key with evaluations:read>"

q takes space-separated key:value terms, and the same keys as parameters: name, source, assessment, status, evaluator (ID), metric_type, trace_id, span_id, request_id, session, run. from and to bound the time a result was written. Results come newest first with a cursor. A result carries its value, assessment, status, target, evaluator and version, and the judge’s trace and cost; never the judge’s reasoning (reasoning_state: withheld says one exists), the console user who wrote it, or a comment.

Keep evaluator definitions in your repository and apply them from CI with a key that holds evaluators:write:

Terminal window
curl -sS -X PUT https://gateway.example.com/v1/evaluators/helpfulness \
-H "Authorization: Bearer <key with evaluators:write>" -H "Content-Type: application/json" \
-d '{"judge_model":"judge","prompt":"Rate how helpful the answer {{output}} is to {{input}}.","output":{"data_type":"numeric","min":0,"max":1,"pass":{"op":"gte","value":0.7}},
"scope":"span","filter":"span.kind:request model:support-model","sample_rate":0.1}'
curl -sS -X POST https://gateway.example.com/v1/evaluators/helpfulness/publish -H "Authorization: Bearer <key with evaluators:write>"
  • PUT /v1/evaluators/{name} saves the definition as a new draft version of the team’s evaluator with that name, or creates it (201). Live traffic keeps running the published version until you publish. The body is the same definition the console saves (type, prompt and route, rule or code, output and pass criteria, scope, filter, sample rate, runs on, daily ceiling, idle windows), validated the same way.
  • POST /v1/evaluators/{name}/publish publishes the latest version, or {"version": n}. The same checks as the console: a judge that calls a model needs a filter, a daily ceiling needs a priced route, a template placeholder must be filled.
  • GET /v1/evaluators lists every type, decision models and code evaluators included; GET /v1/evaluators/{name} returns one with its definition, version, published version and updated_by.
  • Every write is audited in the evaluator’s history with key:<key id> as the actor. An evaluator declared in the gateway YAML (managed_by: yaml) is refused with 409.

The prompt clients in clients/ (Python, TypeScript and Go, dependency-free, server-side) carry the same calls, with the same transport rules: HTTPS unless loopback, no ambient proxy, no redirects, bounded answers, and errors that keep only the status, the gateway’s error code and the request ID.

from m7gtw_prompts.observability import ObservabilityClient
gw = ObservabilityClient("https://gateway.example.com", key)
trace = gw.get_trace(trace_id, fields=["core", "evaluations"])
for span in gw.iter_spans(q="origin:app span.kind:request", start="-1h"):
verdict = my_evaluator(span) # your own evaluation
gw.submit_score("groundedness", value=verdict, trace_id=span["trace_id"], span_id=span["span_id"])
gw.put_evaluator("helpfulness", definition) # a new draft version
gw.publish_evaluator("helpfulness")
gw.ingest_spans(otlp_export_dict) # or protobuf bytes
import { ObservabilityClient } from "m7gtw-prompts";
const gw = new ObservabilityClient("https://gateway.example.com", key);
for await (const span of gw.iterSpans({ q: "span.kind:app", from: "-1h" })) { /* ... */ }
await gw.submitScore("helpfulness", { value: 0.9, traceId, spanId });
c, _ := prompts.New("https://gateway.example.com", key)
var trace map[string]any
err := c.GetTrace(ctx, traceID, []string{"core", "evaluations"}, &trace)
err = c.PutEvaluator(ctx, "helpfulness", definition, nil)

run_experiment (Python) runs your application on every item of a dataset, links each output to one new run (POST /v1/dataset-run-items, with the gateway request it made when your task returns request_id), and posts each of your evaluators’ verdicts as a result on the run item. The run and its results appear in Evals → Runs beside the gateway’s own evaluators. Read a run back with GET /v1/datasets/{name}/runs/{run}?fields=evaluations,cost,trace: each item with its results, its ledger cost and its trace ID. The key needs evals:read, evals:write and scores:write.

def task(item_input):
r = call_my_app(item_input) # through the gateway
return {"output": r.text, "request_id": r.headers["X-Request-Id"]}
run = gw.run_experiment("support-questions", "nightly-2026-11-26", task,
{"exact_match": lambda item, out: out == item.get("expected_output")})

create_agent_eval, record_agent_results and get_agent_eval (Python) call the agent evaluation API; the runner m7gtw_prompts.agent_eval drives them: tasks × targets × trials run on your machine, each trial one trace, and the scorecard read back from the gateway.

Any library that produces a score per example can write it to the span, trace or run item it judged with POST /v1/scores (or submit_score), with source: api and the evaluator’s name. For example, with DeepEval, NeMo Evaluator or Pydantic Evals, run the metric in your CI and post each result:

# DeepEval: one metric per traced request
metric.measure(test_case)
gw.submit_score("answer_relevancy", value=metric.score, trace_id=tid, span_id=sid, metric_type="score",
assessment="pass" if metric.is_successful() else "fail")
# NeMo Evaluator or Pydantic Evals: one row per example of a report
for row in report_rows: # each with the run item it scored
gw.submit_score(row["metric"], value=row["score"], run_item=row["score_target"])

The results are stored like any other: on the span, filterable with evaluation.<name>, in the Quality view and in monitors.

A review job outside the console (a labelling tool, a CI step, an external annotator) works the team’s review queues with a key of reviews:write. The key reviews as one more annotator, key:<id>, under exactly the queue’s rules: one seat per reviewer, held for the queue’s lock_timeout_seconds; at most annotators_per_item reviewers on an item; the item completes with the last review, and its final values and disagreement are computed as for the console. A console reviewer and a key on the same item are two annotators.

Terminal window
KEY="Authorization: Bearer <key with reviews:write>"
# Queue the team's request, take a seat, annotate
curl -sS -X POST https://gateway.example.com/v1/review-queues/queue_1/items -H "$KEY" -H "Content-Type: application/json" \
-d '{"targets":[{"type":"request","id":"req_123"}]}'
curl -sS -X POST https://gateway.example.com/v1/review-queues/queue_1/next -H "$KEY"
curl -sS -X POST https://gateway.example.com/v1/review-queues/queue_1/annotations -H "$KEY" -H "Content-Type: application/json" \
-d '{"target_type":"request","target_id":"req_123","scores":[{"name":"helpful","value":1}]}'
# Comment on it
curl -sS -X POST https://gateway.example.com/v1/comments -H "$KEY" -H "Content-Type: application/json" \
-d '{"target_type":"request","target_id":"req_123","content":"Checked by CI"}'

What a key may do is what a console credential session may do:

Rule Why
A key reviews only queues and items assigned to nobody (403 not_assigned otherwise); it may still add items to an assigned queue, for its people to review Assignees are named people; a key is never one
A key never takes an item another reviewer holds (409 item_locked) It has no reviews:assign
A key reads its own review whole; another reviewer’s shows its status only, never who; the finals are not shown, disagreement is, as to a console reviewer Console identities, others’ answers and finals are for the people who calibrate
A key reads no target content here: a trace or span target is read with GET /v1/traces under traces:read A key is never a content reader of captured requests
A comment by a key names the key; a person’s says person. A key mentions nobody; threads are on a request, a session or a run item Mentions notify console users, whom a key does not know

Every write is the key’s: results with key:<id> as their author, items with key:<id> as who added them, comments audited. The review routes need public_trace_api and evals, not span_store: a queue of requests, sessions or run items reads no span.

Evaluation results do not grow forever. With evaluation_result_retention (operator control, off by default) and metadata retention on with a window, a background pass removes in bounded batches the results and the dataset runs (with their items and item results) older than metadata_retention.retain_days. It keeps:

  • human annotations, and the results of a trace or request that has one;
  • the results of traces kept in the span store’s retained copy (traces with an annotation, a review queue item or a dataset item);
  • datasets and their items: curated ground truth is never telemetry;
  • runs still running.

It stops during a legal hold, like the metadata retention, and every pass that removed something is audited (eval.result_retention.purge). GET /api/v1/admin/evaluations/retention shows the window, the last pass and the totals. Spans follow spans.retention_days on their own. On the analytics store engine the automated results there are removed by the same rule.

404 feature_disabled when public_trace_api or span_store is off, to every caller before the key is read, as the other flagged public routes answer (datasets, prompts, vector stores, agents); 401 without a valid key; 403 scope_forbidden without the scope (also fields=evaluations without evaluations:read); 404 feature_disabled when, for results, evaluators and reviews, evals, evaluation_results or the evaluator flags are off; 403 team_required for a key without a team; 429 past a rate policy; 400 invalid_query, invalid_range or invalid_request for a malformed parameter; 404 trace_not_found or evaluator_not_found for an object the team does not have, whoever else has one.

m7gtw[email protected]