Skip to main content

The apiome pact commands

apiome pact is the Apiome CLI's Pact Broker command group. It has the commands of the pact-broker CLI you already run in CI — publish, can-i-deploy, record-deployment and the rest — with the same flags, the same sentences in the log and the same exit codes. A pipeline moves over by changing pact-broker to apiome pact.

It also has the commands only Apiome has: publishing an OpenAPI provider contract, hosted verification, sending a verifier report, exporting a consumer surface as a pact and exporting a pact as a Postman collection. Most of these have no screen yet (which do); they run in a terminal or a CI job, and an AI agent can ask the same questions over MCP.

Before you start​

You need:

  1. The Apiome CLI. See Install the CLI.
  2. The broker base URL of your workspace — your API address followed by /v1/tenants/<workspace>/pact-broker, for example https://api.apiome.dev/v1/tenants/acme/pact-broker.
  3. An API key from a member whose role holds Pacts → Create (the built-in Editor role does). Create one on API keys. Read-only commands such as can-i-deploy need only Pacts → View. Give each job a key with a Pact scope rather than full access.

Point the CLI at your workspace​

apiome pact reads the two variables Pact tooling already uses:

export PACT_BROKER_BASE_URL=https://api.apiome.dev/v1/tenants/acme/pact-broker
export PACT_BROKER_TOKEN=<your API key>

The broker base URL names both the API and the workspace, so nothing else is needed. If you already use the Apiome CLI, APIOME_BASE_URL, APIOME_TENANT_ID and APIOME_API_KEY work too.

When several are set, the first one found wins:

OrderWhereBase URLCredential
1The command's flags--broker-base-url (-b)--broker-token (-k)
2The CLI's root flagsapiome --base-url … --tenant …apiome --api-key …
3Pact's variablesPACT_BROKER_BASE_URLPACT_BROKER_TOKEN
4Apiome's settingsAPIOME_BASE_URL + APIOME_TENANT_IDAPIOME_API_KEY

Prefer the variables to -k: a secret on the command line is visible to other processes.

If your operator set up a broker host, the short form https://acme.<broker host> works for the commands that call Pact Broker routes. list-pacticipants, create-or-update-pacticipant, delete-pacticipant, describe-version --latest, create-version-tag, delete-version, restore-version, retention, record, stub and verify call Apiome's own API, which the short form does not serve; they stop and ask for the long form.

A pipeline set up for basic auth works too: when no token or key is set, PACT_BROKER_PASSWORD is used as the API key and PACT_BROKER_USERNAME is ignored. A username without a password stops the command with the reason.

Pact keys and scopes​

Apiome's broker has no users or passwords of its own: every credential is a workspace API key. Pact tooling may send it three ways, and all three are the same key:

Tooling settingSent as
--broker-token, PACT_BROKER_TOKEN, pactBrokerTokenAuthorization: Bearer <api-key>
--broker-username / --broker-password, PACT_BROKER_USERNAME / PACT_BROKER_PASSWORD, pactBrokerUsername / pactBrokerPasswordBasic auth: the password is the API key; the username can be anything
apiome pactX-API-Key: <api-key>

Basic auth with an empty password, or any other Authorization scheme, is refused with 401 and a message that says where the key goes.

Three scopes keep a Pact key away from everything else in the workspace. Each admits only the broker (/v1/tenants/<workspace>/pact-broker) and the hosted verifier (/v1/tenants/<workspace>/pact-verifier); pact:read also reads the workspace's pacticipants:

ScopeAllowsCommands
pact:readEvery read of the broker, the hosted verifier and the pacticipants, fetching the pacts to verify, and checking a pact before publishingcan-i-deploy, check, describe-version, list-pacticipants, a verifier fetching its pacts
pact:publishPublishing pacts and provider contracts, tagging a version or recording its branch, recording a deployment or releasepublish, publish-provider-contract, record-deployment, record-undeployment, record-release, record-support-ended
pact:verifyPublishing verification results, sending a verifier report, hosted verification, registering provider states, tagging the provider versionverify, publish-verification-results, a Pact verifier with publishVerificationResults

Create a key with the matching preset on API keys:

JobPresetScopes
Gate a deploy with can-i-deploy onlyPact: read-onlypact:read
Publish a consumer's pacts; record deploymentsPact: consumer + deploypact:read pact:publish
Verify a provider in CIPact: CI verifierpact:read pact:verify

:::note Security

  • A Pact scope is checked before the key's role: the member who created the key still needs Pacts → View (reads) or Create (writes), and a key works only in its own workspace.
  • Deleting anything, creating or changing a pacticipant, webhooks, environments and cleanup need a Full access key — run create-environment and create-webhook with one, once, outside the pipeline. So do export-consumer-contract and publish-consumer-contract, which call a project's consumer contracts rather than the broker.
  • A CI verifier key cannot publish a pact, so a compromised provider build cannot change what its consumers expect.
  • Store the key as a CI secret and prefer the variables to -k. :::

The commands​

CommandDoesReplaces
publishPublish pact files for a consumer versionpact-broker publish
checkCompare pact files with several provider versions before publishing; publishes nothing—
recordRun the consumer's tests against the hosted mock, turn the calls into a pact and publish it—
stubServe a provider's published pacts as a hosted mock (Serve pacts as a mock)—
list-pacticipantsList the workspace's pacticipantspact-broker list-pacticipants
create-or-update-pacticipantCreate a pacticipant, or update the one with this name; never renamespact-broker create-or-update-pacticipant
delete-pacticipantDelete a pacticipant with its history; restorable until purged—
describe-versionShow a version's branches, tags and build URLpact-broker describe-version
create-version-tagTag a version (one request per tag)pact-broker create-version-tag
delete-versionDelete a version with its pacts and results; refused while it is deployed—
restore-versionRestore a deleted version with its pacts, results and deployments—
retention show, retention set, retention previewRead, change or preview the clean-up rules, the nightly switch and the restore window—
can-i-deployAsk whether a version can be deployedpact-broker can-i-deploy
record-deploymentRecord a deployment to an environmentpact-broker record-deployment
record-releaseRecord a release to an environmentpact-broker record-release
record-undeploymentRecord that a service no longer runs in an environment (one instance)pact-broker record-undeployment
record-support-endedRecord that a released version is no longer supportedpact-broker record-support-ended
create-environmentCreate an environmentpact-broker create-environment
create-webhookCreate a contract webhookpact-broker create-webhook
verifyVerify a provider with Apiome's hosted verifiera Pact verifier in your build
publish-provider-contractPublish an OpenAPI provider contract with its evidencepactflow publish-provider-contract
publish-verification-resultsSend a report from a verifier you ran—
export-consumer-contract, publish-consumer-contractTurn a declared consumer surface into a pact—
export-postmanWrite a pact as a Postman collection with test scripts—
scaffold-provider-testsWrite a provider verification test (pact-js, pact-jvm, pact-go, pact-python) with a stub per provider state—
setupShow the guided set-up, or create pacticipants from projects, environments, CI pull requests and Actions secrets in one re-runnable command—
migrateImport a Pact Broker or PactFlow workspace—

Every option of every command is in the CLI reference.

The same command, in the app​

Every apiome pact command has a screen in Contracts. Every Contracts screen that changes something shows The same, from anywhere — its action as an apiome pact command, a Pact CLI command, a GitHub Action step and a REST request, built from what you filled in, with secrets written as variables. The first were the webhook editor and the Publish page.

CommandWhere in the app
can-i-deployContracts → Can I deploy
create-webhookContracts → Webhooks → New webhook
describe-versionContracts → Pacticipants → a pacticipant
list-pacticipantsContracts → Pacticipants
create-or-update-pacticipantContracts → Pacticipants → New pacticipant, or a pacticipant's Settings
delete-pacticipantA pacticipant's Settings → Danger zone
create-version-tagA pacticipant's Versions → + tag, or Add a tag for the selection
delete-version, restore-versionA pacticipant's Versions → Delete version, or Deleted → Restore
retention show, retention set, retention previewContracts → Settings → Clean-up (What to keep, Save rules, If it ran now)
publishContracts → Publish a pact (also a project's Consumers → Import Pact file)
publish-consumer-contractContracts → Publish a pact → Derive from a project
checkContracts → Publish a pact → Check it before it counts
recordContracts → Generate a pact from a mock; Start clean is what record does before each run unless --append
create-environmentContracts → Environments → New environment
record-deploymentContracts → Environments → Record a deployment, or an environment's menu → Record a deployment here
record-releaseContracts → Environments → Record a release
record-undeploymentContracts → Environments → an environment's ⋯ menu → Record an undeployment
record-support-endedContracts → Environments → Released to users → End support, or untick a release in Record a release
verifyContracts → Verification (Run a verification)
publish-provider-contractContracts → Publish a provider contract
publish-verification-resultsContracts → Verification → Upload results
export-consumer-contractThe Export page → A pact from a project
scaffold-provider-testsThe Export page → Provider test scaffolding
setupSet up contracts (Contracts → “⋯” → “Set up contracts”)
export-postmanThe Export page → A Postman collection (--all-consumers is All consumers — one folder each; --state-setup is Include provider-state setup as pre-request scripts)
migrateContracts → Migrate from a broker (the Migration wizard); --follow is Switch over → Keep copying until everyone has moved

A few things in the app have no command yet, and say so in their The same, from anywhere block: editing, deleting and testing a webhook, redelivering a delivery, re-running one verification, answering a re-publish request, the verification settings, Compare only on the Publish a provider contract page, a pacticipant's rename, linked project, labels and restore, and editing or deleting an environment. Each has a REST route. A pacticipant's README badge (its Settings → Badges) is a public URL, not a command.

On the Publish page every flag of publish and publish-consumer-contract has a field, and on the Publish a provider contract page every flag of publish-provider-contract, and on the Export page every flag of export-consumer-contract, export-postman and scaffold-provider-tests; the ledger row lists which (fields), and the same check holds it to the command's flags. With the Export page every apiome pact command has a screen.

The table is kept honest by a check in CI: adding a command without its row in docs/pact-parity-ledger.json, or a Contracts screen that writes without a command or a written reason, fails the build. See The CLI ↔ UI parity ledger.

Publish pacts​

apiome pact publish ./pacts \
--consumer-app-version "$GIT_COMMIT" \
--branch "$GIT_BRANCH" \
--build-url "$CI_BUILD_URL"

Name pact files or folders; a folder publishes every *.json file in it. Every file is read before anything is sent, and a file that is not a pact stops the run with its name and the reason. Pacts of several consumers are sent as one request per consumer.

Give the commit SHA as --consumer-app-version, as above. Apiome can then post each pact's verdict to that commit as a GitHub or GitLab status: pending until the provider verifies it. See Commit statuses.

  • --auto-detect-version-properties (-r) reads the branch and build URL from GitHub Actions, GitLab, Jenkins, Buildkite, CircleCI, Travis, Bitbucket, AppVeyor, CodeShip or Azure DevOps, and falls back to git.
  • --tag (-t) tags the version; --tag-with-git-branch (-g) tags it with the detected branch.
  • --merge is refused: Apiome keeps the pact a version published, and refuses a different one for the same version.

Record a pact from the hosted mock​

apiome pact record --mock billing-api/2.7.0 --consumer "Orders UI" --matching type --publish -- npm test

Runs the command after -- with APIOME_MOCK_URL (the mock's address), APIOME_MOCK_CAPTURE_HEADER (X-Mock-Capture) and APIOME_MOCK_CAPTURE (<consumer>@<version>) in its environment, waits for the mock to store the calls, and writes the pact to pacts/<consumer>-<provider>.json. With --publish, and only when the command passed, it publishes the pact with the branch, tags and build URL. The version defaults to the commit and the branch to the CI's or git's, as with publish --auto-detect-version-properties.

FlagWhat it does
--mockThe mocked API, <project>/<version>. Required.
--consumer (-c)The consumer, as its pacts name it. Required.
--consumer-app-version (-a)The consumer version. Default: the commit (the CI's commit variable, then git rev-parse HEAD).
--branch, --tag (-t), --build-urlRecorded with the publish. The branch and build URL default to the CI's.
--providerThe provider. Default: the pacticipant bound to the mocked project.
--matchingexact, type (default) or spec. See How values are matched.
--publishPublish the pact when the command passed.
--pact-dirWhere to write the pact (default pacts).
--appendKeep the calls an earlier run recorded for this consumer version. By default they are deleted first.
--capture-urlAlso export APIOME_MOCK_CAPTURE_URL, a private capture URL for clients that cannot add a header. It is revoked when the run ends.
--settle-timeoutSeconds to wait for the mock to store the calls (default 15).

It exits with the command's own code when the command failed (the pact is written but not published), 1 when nothing was recorded or the pact could not be generated or published, and 0 otherwise. The report accounts for every call that did not reach the pact. See Record from a pipeline.

Check before publishing​

apiome pact check ./pacts --against main --against deployed:production

Compares each pact with the provider contract of every version --against names — main, deployed:<environment>, version:<number> or draft:<revision>, at most ten — and publishes nothing. It prints one row per provider version with the verdict a publish would record, every interaction that differs or is not in the spec, and every selector that named nothing. It exits 0 only when every pact passes against every version, 1 otherwise. A bad selector is refused before anything is sent. See Check before publishing.

Ask can-i-deploy​

apiome pact can-i-deploy \
--pacticipant "Billing Service" --version "$GIT_COMMIT" \
--to-environment production \
--retry-while-unknown 6 --retry-interval 10

It prints the matrix rows, then Computer says yes \o/ or Computer says no ¯\_(ツ)_/¯ with the reason — the lines pact-broker prints. Name the version one way: --version, --latest (with --tag for the latest tagged version), --branch or --main-branch. Use --to for a tag instead of an environment, and --ignore to leave an application out. --dry-run prints the verdict without stopping the job. One pacticipant is checked per run; check several by running the command once for each.

See Can I deploy? for how the verdict is reached.

Record deployments and releases​

apiome pact create-environment --name production --display-name Production --production
apiome pact record-deployment --pacticipant "Billing Service" --version "$GIT_COMMIT" --environment production
apiome pact record-release --pacticipant "Mobile App" --version 4.2.0 --environment production
apiome pact record-undeployment --pacticipant "Reporting Job" --environment production --application-instance us-east
apiome pact record-support-ended --pacticipant "Mobile App" --version 4.1.0 --environment production

The environment is found by name. An unknown name stops with the create-environment command that creates it. Add --application-instance (--target) to record-deployment when the application runs several copies in one environment.

record-undeployment ends the deployment in the instance you name, or the environment's only instance when you name none. When nothing of the service runs there it stops (exit 1) with pact-broker's sentence — “Billing Service is not currently deployed to production environment. Cannot record undeployment.” — or lists the instances to choose from. record-support-ended ends the support of one released version; a version not released there stops the same way. Both keep the record in the Environments history. See Environments and deployments.

Ask from an AI agent (MCP)​

An agent connected to Apiome's MCP server can ask the same questions without a terminal. Four MCP tools cover the commands an agent needs most:

ToolDoes what this command doesNeeds
pact.listLists the latest pact of each consumer and provider pair, with how its latest verification wentPacts → View
pact.matrixGET …/matrix: the verdict and the rows behind itPacts → View
pact.can_i_deployapiome pact can-i-deployPacts → View
pact.record_deploymentapiome pact record-deploymentPacts → Create

For example, an agent asks pact.can_i_deploy with {"pacticipant": "Billing Service", "version": "4f1e2d0", "to_environment": "production"}. It reads summary.deployable: true, false, or null while a verification result is still missing. On null, retryAfterSeconds says how many seconds to wait before asking again.

  • Use an MCP key. Create one with Create MCP key on API keys. A REST API key does not work here. Apiome checks the Pacts permissions of the person who created the key. If that person loses the permission, the key loses it too. A key whose creator was removed is refused with mcp-pact-key-has-no-owner. Create a new key in that case.
  • Use the whole workspace. Pacts belong to the whole workspace, so a key limited to projects is refused.
  • Answers are bounded. pact.list returns up to 100 pacts a page. Pass nextCursor back as cursor to get the next page. pact.matrix and pact.can_i_deploy return up to max_rows rows (default 50, at most 100). rowsTotal and rowsTruncated say how many rows were left out. The verdict always counts every row.
  • Nothing is ignored. If a selector has a key the tool doesn't know, or a value of the wrong type, or you give both to_environment and to_tag, the tool refuses it and says why. A refusal from Apiome includes its code in brackets, such as [pact-matrix-invalid].
  • Recording is a write. pact.record_deployment is marked as a write, so MCP hosts can ask before they run it, and it is off until the workspace allows it (see Choose what agents may do). The four tools form the pact toolset. Admins can turn it off for the workspace, or for one key, in MCP settings.

Every argument is listed in the MCP tool reference.

Choose what agents may do​

In Contracts, click Settings, then the Agents tab.

The Agents tab: four switches under What an AI agent may do with contracts — Read pacts, verdicts and can-i-deploy on; Draft a pact on, with a note that no agent tool drafts yet; Publish pacts and provider contracts off; Record deployments off, never to an environment marked production — and Save switches.The Agents tab: four switches under What an AI agent may do with contracts — Read pacts, verdicts and can-i-deploy on; Draft a pact on, with a note that no agent tool drafts yet; Publish pacts and provider contracts off; Record deployments off, never to an environment marked production — and Save switches.
Route/ade/dashboard/pacts/settings?tab=agents
SwitchDefaultWhat it allows
Read pacts, verdicts and can-i-deployOnpact.list, pact.matrix and pact.can_i_deploy
Draft a pact from a project or a mock captureOnNo agent tool drafts pacts yet; the switch applies when one ships
Publish pacts and provider contractsOffNo agent tool publishes yet; the switch applies when one ships, never on a main branch
Record deploymentsOffpact.record_deployment, never to an environment marked production

Turn the switches you want on and click Save switches. An agent whose action is switched off is refused with mcp-pact-agent-action-off and the reason, and an agent never records to an environment marked production (mcp-pact-agent-production), whatever the switch says. Every refusal is written to the access audit as pacts.agent.refused. The switches need the Contracts admin permission (pacts:delete); everyone else sees them read-only. From a script: PUT /v1/tenants/{tenant}/pact-contract-settings/agents with {"read": true, "draft": true, "publish": false, "record": true}.

:::note Recording is off until you allow it Before PFX-8.15 any MCP key whose owner had Pacts → Create could record deployments. Now recording needs the Record deployments switch as well. Turn it on if your agents record deployments to non-production environments. :::

Create a webhook​

apiome pact create-webhook https://ci.example.com/hooks/ledger \
--request POST \
--header "Content-Type: application/json" \
--data '{"pact": "${pactbroker.pactUrl}"}' \
--provider "Ledger API" \
--contract-requiring-verification-published

Choose at least one event flag. --data @body.json reads the body from a file. The password of --user name:password is stored sealed and never printed. See Contract webhooks.

Verify a provider​

apiome pact verify \
--provider "Ledger API" --provider-app-version "$GIT_COMMIT" --branch main \
--target ledger-staging \
--consumer-version-selector '{"mainBranch": true}' \
--consumer-version-selector '{"deployedOrReleased": true}' \
--enable-pending

Apiome replays each selected pact against the registered verification target ledger-staging and publishes a result per pact. It prints one row per pact and every interaction it could not replay, with the reason. --no-publish-verification-results is a dry run. --skip-already-verified skips pacts that already have a result for --provider-app-version, and --provider-states-setup-url sends each provider state to the provider's own endpoint instead of the registered states. A target that could not be reached ends the run as could-not-connect, which is not a failed verification. --allow-mutating against a production target is refused. See Verify a provider from Apiome. Each published result is also posted as a commit status to the provider's commit and to the consumer's commit, when their version numbers are commit SHAs.

Export a pact as a Postman collection​

export-postman writes a pact as a Postman Collection v2.1. A provider team can then run the consumer's requests in Postman, or in CI with Newman, before any Pact tooling is set up:

apiome pact export-postman --provider "Ledger API" --consumer "Billing Service" --branch main \
--provider-base-url http://localhost:8080 -o ledger.postman_collection.json
newman run ledger.postman_collection.json
  1. Choose the pact. --provider and --consumer give the latest pact between them. Add one of --consumer-version, --tag, --branch or --pact-version (the content SHA) to pick another one. To export a pact file you have not published yet, use --pact-file billing-ledger.json instead.
  2. Point it at the provider. Requests go to {{baseUrl}}. --provider-base-url fills in that variable. Without it, the variable is empty: set it in Postman, or pass newman run … --env-var baseUrl=http://localhost:8080.
  3. Set up the provider states. Each request's description names its states (Given: an invoice 1042 exists), and the summary lists them all. Without more, set them up on the provider before the run. With --state-setup, each request that needs a state gets a pre-request script that first POSTs {"state", "params", "action": "setup"} per state, in the pact's order, to the {{stateChangeUrl}} variable — the body pact_verifier_cli --state-change-url sends. --state-change-url fills the variable in; otherwise set it in Postman or with newman run … --env-var stateChangeUrl=…. An unset variable or a setup that answers an error stops the request with an error naming the state.

To export every consumer of a provider in one collection, use --provider with --all-consumers (and at most one of --tag or --branch): one folder per consumer, each from its latest such pact. A consumer without one is listed as left-out with the reason, and every notice names its consumer.

Each HTTP interaction becomes one request, with a saved example of the expected response and a test script. The script checks the status, each expected header and the body by Pact's default rules: an object may carry extra keys, an array must have the same length, and every other value must be equal. --no-tests leaves the scripts out.

The summary lists everything the collection does not carry, with the reason:

OutcomeFor
left-outMessage interactions, gRPC calls, interactions without a method, and request bodies that are not text — and, with --all-consumers, a consumer without such a pact. Postman sends HTTP requests with text bodies only.
not-assertedResponse values governed by a matching rule (a regex or type match would be stricter as an equality test), and response bodies that are not text. The saved example still shows the recorded values.
not-appliedRequest generators: the request sends the pact's example values.
infoThe provider states to set up before the run.

--fail-on-left-out exits 1 when an interaction was left out. A pact with no HTTP interaction at all is refused with pact-postman-no-http-interactions. To make a collection from an API specification rather than a pact, use apiome export postman (see Export to an API client). The command calls POST …/v1/tenants/<workspace>/pact-postman-collections (REST reference) and needs Pacts → View.

Choose the output​

--output (-o) picks the format of every command:

ValuePrints
tableAligned columns and pact-broker's sentences (the default)
jsonThe server's answer, unchanged — the same as apiome --json pact …
markdownTables and lists ready for a job summary or a pull-request comment
apiome pact can-i-deploy -a "Billing Service" -e "$GIT_COMMIT" --to-environment production \
-o markdown >> "$GITHUB_STEP_SUMMARY"

Exit codes​

apiome pact exits like pact-broker:

CodeMeans
0It worked; for can-i-deploy, the version can be deployed (or --dry-run); for verify, the run passed
1Anything else: the server refused (no permission, a key of another workspace, an unknown version, a conflict), a flag was wrong, can-i-deploy said no or could not decide, or verify failed
The tests' ownrecord only: the wrapped command failed, so its code is passed on unchanged (even 2)

The rest of the Apiome CLI exits 2 for a bad flag or a refused request; inside apiome pact both are 1, so a script written for pact-broker keeps working. The message on stderr says what went wrong.

Migrating from a Pact Broker​

apiome pact migrate --from <source broker URL> imports an existing Pact Broker or PactFlow workspace into the workspace that PACT_BROKER_BASE_URL names. It carries over pacticipants, versions, pacts, verification results, environments, deployments and webhooks, and keeps their timestamps. Read the token for the source from PACT_SOURCE_BROKER_TOKEN. Start with --dry-run, which writes nothing. A run that stops resumes where it left off. --follow keeps copying what is new every --interval minutes until you stop it, while pipelines move over. The checklist, what is not carried over and what each refusal means are on Migrate from Pact Broker or PactFlow.