---
title: "Config versions"
subtitle: "Label traces with the config that produced them, then compare live behavior scores across versions in one call."
---

When you change your agent's setup, such as its prompt, model or tool calling, you want to know whether production got better or worse. Send the config and its version as metadata on every trace, using any keys you like, and Respan's [behaviors](/docs/documentation/features/pulse/behaviors) score each trace as it arrives. Then group by the metadata key that holds the version: one call returns a list with each version's trace count, behavior counts, average final score, cost and duration.

**Example:** you send `"config": "support-bot"` and `"version": "v2"` with a new system prompt. An hour later you filter on `config = support-bot`, group by `version`, and see the average final score go from 0.41 (`v1`) to 0.76 (`v2`), with **Refusal** dropping from 6 of 6 traces to 0.

This compares **one config over time**. To send live traffic to two models at once, use an [A/B test](/docs/ai-gateway/observability/ab-tests) instead.

## Label your traces

<Steps>
<Step title="Check behaviors are on">

Behaviors must be on for your organization. See [Behaviors](/docs/documentation/features/pulse/behaviors). Only new traces are scored, so label your traffic before you change the config.

</Step>
<Step title="Send the version as metadata">

Pick your own keys. Here `config` names what you version and `version` is the version. Change `version` each time you ship a change.

<Tabs>
<Tab title="Gateway">
```python
response = client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Where is my order #8812?"}],
    extra_body={"metadata": {"config": "support-bot", "version": "v2"}},
)
```
</Tab>
<Tab title="Tracing">
```python
from respan import Respan, propagate_attributes

Respan()

with propagate_attributes(metadata={"config": "support-bot", "version": "v2"}):
    ...  # your LLM calls
```
</Tab>
<Tab title="Create span API">
```bash
curl -X POST "https://api.respan.ai/api/request-logs/" \
  -H "Authorization: Bearer $RESPAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "log_type": "chat",
    "trace_unique_id": "3f6c2a1e9b7d4c58a0e1f2d3c4b5a697",
    "input": [{"role": "user", "content": "Where is my order #8812?"}],
    "output": {"role": "assistant", "content": "It shipped yesterday and arrives Friday."},
    "metadata": {"config": "support-bot", "version": "v2"}
  }'
```

Send a new `trace_unique_id` for each conversation. Without it, the span is logged but isn't a trace, so it's left out of traces summaries and comparisons.
</Tab>
</Tabs>

If you manage prompts in Respan, you don't need to send anything: group by `prompt_version_number` instead (see [Request options](#request-options)).

</Step>
</Steps>

## Compare versions

Call the traces summary with `group_by` set to the metadata key that holds the version. Add `filters` to narrow it to one config. Pick the behaviors to score with `behavior_columns`: include the ones your change is meant to move, and read each behavior's rate, not only the final score (see [Choosing behaviors](#choosing-behaviors)).

```bash
curl -X POST "https://api.respan.ai/clickhouse/traces/summary/?group_by=metadata__version&start_time=2026-11-24T04:00:00Z&end_time=2026-11-24T06:00:00Z" \
  -H "Authorization: Bearer $RESPAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filters": {"metadata__config": {"operator": "", "value": "support-bot"}},
    "behavior_columns": ["refusal", "task_complete", "instruction_miss"],
    "is_including_behavior_final_score": true
  }'
```

With `group_by`, the response is a paginated list, like other list endpoints. Each result is the usual traces summary for one version, with the version in `metadata`. Results are ordered by when each value first appeared, so versions come in the order you shipped them. Trimmed:

```json
{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "metadata": {"version": "v1"},
      "total_count": 6,
      "total_cost": 0.000108,
      "total_duration": 3.38,
      "errored_trace_count": 0,
      "behavior_summary": {
        "is_available": true,
        "unavailable_reason": null,
        "total_count": 6,
        "true_counts": {"refusal": 6, "task_complete": 0, "instruction_miss": 1},
        "scored_counts": {"refusal": 6, "task_complete": 6, "instruction_miss": 6},
        "scored_trace_count": 6,
        "average_final_score": 0.410915
      }
    },
    {
      "metadata": {"version": "v2"},
      "total_count": 6,
      "total_cost": 0.000108,
      "total_duration": 5.12,
      "errored_trace_count": 0,
      "behavior_summary": {
        "is_available": true,
        "unavailable_reason": null,
        "total_count": 6,
        "true_counts": {"refusal": 0, "task_complete": 5, "instruction_miss": 2},
        "scored_counts": {"refusal": 6, "task_complete": 6, "instruction_miss": 6},
        "scored_trace_count": 6,
        "average_final_score": 0.758126
      }
    }
  ]
}
```

`v2` raised the average final score by 0.347, and **Refusal** went from 6 of 6 traces to 0.

Group by any metadata key you send, not only a version: a customer tier, a region, an experiment name. Traces without the key aren't in any result. For the total over every trace, make the same call without `group_by`. To compare the same config before and after a change you didn't version, leave out `group_by` and call twice with two time ranges, split at the moment you shipped.

## What the numbers mean

Each result has the usual traces summary fields (`total_count`, `total_cost`, `total_tokens`, `total_duration`, `errored_trace_count`, and more) and a `behavior_summary` object.

| Field | Meaning |
| --- | --- |
| `metadata` or `prompt_version_number` | The result's value of the `group_by` key. |
| `total_count` | Traces that match the filters and have that value. |
| `true_counts` | Per behavior: traces where it was detected. |
| `scored_counts` | Per behavior: traces that have a verdict on it. Traces not scored yet aren't counted. |
| `scored_trace_count` | Traces with a final score: at least one selected Issue or Win behavior scored. |
| `average_final_score` | 0 to 1, higher is better. For each trace, a Win behavior counts its confidence `p` and an Issue behavior counts `1 - p`, averaged with equal weight; Info behaviors are left out. Then averaged over `scored_trace_count`. `null` when nothing is scored yet. |
| `is_available`, `unavailable_reason` | When `is_available` is `false`, the counts are `null`, never 0. |

Derived numbers you compute yourself:

| Number | How |
| --- | --- |
| Behavior rate | `true_counts[b] / scored_counts[b]` |
| Change between versions | Subtract one result's value from the other's. There's no built-in delta. |
| Average cost and duration | `total_cost / total_count` and `total_duration / total_count` |

For which behaviors are Issues, Wins, or Info, see [Built-in behaviors](/docs/documentation/features/pulse/behaviors#built-in-behaviors). Custom behaviors use the type you gave them.

### Choosing behaviors

`average_final_score` only counts Issue and Win behaviors. An Info behavior such as **Refusal** has its own rate but never moves the score. So a version that refuses everything can still score well if it trips no Issue behavior. For example, a config that refuses every request can score 0.61 while a helpful one scores 0.32, when **Task complete** isn't decisive. Always include **Task complete** (a Win) and the behaviors your change targets, and compare their rates. For your own definitions, create [custom behaviors](/docs/documentation/features/pulse/behaviors#create-a-custom-behavior) and pass their IDs.

## Request options

`start_time`, `end_time`, `group_by`, `page` and `page_size` go in the query string. The rest go in the JSON body.

| Option | Values | Notes |
| --- | --- | --- |
| `start_time`, `end_time` | ISO 8601 | Without `start_time`, the window is the hour before `end_time`; without `end_time`, it ends now. |
| `group_by` | `metadata__<key>`, or `prompt_version_number` | Returns a paginated list, one result per value, ordered by when each value first appeared. `prompt_version_number` groups by the version of the [Respan prompt](/docs/documentation/features/prompt-management/prompt-management-quickstart) a trace's calls used; filter on the prompt to compare one prompt's versions. A trace that used two versions is in both results. |
| `page`, `page_size` | Integers | With `group_by`, as on other list endpoints. |
| `filters` | `metadata__<key>`, and any other trace filter | Shape: `{"metadata__<key>": {"operator": "", "value": "<value>"}}`. Metadata values are strings. Applies to every result. |
| `behavior_columns` | Built-in names such as `refusal`, `task_complete`, `instruction_miss`, `incomplete_answer`, `structured_output`, or a custom behavior's ID | Up to 20. Needed for `behavior_summary`. |
| `is_including_behavior_final_score` | `true` | Adds `scored_counts`, `scored_trace_count` and `average_final_score`. Needs at least one `behavior_columns` entry, or the request returns 400. |
| `behavior_granularity` | `minute` or `hour` | Without `group_by` only (with it, 400): adds `buckets` to `behavior_summary`, one entry per UTC minute or hour in the window. |

To see which metadata keys you can group by, and their values, use the trace filter options (`GET /api/filters/?view=traces`, then `?metadata_key=<key>`).

## Before you compare

- **Scoring lags ingest.** A trace is counted in `total_count` right away, but its behavior verdicts arrive later, usually within a minute. Compare `scored_trace_count`, not `total_count`, and don't compare a window that ended minutes ago.
- **Only new traces are scored.** Turning a behavior on, or editing it, doesn't rescore earlier traces.
- **Verdicts are kept for 90 days.** A window that starts earlier returns `is_available: false` with the counts `null`.
- **One project per request.** `is_including_behavior_final_score` returns 400 for workspace-level reads.
- **Metadata values must match exactly.** `v2` and `V2` are different versions.
- **Group-by keys use letters, digits, `_`, `.`, `:` and `-`.** Any other key returns 400.
- **One value per trace.** A trace counts under exactly one value of the key; if its spans send different values, only one of them is used, so send the same value on every span.
- **Order is within the window.** A version that shipped before the window starts is placed by its first trace in the window.
