Generate mocks with AI
Before you begin
- Role
- Admin or higher.
- You need
- A project
MockHub can write mocks for you from text that describes an API: a few sentences, an OpenAPI fragment, a curl command or HAR text. Each generation adds up to 50 mocks to the project, all Inactive, so nothing answers until you have checked it.
To turn a HAR file, a Postman collection or curl commands with their output into mocks that answer exactly what was recorded, import them instead: the import copies each response without a model and spends no AI credits. When the pasted text looks like one of these, the dialog offers Import exactly as captured, which opens the import on the same text. Keep AI for what was not recorded: describing an API, drafting responses for commands without output, or making the data vary.
-
On the project’s Mocks tab, select the arrow beside New mock (More ways to add mocks), then Generate. A project with no mocks shows Generate as a button of its own.
-
In Generate mocks with AI, paste the source into API description, or select Load from a file… to read a
.json,.yaml,.yml,.txtor.mdfile into it. -
Select Generate.
While the model works, the dialog shows how far it has got and how long it has taken: Reading your API description…, Planning the mocks…, then a count such as Drafting mocks: 12 of 47, and Saving 47 mocks…. A large API can take a minute or two. The dialog cannot be closed until the generation finishes.
When the mocks use response templates, Rendering dynamic responses in the sandbox… comes before saving.
Result
Section titled “Result”MockHub shows how many mocks it generated, such as 3 mocks generated. The Mocks tab switches to its Inactive mocks, newest first, with the new mocks ticked. A mock whose response template will not render is left unticked, and the message says how many there are.
If the generation left anything to do, a message above the list says so until you select Dismiss: it links to each mock whose response will not render, and lists each mock that was not created with the reason. It stays while you open the mocks to fix them, in that browser tab.
The message also says how many dynamic responses MockHub rendered in the sandbox before saving them, and how many it did not check, such as “3 dynamic responses rendered in the sandbox; one was not checked.”
When the text described no endpoint it says “The description did not describe any endpoints.”
If the connection drops during a generation, the dialog says “The connection closed before the result arrived, but the generation goes on. Its mocks appear in the list as they are created; generating again would create them twice.” The Mocks tab then lists inactive mocks, newest first, and checks for new ones every 10 seconds for three minutes, which is longer than a generation can run. Select Stop checking to end it sooner.
The model may use response templates and fake data in the bodies, and may create scenarios for mocks that belong to a flow. A scenario with the name of one the project already has is reused.
When the workspace’s plan includes the data store and the project uses response templates, the model may also give the mocks of a resource the source creates and reads back a data store write or condition, so that what a client creates comes back from the reads until it is deleted. Each mock’s Data store card shows what it was given.
A generated mock matches on its method and path only, so every request to that endpoint gets its answer, whatever headers, query parameters or body it sends. Where one endpoint needs several answers, the model may add the matchers that tell them apart, such as a JSON path on a field of the body; add your own the same way. It never writes cookie, form field or multipart rules. The paths of an OpenAPI document include its basePath, or the path of its first server URL.
A mock with a matcher MockHub cannot use is left out, and the reason names the matcher. Saved without it, the mock would answer requests the model wrote it to exclude.
Review and activate
Section titled “Review and activate”A generated mock is a draft written by a model, and can be wrong. Check each one before it answers anyone:
-
On the Mocks tab, select the arrow at the start of the mock’s row, labelled Details of and the mock’s name. The row opens on what the mock matches and what it answers.
-
If the response uses templates, select Render a sample to see what it answers a request made up from its matchers, and any expression that failed. Samples do not count towards the workspace’s requests.
-
Select Activate in the opened row, or Delete if the mock is wrong. To change it first, select its name and edit it; see Test a mock before saving.
A mock tagged Duplicate answers exactly the same requests as another mock in the project, such as one an earlier generation from the same text created; its opened row names the others. When one of them is active, select Activate in place of and its name: the new mock is activated and the old one deactivated in one step, which works even at the plan’s limit. Activate as well keeps both active, and MockHub then chooses which one answers. With ticked mocks, the same choice is Activate in place of and the number of active mocks they replace.
Once you have checked them, act on the ticked mocks together: untick any you want to keep, then select Activate, or Delete to remove the ones you do not want. See Several mocks at once.
What is sent to the model
Section titled “What is sent to the model”The text is sent to a third-party AI model, and only to model providers that do not collect the data they receive. Before it leaves MockHub, the values of common secrets are replaced with [REDACTED]: credential headers and cookies, query, form and body fields with secret names such as password, token or api_key, credentials in a URL or in the options of tools such as curl, wget and HTTPie, and the fields in the project’s Body keys to redact in captures. MockHub project access keys and personal, machine and MCP OAuth access tokens are also replaced when they appear in text. A HAR body that is not text is replaced whole. Remove any other secret before you paste.
Limits
Section titled “Limits”- One generation reads at most 32 KiB of text and creates at most 50 mocks. For a larger API, generate from one part at a time.
- The source is text only, pasted or loaded from a text file.
- Each generation spends 5 AI credits, from the allowance the plan sets per day and per month, which the assistant spends too; the limits page lists it. The dialog shows what a generation spends and how many credits are left. No more than five generations can start in the same minute. A generation refused because AI generation is paused or unavailable spends nothing, and one that fails before the AI provider charges for it gives its credits back.
- A mock the model gets wrong is left out rather than saved, and so is one whose name another mock in the project already has. The message above the list names each one left out and why.
- A mock whose response template has a syntax error is still created, and answers with an error until the template is fixed. Try it shows that error and where in the body it is.
- Such a mock is tagged Won’t render on the Mocks tab, and its page says what is wrong and where. Saving a changed response checks it again, so the tag stays until the error is fixed, as on a mock you write yourself.
- Before saving, MockHub also renders each dynamic response in the sandbox, on a request the model wrote for it. A response that fails there, such as one calling a helper that does not exist, or one whose body is not the JSON or XML its
Content-Typenames, is created and tagged Won’t render in the same way. That tag goes with the next change to the response, because a save checks only the template’s syntax. A generation renders at most 20 responses within 10 seconds, which do not count towards the workspace’s requests; a response it did not reach, or whose request the mock does not take, is saved without that check. Responses served as written are not rendered. - If the project is at its scenario limit and the model proposes a new scenario, the whole generation fails.
- A refusal says why: AI generation paused, AI unavailable, AI switched off for this workspace or a plan limit.