Pact from a mock
A consumer that runs against the hosted mock already shows what it relies on. Apiome can turn those calls into the consumer's pact, with no Pact library and no test rewrite. You record the calls, review the pact Apiome writes from them, and publish it. You get an ordinary Pact v4 document, so webhooks, pending pacts and verification work as for any other pact.
The mock answers from the spec, so every captured call already agrees with the provider's contract. The pact adds the part only the consumer knows: which of it the consumer uses. REST, GraphQL, gRPC and event channels all record the same way (see Other protocols), and a consumer that reports which fields it reads gets a pact that expects only those.
There are three ways to do it:
- From the page — Contracts → Generate a pact from a mock. Best for the first pact, and for looking at what a consumer really calls.
- From a pipeline —
apiome pact recordor the GitHub Action'srecordcommand wraps the consumer's tests and publishes the pact when they pass. - With the REST request — from your own script.
Once a pipeline records on every build, keep it current from CI: set, per mock and consumer, when a build's pact is published and what happens when it asks for less than the last one.
No new run is needed when the consumer already called the mock, and no traffic at all is needed to start: see Other sources.
The other direction is here too: serve pacts as a mock gives consumer teams a hosted stub that answers only with what the published pacts promise.
Record, review and publish from the page
Open Contracts, find Start something, and click “Generate a pact from a mock” (or go to
/ade/dashboard/pacts/from-mock). The Publish a pact page also leads here, from its Record
from a mock tab.


/ade/dashboard/pacts/from-mockBefore you start
- The hosted mock must be on for the version you record against. If it is off, the page says so and shows the Hosted mock switch. Only the version's creator or a workspace admin can turn it on.
- You need Pacts → View and Versions → View to record and review, and Pacts → Create to publish.
- Your consumer must be able to send one extra header,
X-Mock-Capture. If it cannot, use a capture URL.
1. Choose the mock and the consumer
Under Where the interactions come from:
- Choose the Mock — project and the Mock — version. The mock's address appears under the version. A version whose mock is off is marked mock off in the list.
- Type the Consumer, for example
Orders UI. Pick an existing pacticipant from the suggestions, or type a new name: publishing registers it. - Type the Consumer version the pact is for, for example
3.4.0. A git SHA is ideal. - Leave Provider empty when one pacticipant is linked to the mocked project. If none is, or more than one, the page asks for the name here.
- Keep Record a session chosen. The other two cards, Use past traffic and Build from scenarios, are described under Other sources.
2. Record a session
-
Click “Start recording”. The page shows two lines under Point your consumer here: the mock's address, and the header to send.
API_BASE_URL=https://mock.apiome.dev/acme/billing-api/2.7.0X-Mock-Capture: Orders UI@3.4.0 -
Click “Copy”, point your consumer at the mock, and add the header to every request (or once, in your HTTP client).
-
Run your app, or its tests. The counter shows how long the page has been recording and how many calls it has. New calls appear within a few seconds.
-
Click “Stop recording” when you are done. Click “Record more” to carry on.
Only calls that carry the header are captured. Other users of the same mock are not affected.
Capturing happens in the mock, not in the page. Recording means the page is watching the calls for this mock version, consumer and consumer version. So you can close the page: choose the same four values later, click “Start recording”, and the calls are still there until they expire. If the version already had captured calls when you started, the page says how many. Click “Start clean” to delete them and begin again. That needs Pacts → Delete.
When the consumer cannot add a header
Open No way to add a header? and click “Create a capture URL”. Every call made under that URL is served by the same mock and recorded for your consumer and version. The URL is shown once, so copy it then. It only tags calls: a private mock still needs its API key. Creating one needs Pacts → Create.
3. Check the captured calls
Captured calls groups the calls the way the pact will: one row per operation, status and provider state. Every row says why it is in or out.
| The row says | What it means |
|---|---|
| 3 paths merged into one interaction | /invoices/42, /43 and /107 became one interaction, GET /invoices/{id}. |
| Answered from the spec | The mock's ordinary answer. No provider state. |
| State from X-Mock-Scenario | The answer came from a scenario. Its name is the provider state. |
| Stateful: answered from the X-Mock-Session | The answer came from the mock's stateful session. The state says what must exist. |
| 2 fields left out | Fields that were not in every response, or whose type changed. |
| Injected by chaos mode… | Not something the provider promises. Always left out. |
| Nothing in the spec matched this call… | A pact cannot be checked against a path the spec does not have. Always left out. |
Untick a row to leave that interaction out of the pact. It stays in the table, marked Left out by request, and you can tick it again. The box in the table's heading ticks or unticks every interaction. Rows that can never be in a pact cannot be ticked.
4. Choose how strict the pact is
Under How strict the pact should be, pick a preset or set Values yourself:
| Preset | Values | Response fields | What the provider must return |
|---|---|---|---|
| Loose | By type | Only what was read | Only the fields the consumer read, each of the captured type. |
| Balanced (default) | By type | All returned | Any value of the same type as the one captured. |
| Strict | From the spec | All returned | The same, and also the spec's formats (uuid, date-time, date), patterns and integers. |
| — | Exact | either | Exactly the values of the first call. Use it for a field or two with an override, not for a whole pact. |
Loose and Only what was read need the consumer to report which fields it reads. Until the session has a report, both are switched off and the hint under Response fields says why, and every field the mock returned is expected. Once a report arrives they switch on by themselves. An operation no report covers keeps every field, and the hint says how many interactions that is.
Sensitive values lists what the mock's redaction rules removed before the calls were stored. A value marked Example was replaced by the spec's example and is matched by type. One marked Removed is not in the pact.
To change one field, click “Override”, choose the Operation, type the Response field
($.id, $.lines[*].sku) and choose Match as. Then click “Add override”. If the captured
values do not fit, the override says Not applied and why.
5. Read the pact so far
The panel beside the form fills in as calls arrive:
- Of the spec, this consumer uses — how many of the spec's operations the pact covers, and how many of the response fields those operations declare. The provider can change the rest without breaking this consumer.
- Against — whether the pact agrees with the mocked spec. Click “Compare with the provider’s versions” to check it against the provider's main branch, what is deployed (production first), and the latest draft, as Check it before it counts does.
6. Review and publish
Click “Review pact”.


/ade/dashboard/pacts/from-mock- Read Changes since the last pact: interactions that are New, those No longer expected, and fields Now expected or No longer needed. If the pact asks for less than the last one, a note says Looser than before: the provider is no longer held to what was dropped.
- Open Pact JSON to read the document itself.
- Type the Branch the consumer version was built from, if you use branches.
- Click “Publish pact”. To publish it from a build instead, click “Download” and use
apiome pact publish.
After publishing, click “See it in the matrix” to watch for the provider's verdict. The new pact is pending until the provider has passed it once.
What the status line means
| The page says | What to do |
|---|---|
| Turn on the hosted mock for Billing API 2.7.0 to record against it. | Use the Hosted mock switch beside it, or ask the version's creator. |
| Waiting for the first call. Check the URL and the X-Mock-Capture header. | Check that the consumer calls the mock's address and sends the header, spelled as shown. |
| Nothing here matches the spec, so there is nothing to put in a pact. | Every call went to a path the spec does not have. Check the base URL and the version. |
| This session's calls are gone (kept 7 days). | Captures expire. Record again. An admin can change how long they are kept. |
| …is a draft, so its mock is private… | Send a workspace API key with every call, as well as the capture header. |
Report which fields the consumer reads
The mock sees what it returned, not what the consumer used. To get a pact that expects only the fields the consumer relies on, let the consumer report what it read. Each report goes to the same capture session as the calls, and Only what was read uses every report the session holds.
In a browser app, load the mock's recorder before your own code. It wraps fetch for calls to
that mock and reports every second, and when the page is hidden:
<script
src="https://mock.apiome.dev/acme/billing-api/2.7.0/__capture__/recorder.js"
data-capture="Orders UI@3.4.0"></script>
In Node, tests or a TypeScript app, use the hook in the SDK's npm package (or the same file from
the mock's recorder.js). Nothing is reported until you call it:
import { recordFieldUsage } from '@acme/billing-sdk/fieldUsage';
const usage = recordFieldUsage({
mockUrl: process.env.APIOME_MOCK_URL!, // a capture URL works too
capture: process.env.APIOME_MOCK_CAPTURE, // "<consumer>@<version>", as in X-Mock-Capture
});
const invoice = await (await usage.fetch(`${process.env.APIOME_MOCK_URL}/invoices/42`)).json();
render(invoice.id, invoice.customer.name);
await usage.stop(); // sends the last report
Send the calls themselves with the X-Mock-Capture header as usual; usage.fetch adds nothing to
them.
What counts as read. Every value your code reads from the parsed body (response.json()):
invoice.customer.name reports $.customer.name, and reading any item of a list reports the field
for all items ($.lines[*].amount). Passing an object on without reading it does not count;
serialising it (JSON.stringify) reads every field in it. For GraphQL the paths are under $.data.
From any other client, post the report yourself. The body is plain JSON, sent as text/plain or
application/json, tagged like a call (the X-Mock-Capture header, a capture member or a capture
URL):
curl -X POST https://mock.apiome.dev/acme/billing-api/2.7.0/__capture__/field-usage \
-H "X-Mock-Capture: Orders UI@3.4.0" \
-d '{"reports": [
{"method": "GET", "path": "/invoices/42", "read": ["$.id", "$.lines[*].amount"]},
{"graphql": {"query": "query GetInvoice { invoice { id } }"}, "read": ["$.data.invoice.id"]},
{"operation": "grpc /billing.Invoices/Get", "read": ["$.invoiceId"]}]}'
The answer (202) says how many items were accepted and lists each refused one with its index and
reason, such as a path no operation of the spec matches. A report for a consumer version with no
captured call is not stored; it is counted on the workspace's capture settings. Each operation keeps
at most 500 read paths, and the reports expire with the session.
GraphQL, gRPC and event channels
The mock records every protocol it serves into the same capture session, and each becomes the matching kind of pact interaction:
| The consumer | Tag it with | Becomes |
|---|---|---|
Calls …/graphql (POST or GET) | The X-Mock-Capture header, or …/~capture/{token}/graphql | A GraphQL-over-HTTP interaction per operation, such as graphql query GetInvoice returns 200. Verified as GraphQL over HTTP. |
| Makes a unary gRPC call | The x-mock-capture metadata entry | A protobuf-plugin Synchronous/Messages interaction, with the version's descriptors in the pact. Verified as a gRPC plugin call. |
Subscribes over WebSocket or SSE (…/events/ws/…, …/events/sse/…) | The header, or …/~capture/{token}/events/… | An Asynchronous/Messages interaction per channel. The first 20 messages of each subscription are recorded. See Message pacts. |
Publishes on demand (…/__channels__/{channel}/publish) | The X-Mock-Capture header | The record that was published, as a message interaction. |
The mock says what it did on each answer: the X-Mock-Capture header on HTTP, WebSocket and SSE
answers, and the x-mock-capture trailing metadata on a gRPC reply (queued, or not-recorded with
x-mock-capture-reason). A record a consumer reads straight from Kafka cannot be told apart from any
other reader's, so it is not recorded: subscribe through the mock, or publish on demand with the
header.
Some calls cannot become an interaction and are listed in report.excluded with the reason: a
streaming gRPC method (a plugin pact replays one unary call), a GraphQL document the mock refused, or
a gRPC message that no longer fits the version's types. Chaos-injected answers are left out as for
REST. The pact is checked against the spec as follows: message pacts against the AsyncAPI form of the
mocked version, REST pacts against its OpenAPI form. GraphQL and gRPC interactions are checked when
the provider verifies the pact, and report.spec_check.reason says so.
Other sources: past traffic and scenarios
A recording needs a run. Two more sources need none. Pick one under Where the interactions come from, after the mock and the consumer. Both give the same Captured calls table, the same strictness choices and the same review as a recording, and the hosted mock does not have to be on.
Use past traffic
Calls the consumer already made with X-Mock-Capture stay in the capture history until they expire.
To build the pact from them:
- Click “Use past traffic”.
- Choose From: Last hour, Last 24 hours (the default), Last 7 days or Everything kept.
- Choose the Caller: Anyone, one API key, or No API key (calls made through a capture URL or to a public mock). Each choice shows how many calls it made.
- Read the line under the filters, for example 1,840 calls in range · 3 consumer versions · kept for 7 days. The calls of every version of the consumer count. The pact is generated for the Consumer version you typed.
Environment label is shown but cannot be changed yet: captured calls carry no environment label, so the history cannot be narrowed by one.
One generation reads the newest 5,000 calls of the range. When the range holds more, the line says the newest 5,000 are used. Narrow the window or choose a caller to use the rest.
Build from scenarios
To write a contract before any consumer code exists, tick what the consumer will rely on. Each scenario of the mock (the four built-in ones and those saved on the version, see Mock scenarios) is a column. Each operation of the spec is a row.


/ade/dashboard/pacts/from-mock- Click “Build from scenarios”. Every operation's happy-path answer is ticked to start with.
- Tick each other pair you want, for example GET /invoices/{id} in not-found. Each tick
becomes one interaction, and its provider state is the scenario's name. That is the same
name the provider registers, and the one a consumer sends as
X-Mock-Scenario. - A dash (—) marks a pair the mock cannot serve as one fixed answer. Click the dash to read why under the table. To change what a scenario answers, click “Edit scenarios”.
The answers come from the version's stored scenarios and the spec:
- happy-path answers with the operation's lowest success status. Its body is the spec's example, or one built from the schema that follows its formats, patterns, lengths and ranges.
- A scenario's canned answer is used as it is. In a sequence, the first answer is used, and the interaction's notes say so. A scenario that only pins a status answers it with a body from the spec.
- The built-in
server-errorandnot-foundapply to every operation, but only where the spec declares a500or a404.
| The dash says | Why |
|---|---|
| …does not change GET /x: the mock answers it as happy-path does. | The scenario has nothing for this operation. Tick happy-path instead. |
| …only adds latency or injected failures… | Like slow: the answer is the same as happy-path's. |
| …answers GET /x by rules over the request… | The answer depends on the request. Record a session instead. |
| …is a template rendered from each request… | The body is built per request. Record a session instead. |
| …is marked off-spec… | The answer is deliberately outside the spec, so no provider can be held to it. |
| The spec declares no 404 response for GET /x… | The provider does not promise that status. |
| …does not fit the spec's 404 schema… | The canned body breaks the spec, so no provider could satisfy it. |
| The spec gives no example… and one built from its schema does not fit it… | Add an example to the spec, or record a session. This also covers a request body that cannot be built. |
The same, from anywhere shows the REST request for both sources. No apiome pact command
generates from past traffic or scenarios yet.
Record from a pipeline
Recording by hand does not belong in a pipeline. apiome pact record wraps the consumer's test
command and does the whole round trip:
-
Start. It finds the version's hosted mock (and stops, saying how to turn it on, when the mock is off). An earlier capture of the same consumer version is deleted, so the pact holds this run's calls only. Pass
--appendto keep them. -
Run. It runs your command with three variables added to its environment:
Variable Value APIOME_MOCK_URLWhere the mock answers, such as https://mock.apiome.dev/acme/billing-api/2.7.0.APIOME_MOCK_CAPTURE_HEADERX-Mock-Capture.APIOME_MOCK_CAPTURE<consumer>@<version>, such asOrders UI@3.4.0.Point the tests' HTTP client at
APIOME_MOCK_URLand send the header on every request. A client that cannot add a header can use--capture-url: the command also exportsAPIOME_MOCK_CAPTURE_URL, a private capture URL that is revoked when the run ends. -
Stop. It waits until the mock has stored the calls (at most
--settle-timeoutseconds, 15 by default). -
Generate. It generates the pact as the page does (
--matching exact|type|spec) and writes it topacts/<consumer>-<provider>.json(--pact-dirchanges the folder). With--fields read, only the fields the tests reported reading are expected; giverecordFieldUsagetheAPIOME_MOCK_URLandAPIOME_MOCK_CAPTUREvariables. Without a report the generation is refused, with the reason. -
Publish. With
--publish, it hands the pact, the tests' result, the branch, tags and build URL to the mock's recording policy. By default the policy publishes the pact only when the tests passed; a pact that got looser is published and the owners are told, or held for review. The report prints what the policy did and why.
apiome pact record \
--mock billing-api/2.7.0 \
--consumer "Orders UI" \
--matching type --publish \
-- npm test
The command runs as you write it after --, not through a shell. To run several commands, wrap them:
-- bash -c "npm ci && npm test". The version defaults to the commit (the CI's commit variable, then
git rev-parse HEAD) and the branch to the CI's or git's; --consumer-app-version and --branch
override them.
In GitHub Actions, the pact-action runs the same thing:
- uses: apiome/apiome/pact-action@main
with:
command: record
mock: billing-api/2.7.0
pacticipant: Orders UI
run: npm test
fields: read # only the fields the tests reported reading; all is the default
broker-base-url: ${{ secrets.PACT_BROKER_BASE_URL }}
broker-token: ${{ secrets.PACT_BROKER_TOKEN }}
What the run reports, and its exit code
The report lists every call that did not reach the pact, with its reason: calls the mock did not store (the session was full, or a credential was left after redaction), calls left out (chaos, off-spec, refused by the mock) and fields left out of an interaction.
| Exit code | When |
|---|---|
| The tests' own | The tests failed. The pact is still written, so you can look at it. With --publish the policy decides: by default it is not published (Publish when Always publishes it anyway). |
1 | The tests passed but something else did not happen: no call was recorded, nothing could become an interaction, or the generation or the publish was refused. The reason is printed. |
127 | The command could not be started. |
0 | The tests passed and every step you asked for worked. A pact the policy held for review counts as worked: the report says where to review it. |
The permissions the key needs
Reading the captures and generating need Pacts → View and Versions → View. Starting
clean needs Pacts → Delete (or pass --append). --capture-url needs Pacts → Create
and Edit, and --publish needs the usual publish permission (Pacts → Create; an API key
with the pact:publish scope may call it).
Keep it current from CI
A pact recorded once goes stale, and a pact that silently drops an expectation removes protection without anyone noticing. Keep it current from CI runs the recording on every build and lets you decide what happens to each build's pact.


/ade/dashboard/pacts/from-mock-
Go to Contracts → Generate a pact from a mock, choose the mock (project and version) and the consumer, and under Where the interactions come from choose Keep it current from CI.
-
Copy the pipeline step into the consumer's CI:
- run: apiome pact record --mock billing-api/2.7.0 --consumer "Orders UI" --publish -- npm testSet
PACT_BROKER_BASE_URLandPACT_BROKER_TOKENin the pipeline. The GitHub Action'srecordcommand does the same (itspublishinput is on by default). -
Choose the policy. Each choice is saved as soon as you change it and applies from the next run:
Setting Choice What a build's pact does Publish when The tests pass (default) Published only when the wrapped tests passed. A failed run publishes nothing and says so. Always Published whatever the tests did. If the pact got looser Publish and tell me (default) Published, and the provider's and the consumer's owner teams are told. Hold for review Not published. It waits under Held for review until someone decides.
The line under the selects shows the last run: its branch, consumer version, how many interactions the pact had, and whether it was the first pact, unchanged, changed or looser — or that it was held, or not published because the tests failed. Until someone saves a policy, the defaults apply.
When a pact counts as looser
Each run's pact is compared with the consumer's latest published pact for the same provider, the way Review pact compares them. The pact got looser when it no longer expects an interaction the last pact did, or no longer expects a response field of an interaction both have. A provider verified against the old pact stays verified for what is unchanged, but nothing protects what was dropped.
Owner teams are found the way every Pact finding is: the pacticipant's own owner, else the owner of its consumer-registry entry or project, else it is reported as unowned (see Give a pacticipant an owner). A team that owns both sides is told once. The notification links to the published pact.
Review a held pact
A held pact is never lost: it stays under Held for review until someone decides, and the Contracts landing's status strip says how many wait.
- Select Review next to the pact.
- Read Changes since the last pact: what it no longer expects comes first. Pact JSON shows the document.
- Decide:
- Publish pact publishes exactly that document, for the consumer version, branch and tags it was recorded with.
- Discard does not publish it. Optionally say why first, under Why discard it. The pact is kept, marked discarded.
- Keep it held closes the dialog and changes nothing.
If the publish is refused — for example because that consumer version already has a different pact for the provider — the reason is shown and the pact stays held.
The same over REST
# Read, then save, the policy of one mock and consumer
curl -H "X-API-Key: $APIOME_API_KEY" \
"$APIOME_URL/v1/tenants/acme/pact-recording/settings?project=billing-api&version=2.7.0&consumer=Orders%20UI"
curl -X PUT -H "X-API-Key: $APIOME_API_KEY" -H "Content-Type: application/json" \
-d '{"project":"billing-api","version":"2.7.0","consumer":"Orders UI","publish_when":"tests-pass","if_looser":"hold"}' \
"$APIOME_URL/v1/tenants/acme/pact-recording/settings"
# The pacts waiting for review, then publish or discard one
curl -H "X-API-Key: $APIOME_API_KEY" "$APIOME_URL/v1/tenants/acme/pact-recording/held"
curl -X POST -H "X-API-Key: $APIOME_API_KEY" "$APIOME_URL/v1/tenants/acme/pact-recording/held/$HELD_ID/approve"
curl -X POST -H "X-API-Key: $APIOME_API_KEY" -H "Content-Type: application/json" \
-d '{"note":"The field moved to v2"}' "$APIOME_URL/v1/tenants/acme/pact-recording/held/$HELD_ID/discard"
apiome pact record --publish calls POST …/pact-broker/pacts/record with the capture session, the
pact and the tests' result. Its answer's outcome is published, held or skipped, with the
reason in reason. Every field is in the Pact Broker API reference.
Serve pacts as a mock
A consumer developed against the spec mock gets everything the spec allows, so it can come to rely
on fields no pact protects. A pact stub answers with what the published pacts promise instead.
Each request gets the example of the interaction it matches, and each provider state is a scenario.
A request no pact covers is answered by the spec mock, so the stub is never a dead end, or with a
501.


/ade/dashboard/pacts/from-mock- Open Contracts → Generate a pact from a mock, and choose the mock in section 1. Its spec answers what no pact covers. You can also choose Serve as a mock in the ⋯ menu of a row on the Contracts landing.
- Select Serve pacts as a mock in the page header.
- Choose the Provider whose pacts the stub serves.
- Choose the Pacts to serve:
- All consumers · latest on main — each consumer's latest pact from its main branch;
- consumer · version — the pact of the consumer version named in section 1 (for example Orders UI · 3.4.0);
- Whatever is deployed to an environment, or anywhere — every consumer version deployed there now.
- Under When no interaction matches, choose Answer from the spec (the mock of section 1) or Return 501. Answer from the spec is unavailable until section 1 names a mock.
- Select Create stub.
The dialog then shows the stub's URL and what it serves: the pacts, the provider states to send as
X-Mock-Scenario, and a ready curl call. Everything it does not serve is listed with the reason:
messages, plugin interactions, duplicates, or a source that chose no pact. Select Update stub
after a change; a stub of the same name is replaced.
Call the stub with a workspace API key:
export STUB=https://mock.apiome.dev/acme/~pacts/billing-service/main
curl -H "X-Api-Key: $APIOME_API_KEY" -H 'X-Mock-Scenario: invoice 7 exists' "$STUB/invoices/7"
Every answer carries X-Mock-Stub: pact when an interaction answered, fallback-spec when the spec
mock did, or no-match for the 501. X-Mock-Stub-Reason says why no interaction answered. The
stub is rebuilt as soon as its pacts change, for example when a consumer publishes a new pact or a
deployment is recorded. How the mock matches requests is on
Pact stubs.
From a pipeline or over REST
apiome pact stub saves the same stub and prints what it serves:
apiome pact stub --provider "Billing Service" --pacts main,deployed --fallback-mock billing-api/2.7.0
apiome pact stub --provider "Billing Service" --pacts "Orders UI@3.4.0" --fallback not-implemented
--pacts takes main, deployed, deployed:<environment> and <consumer>@<version>,
comma-separated or repeated. --name sets the URL's last segment (by default it is made from
--pacts). --delete stops serving the stub.
Over REST, PUT /v1/tenants/{tenant}/pact-stubs/{provider}/{name} saves it:
curl -X PUT https://api.apiome.dev/v1/tenants/acme/pact-stubs/billing-service/main \
-H "X-API-Key: $APIOME_API_KEY" -H 'Content-Type: application/json' \
-d '{"sources": [{"kind": "main"}], "fallback": "spec",
"fallback_mock": {"project": "billing-api", "version": "2.7.0"}}'
GET …/pact-stubs/{provider}/{name} reads the stub and its report. GET …/pact-stubs lists the
workspace's stubs. DELETE …/pact-stubs/{provider}/{name} deletes one.
Generate the pact with the REST request
First capture the consumer's calls into a
capture session. Then ask Apiome to generate the pact from it. In a pipeline,
apiome pact record does both for you. To use
past traffic or scenarios instead, send traffic or
scenarios in place of session.
-
Run your consumer, or its tests, against the hosted mock with
X-Mock-Capture: <consumer>@<version>on every request. -
Find the session:
GET …/pact-captures/sessions?consumer=<consumer>. -
Generate the pact from it:
curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/generate \-H "Authorization: Bearer $APIOME_API_KEY" \-H "Content-Type: application/json" \-d '{"session": "<session id>", "matching": "spec"}' -
Read the
report, then publish thepactwith the usual publish request.
Nothing is stored by this request. Generating twice from an unchanged session gives the same pact, so publishing it again changes nothing.
| Field | What it does |
|---|---|
session | The capture session id. Give exactly one of session, traffic and scenarios. |
traffic | Past traffic instead of a session. See below. |
scenarios | Operations × mock scenarios instead of captured calls. See below. |
provider | The provider's name. Defaults to the pacticipant bound to the mocked project. If none is bound, or more than one, the request is refused with pact-generate-provider-unknown. |
matching | exact, type (default) or spec. See How values are matched. |
fields | all (default) or read: only the fields the consumer reported reading. A source with no report is refused with pact-generate-field-usage-unavailable; for past traffic, the reports of every session in the range count. |
overrides | Up to 200 per-field changes. See Override a field. |
leave_out | Interactions to keep out of the pact, each by its description, such as GET /invoices/{id} returns 404 given not-found. Each is listed in report.left_out_interactions. A name the session has no interaction for is listed there too, never ignored silently. |
previous | What to compare with: latest (default) is the consumer's newest pact for the provider, none skips the comparison, or give a consumer version number. |
Past traffic and scenarios over REST
Both sources name the mock and the consumer the same way: project (slug), version (label),
consumer and consumer_version.
# Past traffic: the consumer's calls of the last day, made with one API key
curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/generate \
-H "Authorization: Bearer $APIOME_API_KEY" -H "Content-Type: application/json" \
-d '{"traffic": {"project": "billing-api", "version": "2.7.0", "consumer": "Orders UI",
"consumer_version": "3.4.0", "since": "2026-11-27T09:00:00Z", "caller": "<API key id>"}}'
# Scenarios: no traffic at all
curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/generate \
-H "Authorization: Bearer $APIOME_API_KEY" -H "Content-Type: application/json" \
-d '{"scenarios": {"project": "billing-api", "version": "2.7.0", "consumer": "Orders UI",
"consumer_version": "3.4.0", "pairs": [
{"operation": "GET /invoices/{id}", "scenario": "happy-path"},
{"operation": "GET /invoices/{id}", "scenario": "not-found"}]}}'
traffictakessinceanduntil(each with a time zone) andcaller: an API key id, ornonefor calls made without one.GET …/pacts/generate/trafficwith the same query says how many calls the filter holds and lists the window's callers.scenariostakes 1 to 500pairs.GET …/pacts/generate/scenarios?project=…&version=…lists every pair withservable, or thereasonit is not. A pair the mock cannot serve is listed inreport.excludedwith itsscenarioand the reason, never dropped silently.report.source.kindsays which source the pact came from (session,trafficorscenarios), andreport.sessionisnullfor the other two. For past traffic,report.source.truncatedistruewhen the range held more than the 5,000 calls one generation reads.
How calls become interactions
Apiome groups the calls by operation (method and spec path), status and provider state.
Each group becomes one interaction. So GET /invoices/42, /43 and /107, all answered 200, are
one interaction, GET /invoices/{id} returns 200.
Some calls are left out. Each one is listed in report.excluded with its reason:
| The call was | Why it is left out |
|---|---|
| Injected by chaos mode | The provider does not promise that answer. |
Not in the spec (off-spec) | A pact cannot be checked against a path the spec does not have. |
Refused by the mock (rejected) | The request itself does not satisfy the spec. |
A status the consumer forced with Prefer: code= is kept, with a note that the provider must be able
to return it.
For each interaction, the request is the first call's: its path, its query, the headers the spec
declares as parameters, and its body. Other headers, such as User-Agent, belong to the client, not
to the contract. The report names them in the interaction's notes. With type or spec matching,
the request path is matched by the spec's parameter shapes, for example ^/invoices/-?\d+$ for an
integer id.
Where provider states come from
The provider state is taken from whatever produced the mock's answer:
| The answer came from | Provider state | params |
|---|---|---|
A scenario (X-Mock-Scenario: not-found) | not-found, the scenario's name | The path parameters, such as {"id": "7"} |
A stateful session (X-Mock-Session), on a path with parameters | a resource exists at /invoices/{id}, or no resource exists at /invoices/{id} for a 404 | The path parameters |
| A stateful session, on a collection | resources created earlier exist at /invoices | — |
A stateful POST to a collection | None: it creates rather than depends on anything | — |
| The spec | None | — |
Register these names once as provider states, so verification can set them up.
How values are matched
matching | A response value is expected to be |
|---|---|
exact | Equal to the first call's value. The report notes when other calls returned different values. |
type | Any value of the same type. A type rule on $ covers the whole body. |
spec | As for type, and also the spec's uuid, date-time and date formats, its patterns, and its integers. |
A rule is only written when every captured value satisfies it. If a value does not fit the spec's
format, the field keeps a type match, and a note gives the value. In type and spec mode, a field
that was null in some responses and a value in others is matched as "that type, or null".
Response fields. A field is expected when it is in every response of the group. A field that some
responses lack, or whose type changes between responses, is left out. Each one is listed in the
interaction's left_out with the reason. Array items are merged into one example item.
Redacted values. The mock's redaction rules remove sensitive values before a call is stored. A
response field that was removed is restored from the spec's example, with a type match, so the
placeholder is never an exact expectation. If the spec gives no example, the field is left out.
Either way it is listed: under redacted, or under left_out.
Override a field
An override changes how one response field is matched:
{
"session": "<session id>",
"overrides": [
{"interaction": "POST /invoices", "path": "$.id", "match": "uuid"},
{"interaction": "GET /invoices/{id}", "status": 200, "path": "$.issued_at", "match": "datetime"},
{"interaction": "GET /customers/{id}", "path": "$.phone", "match": "omit"}
]
}
interactionis the operation,<METHOD> <spec path>. Addstatusorstateto narrow it to one interaction.pathis the response body field, as a Pact path:$.id,$.items[*].sku.matchisexact,type,integer,number,decimal,boolean,uuid,datetime,date,regex(withregex), oromitto leave the field out.
An override is applied only where the field exists and every captured value satisfies it. In
report.overrides, each override lists what it was applied_to. Where it was not applied,
not_applied gives the reason.
Read the report
| Report field | What it holds |
|---|---|
source | Where the interactions came from: kind is session, traffic or scenarios; for past traffic, the window, calls_in_range, calls_read and truncated |
summary | How many calls the session held (or pairs were asked for), were included and excluded, how many interactions there are, and how many overrides applied |
interactions | One row per interaction: its protocol (http, graphql, grpc, message), its calls, notes, left_out and redacted fields, and fields (read when only the fields read are expected) |
fields, field_usage | The fields mode used, and the source's reports: available, operations, reports, sources, and unmatched operations no interaction has |
excluded | Every call left out, or scenario pair that cannot be served (with its scenario), with the reason |
left_out_interactions | Every interaction leave_out named, with its calls |
spec_usage | How much of the mocked spec the pact uses: operations_used of operations_total, and response_fields_used of response_fields_total (the fields the used operations declare). null when the spec could not be read |
spec_check | The pact compared with the mocked spec revision (AsyncAPI for message pacts): verdict and any failures, or the reason it was not compared |
previous | The changes since the consumer's previous pact |
sha, bytes | The pact's content address and size; publish_problem says when it is too big to publish |
empty_reason | Why pact is null, for example when nothing matched the spec |
Changes since the previous pact. previous lists the interactions that are new (added), those
the consumer no longer needs (removed), and, for the others, the response fields now expected
(fields_added) and no longer expected (fields_removed). looser is true when something the
previous pact expected is no longer expected. A provider verified against the old pact stays
verified for the unchanged parts, but nothing protects what was dropped. Interactions are paired by
method, spec path, status and provider state, so a hand-written previous pact compares too.
Who can do what
Generating a pact needs Pacts → View and Versions → View, because the mocked spec revision is read. It writes nothing. Publishing the result needs the usual publish permission. A workspace may generate as many pacts per minute as it may run pre-publish checks.
For Keep it current from CI: reading the policy and the held pacts needs Pacts → View;
changing the policy and discarding a held pact need Pacts → Edit; a CI run with --publish
and Publish pact on a held pact need Pacts → Create. Saving the policy, each run, each
approval and each discard is in the audit log.
For Serve pacts as a mock: creating or replacing a stub needs Pacts → Create, reading stubs Pacts → View, and deleting one Pacts → Delete. Each save and delete is in the audit log. Calling a stub needs a workspace API key.
Related
- Capture for a consumer — record the calls.
- Pact stubs — how a stub answers, and its headers.
- Publish pacts — publish the generated pact.
- Run Pact in CI — the
recordstep in a pipeline. - Pact Broker CLI —
apiome pact record,apiome pact stuband their flags. - Provider states — register the states the pact names.
- Pact Broker API — the
pacts/generaterequest and its errors.