Skip to main content

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 record or the GitHub Action's record command 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.

Generate a pact from a mock while recording: Billing API 2.7.0 as the mock and Orders UI 3.4.0 as the consumer, the set-up snippet with the mock address and the X-Mock-Capture header, a counter reading 23 calls, the Captured calls table with four interactions ticked and the chaos and off-spec calls unticked with their reasons, the strictness presets, and beside them The pact so far with 3 of 12 operations used.Generate a pact from a mock while recording: Billing API 2.7.0 as the mock and Orders UI 3.4.0 as the consumer, the set-up snippet with the mock address and the X-Mock-Capture header, a counter reading 23 calls, the Captured calls table with four interactions ticked and the chaos and off-spec calls unticked with their reasons, the strictness presets, and beside them The pact so far with 3 of 12 operations used.
Route/ade/dashboard/pacts/from-mock

Before 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:

  1. 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.
  2. Type the Consumer, for example Orders UI. Pick an existing pacticipant from the suggestions, or type a new name: publishing registers it.
  3. Type the Consumer version the pact is for, for example 3.4.0. A git SHA is ideal.
  4. 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.
  5. 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​

  1. 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.0
    X-Mock-Capture: Orders UI@3.4.0
  2. Click “Copy”, point your consumer at the mock, and add the header to every request (or once, in your HTTP client).

  3. 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.

  4. 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 saysWhat it means
3 paths merged into one interaction/invoices/42, /43 and /107 became one interaction, GET /invoices/{id}.
Answered from the specThe mock's ordinary answer. No provider state.
State from X-Mock-ScenarioThe answer came from a scenario. Its name is the provider state.
Stateful: answered from the X-Mock-SessionThe answer came from the mock's stateful session. The state says what must exist.
2 fields left outFields 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:

PresetValuesResponse fieldsWhat the provider must return
LooseBy typeOnly what was readOnly the fields the consumer read, each of the captured type.
Balanced (default)By typeAll returnedAny value of the same type as the one captured.
StrictFrom the specAll returnedThe same, and also the spec's formats (uuid, date-time, date), patterns and integers.
—ExacteitherExactly 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”.

The Review the generated pact dialog for Orders UI 3.4.0 to Billing Service with 4 interactions: the Changes since the last pact tab lists a new GET /invoices/{id} returning 404, a field no longer needed on GET /customers/{id}, and 2 interactions unchanged, with a note that the pact is looser than before in one place; below are the Branch field and the Keep editing, Download and Publish pact buttons.The Review the generated pact dialog for Orders UI 3.4.0 to Billing Service with 4 interactions: the Changes since the last pact tab lists a new GET /invoices/{id} returning 404, a field no longer needed on GET /customers/{id}, and 2 interactions unchanged, with a note that the pact is looser than before in one place; below are the Branch field and the Keep editing, Download and Publish pact buttons.
Route/ade/dashboard/pacts/from-mock
  1. 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.
  2. Open Pact JSON to read the document itself.
  3. Type the Branch the consumer version was built from, if you use branches.
  4. 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 saysWhat 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 consumerTag it withBecomes
Calls …/graphql (POST or GET)The X-Mock-Capture header, or …/~capture/{token}/graphqlA GraphQL-over-HTTP interaction per operation, such as graphql query GetInvoice returns 200. Verified as GraphQL over HTTP.
Makes a unary gRPC callThe x-mock-capture metadata entryA 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 headerThe 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:

  1. Click “Use past traffic”.
  2. Choose From: Last hour, Last 24 hours (the default), Last 7 days or Everything kept.
  3. 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.
  4. 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.

Generate a pact from a mock with Build from scenarios chosen: the Operations × scenarios table for Billing API 2.7.0 with columns happy-path, server-error, not-found, slow, validation-error and rate-limited, the happy-path answers ticked, dashes for the pairs the mock cannot serve, and below it the Interactions table with each interaction in its scenario's provider state.Generate a pact from a mock with Build from scenarios chosen: the Operations × scenarios table for Billing API 2.7.0 with columns happy-path, server-error, not-found, slow, validation-error and rate-limited, the happy-path answers ticked, dashes for the pairs the mock cannot serve, and below it the Interactions table with each interaction in its scenario's provider state.
Route/ade/dashboard/pacts/from-mock
  1. Click “Build from scenarios”. Every operation's happy-path answer is ticked to start with.
  2. 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.
  3. 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-error and not-found apply to every operation, but only where the spec declares a 500 or a 404.
The dash saysWhy
…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:

  1. 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 --append to keep them.

  2. Run. It runs your command with three variables added to its environment:

    VariableValue
    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 as Orders UI@3.4.0.

    Point the tests' HTTP client at APIOME_MOCK_URL and send the header on every request. A client that cannot add a header can use --capture-url: the command also exports APIOME_MOCK_CAPTURE_URL, a private capture URL that is revoked when the run ends.

  3. Stop. It waits until the mock has stored the calls (at most --settle-timeout seconds, 15 by default).

  4. Generate. It generates the pact as the page does (--matching exact|type|spec) and writes it to pacts/<consumer>-<provider>.json (--pact-dir changes the folder). With --fields read, only the fields the tests reported reading are expected; give recordFieldUsage the APIOME_MOCK_URL and APIOME_MOCK_CAPTURE variables. Without a report the generation is refused, with the reason.

  5. 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 codeWhen
The tests' ownThe 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).
1The 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.
127The command could not be started.
0The 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.

Generate a pact from a mock with Keep it current from CI chosen for Billing API 2.7.0 and Orders UI: the pipeline step apiome pact record --mock billing-api/2.7.0 --consumer Orders UI --publish -- npm test, the Publish when select on The tests pass and the If the pact got looser select on Publish and tell me, the line Last run: main · 3.4.0+a1c9e02 · 6 interactions · unchanged, and under Held for review one pact from Orders UI 3.4.1+b2d0f13 that no longer expects one field, with its Review button.Generate a pact from a mock with Keep it current from CI chosen for Billing API 2.7.0 and Orders UI: the pipeline step apiome pact record --mock billing-api/2.7.0 --consumer Orders UI --publish -- npm test, the Publish when select on The tests pass and the If the pact got looser select on Publish and tell me, the line Last run: main · 3.4.0+a1c9e02 · 6 interactions · unchanged, and under Held for review one pact from Orders UI 3.4.1+b2d0f13 that no longer expects one field, with its Review button.
Route/ade/dashboard/pacts/from-mock
  1. 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.

  2. Copy the pipeline step into the consumer's CI:

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

    Set PACT_BROKER_BASE_URL and PACT_BROKER_TOKEN in the pipeline. The GitHub Action's record command does the same (its publish input is on by default).

  3. Choose the policy. Each choice is saved as soon as you change it and applies from the next run:

    SettingChoiceWhat a build's pact does
    Publish whenThe tests pass (default)Published only when the wrapped tests passed. A failed run publishes nothing and says so.
    AlwaysPublished whatever the tests did.
    If the pact got looserPublish and tell me (default)Published, and the provider's and the consumer's owner teams are told.
    Hold for reviewNot 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.

  1. Select Review next to the pact.
  2. Read Changes since the last pact: what it no longer expects comes first. Pact JSON shows the document.
  3. 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.

The Serve pacts as a mock dialog: Provider set to Billing Service, Pacts to serve on All consumers · latest on main with Orders UI · 3.4.0 and Whatever is deployed to production among the options, When no interaction matches on Answer from the spec with the hint that falling back to the spec mock means the stub is never a dead end, the stub URL ending in ~pacts/billing-service/main, The same, from anywhere with the apiome pact stub command, and the Cancel and Create stub buttons.The Serve pacts as a mock dialog: Provider set to Billing Service, Pacts to serve on All consumers · latest on main with Orders UI · 3.4.0 and Whatever is deployed to production among the options, When no interaction matches on Answer from the spec with the hint that falling back to the spec mock means the stub is never a dead end, the stub URL ending in ~pacts/billing-service/main, The same, from anywhere with the apiome pact stub command, and the Cancel and Create stub buttons.
Route/ade/dashboard/pacts/from-mock
  1. 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.
  2. Select Serve pacts as a mock in the page header.
  3. Choose the Provider whose pacts the stub serves.
  4. 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.
  5. 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.
  6. 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.

  1. Run your consumer, or its tests, against the hosted mock with X-Mock-Capture: <consumer>@<version> on every request.

  2. Find the session: GET …/pact-captures/sessions?consumer=<consumer>.

  3. 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"}'
  4. Read the report, then publish the pact with 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.

FieldWhat it does
sessionThe capture session id. Give exactly one of session, traffic and scenarios.
trafficPast traffic instead of a session. See below.
scenariosOperations × mock scenarios instead of captured calls. See below.
providerThe 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.
matchingexact, type (default) or spec. See How values are matched.
fieldsall (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.
overridesUp to 200 per-field changes. See Override a field.
leave_outInteractions 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.
previousWhat 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"}]}}'
  • traffic takes since and until (each with a time zone) and caller: an API key id, or none for calls made without one. GET …/pacts/generate/traffic with the same query says how many calls the filter holds and lists the window's callers.
  • scenarios takes 1 to 500 pairs. GET …/pacts/generate/scenarios?project=…&version=… lists every pair with servable, or the reason it is not. A pair the mock cannot serve is listed in report.excluded with its scenario and the reason, never dropped silently.
  • report.source.kind says which source the pact came from (session, traffic or scenarios), and report.session is null for the other two. For past traffic, report.source.truncated is true when 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 wasWhy it is left out
Injected by chaos modeThe 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 fromProvider stateparams
A scenario (X-Mock-Scenario: not-found)not-found, the scenario's nameThe path parameters, such as {"id": "7"}
A stateful session (X-Mock-Session), on a path with parametersa resource exists at /invoices/{id}, or no resource exists at /invoices/{id} for a 404The path parameters
A stateful session, on a collectionresources created earlier exist at /invoices—
A stateful POST to a collectionNone: it creates rather than depends on anything—
The specNone—

Register these names once as provider states, so verification can set them up.

How values are matched​

matchingA response value is expected to be
exactEqual to the first call's value. The report notes when other calls returned different values.
typeAny value of the same type. A type rule on $ covers the whole body.
specAs 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"}
]
}
  • interaction is the operation, <METHOD> <spec path>. Add status or state to narrow it to one interaction.
  • path is the response body field, as a Pact path: $.id, $.items[*].sku.
  • match is exact, type, integer, number, decimal, boolean, uuid, datetime, date, regex (with regex), or omit to 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 fieldWhat it holds
sourceWhere the interactions came from: kind is session, traffic or scenarios; for past traffic, the window, calls_in_range, calls_read and truncated
summaryHow many calls the session held (or pairs were asked for), were included and excluded, how many interactions there are, and how many overrides applied
interactionsOne 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_usageThe fields mode used, and the source's reports: available, operations, reports, sources, and unmatched operations no interaction has
excludedEvery call left out, or scenario pair that cannot be served (with its scenario), with the reason
left_out_interactionsEvery interaction leave_out named, with its calls
spec_usageHow 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_checkThe pact compared with the mocked spec revision (AsyncAPI for message pacts): verdict and any failures, or the reason it was not compared
previousThe changes since the consumer's previous pact
sha, bytesThe pact's content address and size; publish_problem says when it is too big to publish
empty_reasonWhy 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.