Labels, deletes and retention
A CI pipeline records a version for every build, so a busy pacticipant collects thousands of versions nobody will deploy again. This page covers three things you can do about that, and one way to keep pacticipants organised:
- Labels group pacticipants (
team-billing,tier-1). - Delete removes a version or a whole pacticipant. A delete can be undone for the workspace's restore window (30 days unless you change it).
- Clean-up keeps the versions your rules name and removes the rest every night. You always see what it will remove before it removes anything. A retention run does the same once, on demand.
- Purge removes deleted data for good once the restore window has passed.
The clean-up rules, their preview and Recently deleted are on Contracts → Settings →
Clean-up (see Set the clean-up rules), and in
apiome pact retention show|set|preview. Labels and single deletes are on the
Pacticipants pages. Everything is also in the
Pacticipants API and the
Pact Broker API. Both take an API key, in X-API-Key or as a
bearer token.
Set the clean-up rules
Contracts → Settings opens on the Clean-up tab. It says what is kept, shows what the rules would remove if they ran now, and lists what was deleted recently.


/ade/dashboard/pacts/settings-
Read what is kept. Each rule under What to keep is a sentence with how many versions it keeps today. A version that any rule keeps stays:
Rule Keeps Every version deployed or released anywhere Always on. It has no remove button, and no rule set can turn it off. The latest N versions on each pacticipant's main branch The newest N on the branch set as the pacticipant's main branch. A pacticipant with no main branch keeps nothing by this rule. The latest N on every other branch, for D days The newest N of each other branch, while they were recorded in the last D days. Leave the days empty to keep them however old they are. Anything tagged … Every version carrying one of the tags. Separate several with commas. Each pacticipant's latest version is also always kept.
-
Change a rule. Type a new number in its sentence, click the × to remove it, or click Add a rule to bring one back.
-
Check the preview. If it ran now redraws as you edit: how many versions would go, with how many pacts and verification results. Click See the list for the versions, per pacticipant. The preview is planned by the same code as the nightly run, so it lists exactly what the next run removes, unless something is published, deployed or deleted in between.
-
Turn on Run clean-up nightly. While it is off, nothing is ever removed, and the preview says Nothing is removed while clean-up is off. When it is on, the clean-up runs once a night after 02:00 UTC.
-
Choose Keep deleted items restorable for — 7, 30 or 90 days. This is the workspace's restore window: a deleted version or pacticipant is purged when it has passed.
-
Click Save rules. Discard goes back to the saved rules.
A rule set that would remove a deployed or released version cannot be saved: the answer is Deployed and released versions are always kept.
Recently deleted lists the deleted pacticipants, and the versions deleted on their own, newest first: who deleted each (Clean-up for the nightly run), what comes back with it, and when it is purged. Click Restore to bring one back. A restored version comes back with its pacts, results and deployments; a restored pacticipant with the versions deleted with it.
Saving the rules and Restore need the Contracts admin permission (pacts:delete: Admin or
Owner). Everyone else sees the tab read-only, with a note saying so.
From the CLI
apiome pact retention show
apiome pact retention preview --main-branch-latest 5 --other-branch-latest 1 --other-branch-days 90
apiome pact retention set --main-branch-latest 5 --other-branch-latest 1 --other-branch-days 90 \
--keep-tag keep --nightly --restore-days 30
set changes only the flags you give and keeps the rest as saved; 0 removes a rule
(--main-branch-latest 0), and --no-tags removes the tag rule. preview without flags previews the
saved rules; with flags it previews them changed by the flags, without saving. The Clean-up tab's
The same, from anywhere block shows the command for what the form holds. See
apiome pact retention.
From the REST API
| Request | What it does | Needs |
|---|---|---|
GET /v1/tenants/acme/pact-retention/policy | The rules, the nightly switch, the restore window, the last and next nightly run, and can_edit. | pacts:view |
PUT /v1/tenants/acme/pact-retention/policy | Replace the rules (a field left out takes its default). | pacts:delete |
POST /v1/tenants/acme/pact-retention/policy/preview | What the saved rules ({}) or a draft ({"rules": {…}}) would remove now. Changes nothing. | pacts:view |
GET /v1/tenants/acme/pact-retention/deleted | Recently deleted, newest first, a page at a time (limit, cursor). | pacts:view |
curl -X PUT https://api.apiome.dev/v1/tenants/acme/pact-retention/policy \
-H "X-API-Key: sk_live_…" \
-H "Content-Type: application/json" \
-d '{
"keep_main_branch_latest": 5,
"keep_other_branch_latest": 1,
"keep_other_branch_days": 90,
"keep_tags": ["keep"],
"nightly_enabled": true,
"restore_window_days": 30
}'
An unknown field, a repeated tag, or keep_other_branch_days without keep_other_branch_latest is
refused with the reason; nothing is dropped silently.
Label pacticipants
A label is a free-form name on a pacticipant. A pacticipant can carry any number of labels.
-
Add a label.
curl -X PUT https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service/labels/team-billing \-H "X-API-Key: sk_live_…"The answer is
201when the label is new and200when the pacticipant already had it. A label may contain/(team/billing). -
List the pacticipants with a label:
GET /v1/tenants/acme/pacticipants?label=team-billing. -
List every label in the workspace:
GET /v1/tenants/acme/pacticipant-labels. -
List one pacticipant's labels:
GET …/pacticipants/billing-service/labels. The answer comes a page at a time, by name: passlimit(1 to 200, default 50), and whilehas_moreistruepass the answer'snext_cursorascursorto read the next page. -
Remove a label:
DELETE …/pacticipants/billing-service/labels/team-billing.
The Pact Broker's label routes work too, so a script written for a Pact Broker runs unchanged:
| Pact Broker route | What it does |
|---|---|
GET …/pact-broker/labels | Every label, under _embedded.labels. |
GET …/pact-broker/pacticipants/label/{label} | The pacticipants with that label. |
PUT …/pact-broker/pacticipants/{p}/labels/{label} | Add a label. 201 with a Location header when it is new. |
GET / DELETE …/pact-broker/pacticipants/{p}/labels/{label} | Read or remove one label. |
A pacticipant's labels are also embedded in its Pact Broker document (_embedded.labels), and a
contract webhook can send them with ${pactbroker.consumerLabels} and
${pactbroker.providerLabels}.
One difference from the Pact Broker: labelling a pacticipant that does not exist answers 404.
The Pact Broker would create the pacticipant.
Delete a version
curl -X DELETE "https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service/versions/3f2a9c1?reason=broken%20build" \
-H "X-API-Key: sk_live_…"
The answer is 204. Straight away:
- The version is gone from every read. That includes its pacts, the verification results it published as a provider, and its deployments and releases. The matrix and can-i-deploy no longer see it.
- A branch it headed falls back to the latest version still on that branch. A branch with no version left is hidden until a new version is recorded on it.
- The version number is free. Publishing
3f2a9c1again records a new version. reasonis kept with the delete and in the audit trail. It is optional, up to 500 characters.
DELETE …/pact-broker/pacticipants/{p}/versions/{v} does the same through the Pact Broker API.
In the console, open the pacticipant's Versions tab and choose Delete version from the
row's ⋯ menu, or select several rows and click Delete. See
Manage versions. From a pipeline, run
apiome pact delete-version -a "Billing Service" -e 3f2a9c1 --reason "broken build".
A deployed version is protected
A version that is currently deployed to an environment, or released and still supported, is
refused with 409 pacticipant-version-in-use. The message names the version. Do one of these:
- Record the undeployment first (
pact-broker record-undeployment, orrecord-support-endedfor a release), then delete. - Add
force=trueto delete it anyway. Its deployment disappears with it, so can-i-deploy will no longer count it as running there.
The Versions tab and apiome pact delete-version never send force. They say, for example,
3f2a9c1 is running in Production. Record its undeployment first.
Delete a pacticipant
curl -X DELETE "https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service?reason=service%20retired" \
-H "X-API-Key: sk_live_…"
This deletes the pacticipant with all of its versions, and with them their pacts, verification
results, deployments, branches, tags and labels. The handle is free again at once: publishing a
pact that names Billing Service registers a new pacticipant. The project and the consumer it was
bound to are not touched.
As with a version, a pacticipant with a deployed or released version is refused with
409 pacticipant-version-in-use unless you add force=true. DELETE …/pact-broker/pacticipants/{p}
does the same through the Pact Broker API.
Restore what you deleted
Everything you delete stays restorable for the workspace's restore window: 30 days unless you change it on the Clean-up tab.
-
Find it. Add
state=deletedto a list:To find Request Deleted pacticipants GET /v1/tenants/acme/pacticipants?state=deletedDeleted versions of a pacticipant GET …/pacticipants/billing-service/versions?state=deletedEach row has
deleted_at,deleted_by_label,delete_reasonandpurge_after: when it goes for good. A version also hasdelete_cause:versionif it was deleted on its own,pacticipantif it went with its pacticipant, orretentionif a retention run deleted it. -
Restore it.
# A versioncurl -X POST https://api.apiome.dev/v1/tenants/acme/pacticipants/billing-service/versions/3f2a9c1/restore \-H "X-API-Key: sk_live_…"# A pacticipant: by its id (from step 1), or by its handlecurl -X POST https://api.apiome.dev/v1/tenants/acme/pacticipants/2f9c…/restore \-H "X-API-Key: sk_live_…"
In the console, anything deleted is listed under Contracts → Settings → Clean-up →
Recently deleted, with Restore. A deleted version can also be restored from the pacticipant's
Versions tab: click
Deleted, then Restore on its row. See
Restore a deleted version. A deleted pacticipant is
restored from the Pacticipants page. From a pipeline, run
apiome pact restore-version -a "Billing Service" -e 3f2a9c1.
What comes back:
- A version comes back with its pacts, results and deployments. A branch it headed is headed by it again.
- A pacticipant comes back with the versions that were deleted with it. A version you had deleted on its own before stays deleted; restore it separately. With several deleted pacticipants of the same handle, restoring by handle brings back the most recently deleted one.
A restore is refused with 409 pacticipant-restore-conflict when a live pacticipant has taken the
handle, or a live version has taken the number, in the meantime. Delete that one first if you want
the old one back.
Clean up old versions with a retention run
A retention run is a one-off clean-up with rules you send in the request, rather than the saved clean-up rules. It keeps the versions you name and deletes the others. A version is kept when any of these is true:
| Rule | Keeps |
|---|---|
| Always | The pacticipant's latest version. |
keep.latest_per_branch: N | The newest N versions of each branch. |
keep.latest_per_main_branch: N | The newest N versions of the pacticipant's main branch. |
keep.latest_per_other_branch: N (with keep.other_branch_days: D) | The newest N versions of every other branch (recorded in the last D days). |
keep.deployed_or_released (on by default) | Every version currently deployed or released. |
keep.tags: [...] | Every version carrying one of the tags. |
keep.created_within_days: D | Every version recorded in the last D days. |
A run always starts as a dry run, so you see the plan before anything is deleted.
:::note Imported history keeps its dates
A version imported from another Pact Broker keeps the date the source recorded,
so keep.created_within_days counts it from that date, not from the import. Read the dry run's plan
before you apply a first retention run after a migration.
:::
-
Ask for the plan.
dry_rundefaults totrue, so this deletes nothing:curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-retention \-H "X-API-Key: sk_live_…" \-H "Content-Type: application/json" \-d '{"keep": { "latest_per_branch": 10, "created_within_days": 30 },"pacticipants": ["billing-service"],"reason": "monthly cleanup"}'The answer counts what each pacticipant keeps and why (
kept_by), lists the versions it would delete (oldest first, up to 100 per pacticipant), and ends with aplan_digest. Leave outpacticipantsto clean every pacticipant in the workspace. -
Check the plan. Look at
deletedand thedeletionsof each pacticipant. -
Apply it. Send the same request again with
"dry_run": falseand theplan_digestfrom step 1:curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-retention \-H "X-API-Key: sk_live_…" \-H "Content-Type: application/json" \-d '{"keep": { "latest_per_branch": 10, "created_within_days": 30 },"pacticipants": ["billing-service"],"reason": "monthly cleanup","dry_run": false,"plan_digest": "sha256:…"}'The answer is the same plan with
"applied": true.
If anything changed between the two calls, the run deletes nothing. That covers a version
published, deployed or deleted in between. The answer is 409 pact-retention-plan-changed, with
the new plan under detail.plan: check it and apply its own plan_digest.
A run deletes at most 5,000 versions, oldest first. remaining counts the ones left for the next
run. A run reads at most 100,000 versions; for a larger workspace, name the pacticipants in groups.
Every deletion a run makes is a normal soft delete, with delete_cause: retention and the run's
reason. You can restore any of them during the restore window.
Run it on a schedule. The simplest way is to save the rules and turn on
Run clean-up nightly. To run your own rules from a scheduled CI job
instead, make the two calls: ask for the plan, then apply its digest. Applying needs
pacts:delete, so use an API key of an Admin or Owner.
How the purge works
The retention sweep runs every 5 minutes. Once a night after 02:00 UTC it first runs the clean-up of each workspace that has it turned on. Then it removes for good every pacticipant and version deleted longer ago than its workspace's restore window, with its pacts, verification results and deployment records. A contract webhook limited to a purged pacticipant is removed with it, and so are its owner team and its entries in the Unowned findings report. After that, nothing can bring them back. A deleted pacticipant keeps its owner until then, so restoring it brings the owner back.
Who can do what
| Action | Needs | Viewer | Editor | Admin | Owner |
|---|---|---|---|---|---|
| Read labels, list deleted pacticipants and versions | pacts:view | ✓ | ✓ | ✓ | ✓ |
| Ask for a retention plan (dry run), read the clean-up rules and their preview, list Recently deleted | pacts:view | ✓ | ✓ | ✓ | ✓ |
| Add or remove a label | pacts:edit | — | ✓ | ✓ | ✓ |
| Delete or restore a version or a pacticipant | pacts:delete | — | — | ✓ | ✓ |
| Apply a retention run, save the clean-up rules | pacts:delete | — | — | ✓ | ✓ |
Everything is audited. Every delete, restore, label change, applied retention run and purge
writes an entry to the workspace's Access audit
(pacts.version.delete, pacts.retention.apply, pacts.retention.policy for saved rules,
pacts.retention.nightly for a nightly run, pacts.purge and so on), in the same transaction
as the change, so neither happens without the other. The entry records who acted, the target, the
reason and the counts. A dry run changes nothing and writes no entry. The rest of the Pact Broker's
permissions are on Who can do what.
When something is refused
| Status | code | What to do |
|---|---|---|
400 | pacticipant-invalid-label | A label is 1–255 characters, with no leading or trailing space and no control characters. |
400 | pacticipant-invalid-reason | A reason is at most 500 characters, with no control characters. |
404 | pacticipant-label-not-found | The pacticipant does not carry that label. |
404 | pacticipant-not-found, pacticipant-version-not-found | Nothing deleted or live by that name, or a pacticipant named in a retention run does not exist. A run never skips a name silently. |
409 | pacticipant-version-in-use | A version is deployed or released. Record the undeployment, or add force=true. |
409 | pacticipant-restore-conflict | A live pacticipant or version has the handle or number now. |
409 | pacticipant-not-deleted | You asked to restore something that is not deleted. |
409 | pact-retention-plan-changed | The plan moved since the dry run. Check detail.plan and apply its digest. |
422 | pact-retention-no-selector | Turn on at least one keep rule. With deployed_or_released: false and no other rule, a run would keep only the latest versions. |
422 | pact-retention-plan-digest-required | Send the plan_digest of the dry run with dry_run: false. |
422 | pact-retention-keeps-in-use | Deployed and released versions are always kept: leave keep_deployed_or_released out or true. |
422 | pact-retention-bad-cursor | Pass the next_cursor of the previous Recently deleted page as it was returned. |
422 | pact-retention-too-many-pacticipants, pact-retention-too-many-versions | Name at most 200 pacticipants, and fewer per run in a very large workspace. |
For operators
- Migration
V437adds the deletion columns and thepacticipant_labeltable. It rewrites no existing rows. - Migration
V456addspact_retention_policy(one row per workspace) and two partial indexes for Recently deleted. APIOME_PACT_DELETION_GRACE_DAYS(default30, at least1) is the restore window of a workspace that never saved clean-up rules; a saved restore window replaces it for that workspace. The nightly clean-up and the purge run on the async-job retention tick.- If a workspace has more than 100,000 live versions, the nightly run is refused and deletes
nothing.
last_run.erroronGET …/pact-retention/policysays so, and the tab shows it.
Related
- Pact Broker concepts — pacticipants, versions, branches and tags.
- Environments and deployments — record undeployments before you delete.
- Can I deploy? — what a deleted version means for the matrix.
- Pact Broker compatibility — which Pact Broker delete routes are served.
- Pacticipants API — every endpoint, parameter and error code.