Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Build mocks with AI

With your own AI key (or the built-in mock provider), a mock starts from a sentence: describe the API and get a deployed mock on the OpenAPI version you chose. Open any mock whose spec has no examples and be told so, with one click to generate conforming example payloads for every operation (and so for every MCP tool built from it). Change a spec with an instruction and see the diff before it applies. Every call runs through an assist task: validated inputs, a schema-checked answer, the deploy checks, at most two repairs, and nothing applied without your click.

The examples on this page run against the built-in provider (RUSTYBIN_ASSIST_PROVIDER=mock), whose answers are deterministic.

Describe an API

New mock, Describe it in the console: a description, the OpenAPI version (3.1.0 by default, 3.0.3, or Swagger 2.0 for legacy tooling), and the style as chips: authentication (none, API key, bearer, OAuth2 client credentials), pagination (none, page, cursor) and error shape (problem+json or a simple object). Generate streams the progress ("asking openai", "checking the answer", "repairing") and lands in the wizard's review step with the checks and the example coverage; Create and deploy as usual. The same from the assist bar: "make me a petstore clone with OAuth" ends in an apply card that opens the tab with the description filled in.

POST /_rustybin/mocks/ai/spec is the route: the document, its text and the preview (what POST /_rustybin/mocks/import gives); nothing is created.

POST {{base_url}}/_rustybin/mocks/ai/spec
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{
  "description": "An orders API for a coffee shop: customers, products, orders with line items and a payment status",
  "openapi_version": "3.1.0",
  "style": { "auth": "api_key", "pagination": "cursor", "errors": "problem" },
  "stream": false
}
HTTP 200
[Asserts]
jsonpath "$.preview.openapi" == "3.1.0"
jsonpath "$.preview.title" == "Order API"
jsonpath "$.preview.operations" count == 12
jsonpath "$.preview.declares_security" == true
jsonpath "$.preview.report.errors" == 0
jsonpath "$.preview.coverage.complete" == true
jsonpath "$.preview.suggested_name" exists
jsonpath "$.usage.provider" == "mock"
jsonpath "$.sent.user" contains "cursor"
POST {{base_url}}/_rustybin/mocks/ai/spec
Authorization: Bearer {{admin_token}}
Content-Type: application/json
Accept: text/event-stream
{ "description": "A notes API: notes with tags", "openapi_version": "3.0.3" }
HTTP 200
[Asserts]
header "Content-Type" startsWith "text/event-stream"
body contains "event: progress"
body contains "event: result"
body contains "event: done"

The text of the answer is what POST /_rustybin/mocks takes as spec (the console does this in the wizard's review step).

The task asks for an operationId, a summary, a request body schema and at least one success response with a schema and an example on every operation, reuses schemas through components and applies the style. The answer must declare the version asked for, parse, and pass the deploy checks; the errors go back to the model, at most twice. Swagger 2.0 output is converted to OpenAPI 3.0 when the mock is created, as any 2.0 upload is.

Examples, and the alert when a spec has none

A response is served from the spec's example, else its first named example, else an example stored with the mock, else data generated from the schema (see How a response is chosen). Every mock reports its example coverage: which operations have an example for their success responses, in the spec or stored. An operation whose success responses have no body needs none.

  • The detail page shows a banner, "4 of 6 operations have no example for a success response", with Generate with AI and Use generated values, and the operation list says which; the wizard's review step shows the count.
  • The deploy report carries a warning of class no_examples, so check_mock (MCP), rustybin mock validate (CLI) and the report tab say it too; get_mock names the count.
  • GET /_rustybin/mocks/{name}/coverage answers it for the draft and the live revision.
POST {{base_url}}/_rustybin/mocks
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{
  "name": "docs-noex",
  "spec": {
    "openapi": "3.0.3",
    "info": {"title": "Tickets", "version": "1.0"},
    "paths": {
      "/tickets": {
        "get": {"operationId": "listTickets", "responses": {"200": {"description": "ok", "content": {"application/json": {
          "schema": {"type": "array", "items": {"$ref": "#/components/schemas/Ticket"}}}}}}},
        "post": {"operationId": "createTicket",
          "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ticket"}}}},
          "responses": {"201": {"description": "created", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Ticket"}}}}}}
      }
    },
    "components": {"schemas": {"Ticket": {"type": "object", "required": ["id", "title", "priority"],
      "properties": {"id": {"type": "integer", "minimum": 1}, "title": {"type": "string"}, "priority": {"type": "string", "enum": ["low", "normal", "high"]}}}}}
  },
  "deploy": true
}
HTTP 201
[Asserts]
jsonpath "$.coverage.operations" == 2
jsonpath "$.coverage.with_examples" == 0
jsonpath "$.coverage.without[*].id" contains "listTickets"
jsonpath "$.report.findings[?(@.class == 'no_examples')].level" == "warning"

GET {{base_url}}/_rustybin/mocks/docs-noex/coverage
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.complete" == false
jsonpath "$.without" count == 2
jsonpath "$.live.without" count == 2

Generate with AI runs the task examples_for_operations on the operations that lack examples (or the ones you name), ten per call, with a persona ("realistic support tickets", "edge cases"; the dialog suggests a few, and any text works) and one to three examples per response. From an operation's editor, Generate examples and Generate more run it on that operation alone. Every example is validated against its response schema; the failures go back to the model per operation. The dialog previews them per operation; Save to draft stores them in the draft as operations.<id>.examples.<status> with source: ai:

POST {{base_url}}/_rustybin/mocks/docs-noex/ai/examples
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "per_response": 2, "persona": "realistic support tickets", "stream": false }
HTTP 200
[Asserts]
jsonpath "$.applied" == false
jsonpath "$.source" == "ai"
jsonpath "$.examples.listTickets['200']" count == 2
jsonpath "$.examples.createTicket['201'][0].priority" exists
jsonpath "$.usage.provider" == "mock"
POST {{base_url}}/_rustybin/mocks/docs-noex/ai/examples
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "apply": true, "stream": false }
HTTP 200
[Asserts]
jsonpath "$.applied" == true
jsonpath "$.stored" == 2
jsonpath "$.coverage.complete" == true

GET {{base_url}}/_rustybin/mocks/docs-noex
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.settings.operations.listTickets.examples['200'][0].source" == "ai"
jsonpath "$.settings.operations.listTickets.examples['200'][0].name" == "ai-1"
jsonpath "$.has_draft_changes" == true

POST {{base_url}}/_rustybin/mocks/docs-noex/deploy
Authorization: Bearer {{admin_token}}
HTTP 200

# The stored example answers where the spec had none, for REST and the MCP tool alike.
GET {{base_url}}/mock/docs-noex/tickets
HTTP 200
[Asserts]
header "X-Rustybin-Mock-Source" == "example:ai:ai-1"
jsonpath "$[0].priority" exists

POST {{base_url}}/mock/docs-noex/_rustybin/mcp
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: listTickets
{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "listTickets", "arguments": {}, "_meta": {
  "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {}}}}
HTTP 200
[Asserts]
jsonpath "$.result.isError" == false
jsonpath "$.result.structuredContent.body[0].priority" exists

Use generated values needs no key: the deterministic generator fills the same slots (source: generated), so the values the mock served implicitly become stored, visible and editable. Named operations are redone even when covered; a new run replaces the earlier examples of its source and keeps a person's:

POST {{base_url}}/_rustybin/mocks/docs-noex/ai/examples
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "source": "generated", "operations": ["createTicket"], "per_response": 3, "apply": true, "stream": false }
HTTP 200
[Asserts]
jsonpath "$.source" == "generated"
jsonpath "$.stored" == 3

Stored examples appear in the operation editor with their source and are offered by name: Prefer: example=ai-1 picks one, and X-Rustybin-Mock-Source says example:ai:ai-1. The mock's MCP tools return them as tool results, and rustybin.yaml exports carry them under the operation. At most eight per operation and status, each within the mock's body limit.

POST {{base_url}}/_rustybin/mocks/docs-noex/ai/examples
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "stream": false }
HTTP 409
[Asserts]
jsonpath "$.reason" == "nothing_to_do"

Edit with AI

Edit with AI on the detail page: an instruction ("add a DELETE for orders and a 404 example"), the diff of the spec, the checks of the new version, Apply as draft, then the usual Deploy. The task edit_spec returns the whole document; it must keep the version, parse, pass the checks, differ from the original, and may not remove more than 40 percent of the operations unless the instruction asks to remove something.

POST {{base_url}}/_rustybin/mocks/docs-noex/ai/edit
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "instruction": "add a 404 response to every operation", "stream": false }
HTTP 200
[Asserts]
jsonpath "$.applied" == false
jsonpath "$.diff.changed" count == 2
jsonpath "$.diff.removed" count == 0
jsonpath "$.preview.report.errors" == 0
jsonpath "$.before_text" not contains "AI edit"
jsonpath "$.text" contains "\"404\""

POST {{base_url}}/_rustybin/mocks/docs-noex/ai/edit
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{ "instruction": "add a 404 response to every operation", "apply": true, "stream": false }
HTTP 200
[Asserts]
jsonpath "$.applied" == true
jsonpath "$.detail.draft_changes" contains "spec"

Request examples

The task request_examples writes parameter sets and request bodies an operation accepts, validated against its parameter and body schemas, for "Generate arguments" on an MCP tool and sample requests. Call it through POST /_rustybin/assist/run with spec and operation, or use Generate arguments in the MCP inspector when an AI provider is configured.

Who may, and what is sent

The instance's key belongs to the operator: on a self-service instance visitors get 403 from the AI routes unless RUSTYBIN_ASSIST_VISITORS=true (their calls count against the same per-caller cap); Use generated values works for them regardless. The previews of a described spec and of an edit, and the generated values, compile on the shared pool and spend the caller's 30 compiles a minute when it has no admin rights (see Limits). What goes to the provider is the task's prompt: the description or instruction, the spec (or the operations and schemas that need examples) and the style; the "What was sent" record of the console and the sent field of the JSON answers show it exactly, and the redact pass refuses inputs that hold a stored secret or the admin token.

On every surface

The same job from the API, the console, the command line, an agent and the configuration document.

SurfaceWhere
APIPOST /_rustybin/mocks/ai/spec, POST /_rustybin/mocks/{name}/ai/examples, POST /_rustybin/mocks/{name}/ai/edit, GET /_rustybin/mocks/{name}/coverage
ConsoleThe wizard's Describe it tab, the coverage banner with Generate with AI and Use generated values, Edit with AI on a mock, the assist bar's create_mock, generate_examples and edit_spec cards
CLIrustybin mocks describe, rustybin mocks examples <name> [--apply], rustybin mocks edit <name> "..." [--apply], rustybin mocks coverage <name> (reference)
Management MCPgenerate_spec (with create), generate_examples (with apply), edit_spec_with_ai (with apply), check_mock and get_mock with the coverage; the prompt mock_an_api (agent page)
rustybin.yamlStored examples travel with the mock: mocks.<name>.operations.<id>.examples.<status> (configuration as code)
EnvironmentThe provider and key of Bring your own AI; RUSTYBIN_ASSIST_VISITORS lets self-service visitors use them (configuration)