Skip to main content

Create custom-trace run

Endpoint: POST /runs/custom-trace

Description Creates a run when you pass inline traces and a metric list. Each evaluations[] group has metrics (shortname strings or metric objects) and data (one item = one trace). The server persists each item as a custom trace, then expands metrics onto those traces.

Whole-trace metrics (for example plan_adh, task_comp) score the full trace — omit spans. Span-scoped metrics (for example tool_select) score one OTLP span per evaluation. Send a non-empty spans list of hex span ids from that item, or omit spans to score every span that metric can (for tool_select, every LLM span). Span ids belong to one trace, so a group where any metric names spans must have exactly one data item — send each trace in its own group (400 otherwise). Omitted spans expand across every item in the group. One evaluation is created per (trace, metric spec, span-or-none). A named span must be a kind the metric scores (tool_select scores LLM spans); naming a span recorded as another kind, such as a TOOL span, returns 400. A span with no openinference.span.kind is accepted when named. Duplicate shortnames are allowed: two tool_select objects with different spans / metric_args are independent specs. A metric may reach each span, and each whole trace, once: two specs that reach the same span of one trace, or a whole-trace metric listed twice for one trace, return 400 rather than billing the same target twice. The same traceId sent in two groups is one stored trace, so this applies across groups too.

Credit checks use the expanded evaluation count, not only the number of distinct shortnames. number_of_metrics on the created run is still the count of distinct shortnames; evaluations.length can be larger (two single-trace groups, each with two tool_select specs naming one different span each = four evaluations, with number_of_metrics: 1). A run that expands to zero evaluations returns 400.

Expansion is all-or-nothing: every data item must expand to at least one evaluation. If any single item matches no eligible span (for example, a tool_select group where one trace has no LLM spans), the whole run returns 400 and nothing is persisted or charged — unmatched items are not skipped. The detail names the first unmatched item (evaluations[<group>].data[<item>][, external_id=<id>]). An item counts as matched when any metric in its group targets it, so a whole-trace metric in the group always matches. When sending large batches, drop traces that have no eligible spans before calling.

The run row itself has trace_id: null and dataset: null (run_type label "Custom Trace"). Each evaluation names the inline trace it scored the way you sent it: evaluations[].trace_id is that item's 32-char lowercase hex OTLP traceId, span_id is the hex span it scored (or null for a whole-trace metric), and external_id is the item's external_id (or null). Those traces are stored with trace_source: "CUSTOM" and appear on GET /traces like ingested captures — filter with trace_source_names=CUSTOM. Share, unshare, file, and project-assign them with PUT /traces/{trace_id}. Deleting the run still removes custom traces that no other run scores; a trace another run still scores stays until the last run that scores it is deleted. One traceId holds one source per scope — first source wins. A custom trace never merges with an ingested capture of the same traceId; creating a custom row for a traceId already ingested in that scope is 400, and a later ingest of a traceId already stored as custom is dropped (OTLP partialSuccess — see Ingest traces). Score a stored custom trace again with POST /runs/trace.

Sharing rules

The new run is always owned by you (your account is the individual owner). Sharing isn't accepted directly on this endpoint — visibility is derived from the data collection (if any), from an optional project_id, or from a project-scoped API key. Create placement matches custom runs. After create, the run is a subject run: it snapshots organization, collection, and project from that request and cannot change them. Later share, unshare, file, or project-assign the custom traces with PUT /traces/{trace_id}, the same as ingested captures.

  • Without data_collection_id:
    • Private (org_id = null, no project) when you use a private API key and omit project_id.
    • Org-shared and assigned to a project when you use a project-scoped API key (the key's project is applied and the run is org-shared automatically). A private key cannot org-share via project_id alone. See Introduction — API key scoping.
  • With data_collection_id:
    • The collection is loaded via claim semantics. When claimable, the run is created shared or private according to the collection's org_id and inherits the collection's project. You must still be a member of that organization when the collection is org-shared. Unassigned org collections can be claimed into the key's project; a collection already assigned to a different project returns 403. A project-scoped API key cannot use a private collection (org_id is null): the request returns 400 with detail Data collection must be shared with the organization before it can be added to a project.
    • Do not send project_id when linking to a collection — assign the collection to a project instead (400 if you try).

Each persisted inline trace starts with the same organization, collection, and project as the run, then moves independently via PUT /traces/{trace_id}. After create, place the traces, not the run. Score a stored custom row again with POST /runs/trace.

Use PUT /runs/{run_id} to rename a custom-trace run (alias only). Share, unshare, file, or project-assign its inline traces with PUT /traces/{trace_id} — sending placement fields on the run returns 400.

External IDs

Each object in evaluations[].data[] may include an optional external_id (string, max 255 characters). This is your stable handle for the conversation in your own systems. It is stored on the trace's own external_id field and echoed on every evaluation of that item as evaluations[].external_id, so you can match results back to the request without the hex trace_id. The trace name stays the root span name, and renaming the trace with PUT /traces/{trace_id} does not change external_id. Omit it when you do not need correlation.

Duplicate traceIds

A later custom-trace run that sends a traceId already stored as a custom trace is 400, not an overwrite. Delete the last run that scores the row first, or send a new traceId.

  • A personal create (no organization on the run) that re-sends one of your unshared custom traces returns 400 with "A trace with this id already exists for your account."
  • Creating into an organization also refuses your personal copy of that traceId and any custom trace already shared in the organization (yours or a teammate's). That returns 400 with "A trace with this id is already shared with your organization." Sharing a stored custom trace into the organization uses PUT /traces/{trace_id} and hits the same collision.
  • A traceId you already sent through OTLP ingest in the same scope is refused too: score the stored trace with a trace run instead of re-sending it inline. That returns 400 with "A trace with this id was already ingested; score it with a trace run instead."

Each of these 400s lists the colliding traceIds (hex, up to 10, then and N more) after a colon, for example "A trace with this id was already ingested; score it with a trace run instead: 0af7651916cd43dd8448eb211c80319c." When a batch hits both kinds, the detail carries both sentences.

Span shape

data[].spans is the same span object OTLP ingest accepts (camelCase keys, hex traceId / spanId, attributes, clocks), and it is validated the same strict way. A snake_case key (parent_span_id), an unknown field (a typo such as parentSpanID or attribute), a wrong JSON type, or an unknown kind / status.code name returns 400. Without this check, a typo such as parentSpanID would silently drop the parent, and the span would be stored as a second root. The server wraps each item in the OTLP resource/scope envelope and maps it through the ingest mapper — this is not a third span format. An item that maps to no persistable span, or that drops any span (malformed, duplicate id, parent cycle), returns 400 (a run subject is not ingest partialSuccess). The 400 detail includes the mapper's rejection reasons. Every per-item 400 ends with the item's location: (evaluations[<group>].data[<item>][, external_id=<id>]). Spans in one item must belong to a single OTLP trace (400 if they map to more than one). A span id named on a metric must exist on that item; an id from trace A is not valid on trace B (400 These span ids are not on this trace: … (evaluations[<group>].data[<item>][, external_id=<id>]). for the whole run — missing ids are not skipped).

Parameters

  • Body — application/json:
{
"threshold": "0–100 | null",
"model_slug": "string | null",
"reasoning_level": "string | null",
"is_blocking": false,
"data_collection_id": "integer | null",
"project_id": "integer | null",
"alias": "string | null",
"evaluations": [
{
"metrics": [
"string (metric shortname)",
{
"metric": "string (metric shortname)",
"metric_args": "object | null",
"threshold": "0–100 | null",
"model_slug": "string | null",
"reasoning_level": "string | null",
"spans": ["OTLP hex span id", "..."]
}
],
"threshold": "0–100 | null",
"model_slug": "string | null",
"reasoning_level": "string | null",
"data": [
{
"external_id": "string | null",
"spans": [
{
"traceId": "<32 hex chars>",
"spanId": "<16 hex chars>",
"parentSpanId": "<16 hex chars or omitted>",
"name": "workflow step",
"kind": "SPAN_KIND_INTERNAL",
"startTimeUnixNano": "1735732800000000000",
"endTimeUnixNano": "1735732800123000000",
"attributes": [
{
"key": "openinference.span.kind",
"value": { "stringValue": "LLM" }
}
],
"status": { "code": "STATUS_CODE_OK" }
}
]
}
]
}
]
}

Unknown fields on the run, an evaluation group, a data item, or a metric object are rejected (extra: forbid). A typo such as span instead of spans is 422, not a silent expand to every scoreable span. Custom runs use the same MetricSpec and also reject unknown keys. data_collection_id and project_id must be JSON integers. A digit string ("74"), a whole-number float (1.0), or a boolean (true / false) returns 422 before lookup. Both are optional: JSON null and omitting a field stay valid. threshold still accepts a digit string. An empty metrics list, an empty data list, or an empty spans array on a data item is 422. evaluations is capped at 1000 groups, each group's data at 1000 items, and each item's spans at 1000. The body is also capped at 1000 spans in total across every item (422 if any of these is over), so several groups cannot multiply past the ceiling. Counts do not bound bytes, so the request body is also capped at 4 MiB, the same ceiling as trace ingest. A larger body is 413 before it is parsed: refused from Content-Length before it is read, or measured once read when the header is absent (chunked) or understated.

model_slug

  • Optional run default. When omitted, the server uses gpt-5.6-luna with reasoning level none. That model (or the one you pass) is used for every LLM step unless an evaluation group or metric object overrides it.

reasoning_level

  • Optional at three levels: on the run, on each evaluation group (evaluations[]), and on each metric object (object form only). Same precedence as custom runs: metric object → evaluation group → run.
  • Do not send OpenAI's reasoning_effort on the run root, an evaluation group, a metric object, or an inline trace item root — Aegis uses reasoning_level. Those containers return 422 (Use 'reasoning_level' to set reasoning effort, not 'reasoning_effort'.). Span dicts inside data[].spans may still contain reasoning_effort.

Each item in metrics is either a metric shortname (string) or a metric object. The object is the same MetricSpec as a trace run and a custom run: threshold, metric_args, and optional spans, plus metric (the shortname, because this payload is a list) and optional per-metric model_slug and reasoning_level. Metric identifiers must be shortnames — numeric metric ids are rejected. The same shortname may appear twice in one list (two tool_select specs naming different spans, each with its own metric_args) — that is how arguments vary per span; there is no span_metric_args. Record-scoped metrics (single input/output) cannot be used (400). Whole-trace metrics must omit spans (400 if present). Span-scoped metrics may name OTLP ids or omit spans to expand on kind.

spans on a metric object is the same OTLP hex list as on trace runs (16-character lowercase hex, optional 0x prefix, no duplicates, empty array rejected). Named ids are matched against the group's single data item; a group that names spans and carries more than one item is 400. An omitted spans list that matches no eligible span on one item is 400 for the whole run (same as a named id missing on one item).

threshold (run-level)

  • Optional. Integer in 0–100. The same bound applies to each evaluation group's threshold and each metric object's threshold. When omitted (or null), the run threshold is 80. Each evaluation uses the metric object's threshold if set, otherwise that evaluation group's threshold, otherwise the metric's catalog default.

is_blocking

  • false (default) — The run, traces, and evaluation records are saved, then scoring starts in the background; the 201 response returns right away. Results may still be missing in that payload — poll GET /runs/{run_id} until evaluations complete.
  • true — The API waits until every evaluation for this run has been executed. Totals and billing settle once for the whole run (not once per inline trace).

Once the run is saved, a failure while scoring or reloading it no longer returns 500: the API still returns 201 with the run as saved, so a retry never duplicates a billed run. Scores may be missing in that response — check GET /runs/{run_id}.

Error responses

  • 401, 402 — authentication or insufficient balance (charged per expanded evaluation).
  • 403 — API key scoping violation (project_id in the body conflicts with a project-scoped key, collection already assigned to a different project).
  • 422 — request validation failed. data_collection_id and project_id must be JSON integers. A run-level, evaluation-group, or per-metric threshold outside 0–100 is also rejected. An empty metrics list or empty data list on an evaluation group. Invalid spans on a metric object, an empty spans array on a data item, more than 1000 evaluation groups, more than 1000 items in an evaluation group's data, more than 1000 spans on a data item, or more than 1000 spans across the whole body. Unknown fields, including a typo such as span instead of spans on a metric object. A reasoning_effort key on the run root, an evaluation group, a metric object, or an inline trace item root is rejected (Use 'reasoning_level' to set reasoning effort, not 'reasoning_effort'.).
  • 400 — empty evaluations; unknown or inactive metric shortnames; deactivated model_slug values; record-scoped metrics (These metrics score a single input and output and cannot be run on a trace: <shortnames>.); whole-trace metric with spans (These metrics score the whole trace and do not take a spans list: <shortnames>.); a snake_case span key (OTLP/JSON field names must be camelCase; received '<key>' (evaluations[<group>].data[<item>][, external_id=<id>]).); a span with an unknown field, a wrong JSON type, or an unknown enum name (Invalid OTLP span: <reason> (evaluations[<group>].data[<item>][, external_id=<id>])., where <reason> names the field and spans[<index>]); a data item with no persistable spans (This trace item did not contain any persistable spans: <reasons> (evaluations[<group>].data[<item>][, external_id=<id>]).); a data item that dropped any span (This trace item contained unpersistable spans: <reasons> (evaluations[<group>].data[<item>][, external_id=<id>]).); spans from more than one OTLP trace in one item (Each data item must contain spans from a single trace (evaluations[<group>].data[<item>][, external_id=<id>]).); a metric that names spans in a group with more than one data item (Metrics that name spans need exactly one data item in their evaluation group, because span ids belong to one trace. Send each trace in its own group, or omit spans to score every eligible span (evaluations[<group>]: <shortnames>).); named span id not on that item (These span ids are not on this trace: <ids> (evaluations[<group>].data[<item>][, external_id=<id>]).); named span of a kind the metric does not score (<shortname> scores only <kinds> spans, not: <id> (<kind>), … (evaluations[<group>].data[<item>][, external_id=<id>]).); one metric reaching the same target of one trace twice (These metrics score the same target more than once: <shortname> on span <id> | <shortname> on the whole trace, …. A metric scores each span, and the whole trace, at most once; give repeated specs different spans (<every item that sent that trace, joined by "; ">).); a data item whose omitted spans matched nothing while another item matched (No spans matched the selected metrics on this trace (evaluations[<group>].data[<item>][, external_id=<id>]).); no evaluations after expand (No spans matched the selected metrics on these traces.); project_id sent with data_collection_id; a project-scoped key with a private data_collection_id; duplicate alias; invalid reasoning_level; a re-sent traceId already stored as a custom trace (see Duplicate traceIds above): "A trace with this id already exists for your account." on a personal create, "A trace with this id is already shared with your organization." when creating into an organization; a traceId already ingested in the same scope ("A trace with this id was already ingested; score it with a trace run instead.").
  • 413 — "The request body exceeds the maximum accepted size." — body over 4 MiB, declared in Content-Length or measured after read. Returned before validation, so it takes precedence over 422.
  • 404 — one or more referenced model_slug values are not documented model slugs; data_collection_id not found or not claimable.
  • 500 — failure while creating the run.

Responses

  • 201 — same run object shape as Get run, with run_type: "Custom Trace", trace_id: null, dataset: null, and evaluations with record: null, hex trace_id, and the item's external_id. As a subject run, permissions.can_share, can_assign_project, and can_move_collection are false. Flag meanings: Introduction — Permissions.

Agentic metrics

Use these shortnames in metrics (or in object form metric). Whole-trace metrics omit spans; span-scoped metrics omit spans to score every eligible span, or list OTLP hex ids from that data item.

Whole trace

Single span

curl

curl -X POST "https://api.aegisevals.ai/api/v1/runs/custom-trace" \
-H "Authorization: Bearer sk_00000000000000000000000000000000" \
-H "Content-Type: application/json" \
-d '{"alias":"checkout-agent-regression","evaluations":[{"metrics":["task_comp",{"metric":"plan_adh","metric_args":{"expected_plan":"..."}},{"metric":"tool_select","spans":["37bb383b4dead09f"],"metric_args":{"expected_tools":["search_orders"]}},{"metric":"tool_select","spans":["bce7b7d39f47b947"],"metric_args":{"expected_tools":["bla_bla"]}}],"data":[{"external_id":"conv-123","spans":[{"traceId":"e4b045959556f1c4225d6c17d66340c3","spanId":"37bb383b4dead09f","name":"agent","startTimeUnixNano":"1735732800000000000","endTimeUnixNano":"1735732800123000000","attributes":[{"key":"openinference.span.kind","value":{"stringValue":"LLM"}}]}]}]}]}'