A CLI tool to inspect and delete Opik traces by date range, tags, or TTL policies — across one project or your entire workspace.
- Python 3.10+
pip install requests
| Variable | Required | Default | Description |
|---|---|---|---|
OPIK_API_KEY |
Yes | — | Your Opik / Comet API key |
OPIK_WORKSPACE |
Yes | — | Workspace name |
OPIK_BASE_URL |
No | https://www.comet.com |
API base URL (self-hosted installs) |
export OPIK_API_KEY=your-api-key
export OPIK_WORKSPACE=your-workspaceAlways inspect before you delete.
python manage_traces.py list --projects my-project --older-than-days 90Resolving projects...
Opik Trace Inspector
Workspace : my-workspace
Filters : before 2025-01-17
my-project → 1,743 traces match
──────────────────────────────────────────────────────────
Total: 1,743 traces across 1 project(s)
python manage_traces.py delete --projects my-project --older-than-days 90 --dry-run# Interactive (prompts for confirmation)
python manage_traces.py delete --projects my-project --older-than-days 90
# Non-interactive (skip prompt — for cron/CI)
python manage_traces.py delete --projects my-project --older-than-days 90 --yespython manage_traces.py list [filter options]
Prints the number of matching traces per project. Makes one lightweight API call per project (reads the total field only — does not paginate through all traces). Safe to run at any time.
python manage_traces.py delete [filter options] [--dry-run] [--yes]
| Flag | Description |
|---|---|
--dry-run |
Show what would be deleted, batch by batch. No API delete calls. |
--yes |
Skip the interactive confirmation prompt. |
| Flag | Description |
|---|---|
--projects NAME [NAME ...] |
Projects to target. Omit to target all projects in the workspace. |
--config FILE |
Load settings from a JSON config file. CLI flags override config values. |
--older-than-days N |
Target traces older than N days. Mutually exclusive with --before. |
--before DATE |
Target traces created before this ISO 8601 date (e.g. 2025-01-31). |
--after DATE |
Target traces created after this ISO 8601 date (lower bound). |
--tag TAG [TAG ...] |
Include only traces containing all of these tags. |
--exclude-tag TAG [TAG ...] |
Exclude traces containing any of these tags. |
Use a config file when you want to script complex rules (e.g. per-tag TTL policies, multiple projects) without repeating long CLI flags.
python manage_traces.py list --config config_example.json
python manage_traces.py delete --config config_example.json --dry-run
python manage_traces.py delete --config config_example.json --yesCLI flags always override the config file.
Option A — flat filters (single deletion pass):
{
"projects": ["my-project", "another-project"],
"filters": {
"older_than_days": 90,
"tags": [],
"exclude_tags": []
}
}Option B — TTL rules (multiple passes, processed shortest-retention-first):
{
"projects": ["my-project"],
"ttl_rules": [
{ "tags": ["sensitive", "PII"], "older_than_days": 30, "description": "Short retention for PII" },
{ "tags": ["internal"], "older_than_days": 60 },
{ "tags": [], "older_than_days": 90, "description": "Default catch-all" }
]
}When ttl_rules is used:
- Rules are sorted by
older_than_daysascending (shortest retention = most aggressive = runs first). - The rule with empty
"tags": []is the catch-all — it automatically excludes all tags configured in prior rules so traces aren't double-counted. - If both
filtersandttl_rulesare present,ttl_ruleswins and a warning is printed.
See config_example.json for a fully annotated example.
python manage_traces.py delete --projects my-project --older-than-days 90 --yespython manage_traces.py delete \
--projects my-project \
--after 2024-06-01 --before 2024-12-31 \
--dry-runpython manage_traces.py delete \
--projects my-project \
--tag sensitive \
--older-than-days 30 \
--yes# Omit --projects to target every project
python manage_traces.py delete --config config_example.json --yes# In a crontab or CI step — non-interactive, all workspace projects
OPIK_API_KEY=... OPIK_WORKSPACE=... \
python manage_traces.py delete --config /path/to/ttl.json --yes- Config validation — if
--configis provided, the file is validated before any network calls. - Project resolution — named projects are verified against the workspace; unknown names cause an early error with the list of available projects. If no projects are specified, all workspace projects are discovered automatically.
- Filter construction — CLI flags and config are merged (
TraceFilterdataclass). Filters are sent as query parameters to the Opik API. - Trace collection — paginated
GET /tracescalls (up to 1,000 per page).listuses a single lightweight call;deletepaginates to collect all matching IDs. - Batch deletion —
POST /traces/deletewith up to 1,000 IDs per request, with a 0.2 s delay between batches to respect rate limits.
ERROR: OPIK_API_KEY environment variable is not set.
Export the required environment variables before running.
ERROR: Project(s) not found in workspace: ['my-typo']
The script lists available projects — check the name spelling.
ERROR: No filter criteria specified.
At least one of --older-than-days, --before, --after, --tag, or --exclude-tag is required (or a --config file that specifies filters).
HTTP 429 / rate limit errors
The tool already applies a 0.2 s delay between delete batches. If you still hit limits, the RATE_LIMIT_DELAY constant at the top of manage_traces.py can be increased.