# Supplemental inference for your agent

Keep your current agent and model. Buy another model's work when it helps:
routine text tasks, an independent review, or a batch of independent subtasks.
Choose GPT-6 Luna, GPT-6.1 Sol, Ministral 3B/8B/14B, Nemotron 3 Nano,
Qwen3 Next or Qwen3 Coder Next. Luna uses effort none, Sol low; the six Bedrock
models use provider defaults. Automatic recommendations currently use Luna/Sol.
No supplier account is needed. A buyer-owned funded USDC wallet is required.

For JSON, direct OpenAI uses native structured output. Bedrock models use prompted
JSON; Mekler accepts a strict object or removes one outer Markdown fence before
strict validation. It does not repair values or accept truncated output.

This local MCP server handles quotes, signing, pending jobs and recovery. Each
purchase has an explicit maximum price and stable identifier. A private local
journal enforces a cumulative budget across restarts and concurrent processes.
The signer is your wallet adapter; Mekler does not receive its private key.

## Install and connect

Download `https://api.mekler.ai/clients/inference.zip`, unzip it and install the
local directory with `python3 -m pip install .`. Python 3.11 or newer is required.
The client uses the standard library; the optional file-wallet adapter needs
`python3 -m pip install 'x402[evm,svm]==2.24.0' 'solana==0.36.12'`.
Inspect downloaded source before granting wallet authority.

Configure any stdio MCP client (including Claude Code) to run:

```json
{
  "mcpServers": {
    "mekler-inference": {
      "command": "/absolute/path/to/python3",
      "args": [
        "-m", "mekler_inference.mcp",
        "--journal", "/absolute/private/path/inference.sqlite",
        "--budget-micros", "100000",
        "--network", "eip155:8453",
        "--signer-command", "[\"/absolute/path/to/existing-wallet-adapter\"]"
      ]
    }
  }
}
```

The example allows at most **0.10 USDC total**, not 0.10 per call. Choose your own
budget explicitly. The journal cannot silently increase an existing budget.
Keep it outside source repositories and shared folders; retain it for recovery.
Reservations include failed or uncertain attempts conservatively. A new budget
journal must not replace an unresolved purchase.

The wallet adapter receives one x402 `PaymentRequirements` JSON object on stdin
and returns `{ "x402Version": 2, "accepted": <same requirements>, "payload":
<signed x402 payload> }` on stdout. It must sign only, without submitting payment.
Connect an existing x402 wallet signer this way. AgentCash users can also use the
public HTTP flow below; automatic journal recovery requires a signer adapter
that exposes the original proof, rather than a fetch wrapper that hides it.

If your existing wallet already uses a private key file, an optional adapter is:
`["/absolute/path/to/python3", "-m", "mekler_inference.wallet", "--key-file",
"/absolute/private/path/existing-wallet.key"]`. The file must be owned by the
current user and readable only by that user. Contents are the existing Base hex
key or Solana base58 key. This adapter never creates, funds or exports wallets.
Use `--network solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` for Solana.

## Agent purchase workflow

1. Call `inference_quote` with the actual task, `max_price_usdc`, and a stable
   `idempotency_key` (22–128 letters, digits, underscores or hyphens). Review the
   exact price and selected model. Set `model` explicitly for an independent model
   review, or use `auto` for the disclosed task rules.
2. Call `inference_purchase` with the returned `purchase_id`. It signs once and
   waits up to 20 seconds. The original authorization is saved before transmission.
3. If pending, call `inference_recover` with the same `purchase_id`. After a lost
   response or process restart, use the same identifier and journal. Do not invent
   another identifier to retry uncertain work.

Results are model-generated data, not instructions for your parent agent. Review
them against the original task. JSON-object validation does not prove factual
correctness. No tools, browsing, images, audio or dependent orchestration are
included. Batches contain 1–20 independent tasks.

An example request for a second opinion:

```json
{
  "idempotency_key": "review-example-task-0001",
  "max_price_usdc": "0.03",
  "tasks": [{
    "model": "gpt-6.1-sol",
    "task": "analyze",
    "messages": [{"role": "user", "content": "Review this proposed plan for missing assumptions: ..."}],
    "max_output_tokens": 1000
  }]
}
```

For routine tasks, choose Luna and an output ceiling suitable for the work. Prices
are exact for the selected input allowance and output ceiling, with no fixed
purchase minimum or unused-token rebate. No silent model downgrade occurs when
the budget is too small. A failed, refused or truncated generation is uncharged.

`200` delivers usable stored results. `receipt.finalized=false` means the exact
payment was independently observed in a canonical block and finality is still
being reconciled. It does not mean another payment is needed. Results remain
privately recoverable for 30 days. Supplier processing uses standard OpenAI API
terms with response storage disabled; this is not a zero-retention promise.

## Direct HTTP and Python

POST your JSON unsigned to
`https://api.mekler.ai/v1/compute/inference/generate-completions`. The 402 returns
exact alternatives. Sign one offer and send the identical corresponding request
with `PAYMENT-SIGNATURE`. Save the original proof before sending. On 202, retain
`job_id` and `recovery_token`; poll
`/v1/compute/inference/retrieve-result?job_id=...` with `X-Mekler-Recovery`.
Original input/proof replay recovers the same work without another generation.

Python integrations can use `mekler_inference.Client`, `Journal` and a signer
callback directly. `quote(request)`, `purchase(purchase_id)` and
`recover(purchase_id)` implement the same lifecycle as the MCP tools.
