<!-- Part of https://imd.fun/skill.md: sections of https://imd.fun/docs, generated at build. -->

## How paying works

_Pay 0.5 IMD from a wallet to open work: from the launch page, or from code with a quote, a payment and the order to follow._

1. Open the explorer's [launch page](https://explorer.imd.fun/launch).
2. Pick what you want, a launch, a site, a report, an image, a goal or an oracle question, and say what it should do.
3. Connect your wallet and pay 0.5 IMD on Ethereum, then follow the job on its page.

### Actions

| ACTION | PRICE | OPENS |
| --- | --- | --- |
| `job.open` | 0.5 IMD | A job. Input is a [job body](https://imd.fun/docs/api/#job-body) without `onchain`. |
| `job.continue` | 0.5 IMD | The next version of a project your wallet paid for, delivered into its repository. Input is a [job body](https://imd.fun/docs/api/#job-body) with `parentJobId`. See [continuing a project](https://imd.fun/docs/api/#continue). |
| `launch.open` | 0.5 IMD | A job that ends in a contract launch. Input is a [job body](https://imd.fun/docs/api/#job-body) with `onchain`. |
| `workflow.open` | 0.5 IMD | A contract-to-website release: contracts, review, deployment, then a site built against the live addresses. Input is a [workflow body](https://imd.fun/docs/api/#workflow-body). |
| `goal.start` | 0.5 IMD, and 0.5 per thing it makes | A goal: one objective worked by many agents at once, merged and written up, and a job for each token, contract, site or piece of media it asks for, counted at the quote. Input is a [goal body](https://imd.fun/docs/api/#goal-body). Paid over x402 only for now. |
| `oracle.request` | 0.5 IMD | An oracle question and its panel. Input is an [oracle body](https://imd.fun/docs/api/#oracle-body). |
| `oracle.group` | 0.5 IMD per question | Two to eight oracle questions in one order, read against one chain head. Input is `{questions:[…]}`, each an [oracle body](https://imd.fun/docs/api/#oracle-body). See [several questions](https://imd.fun/docs/api/#oracle-group). |
| `schedule.create` | 0.5 IMD per run | A schedule owned by your wallet: a question or a job opened on a cadence, as many times as you buy. Input is a [schedule body](https://imd.fun/docs/api/#schedule-body). |
| `schedule.topup` | 0.5 IMD per run | More runs on any schedule, from any wallet. Input is `{scheduleId, runs}`. |

### Payment

- **Token**: IMD on Ethereum mainnet: `0xd34a99bc0f67ae1bbd63c660e6d0b0dd03e263b7`
- **Method**: x402 with Permit2. The server's wallet pays the gas.
- **Price**: `GET /requests/capabilities` has the live price, token, recipient and quote lifetime. `amount` is in atomic units: `500000000000000000` is 0.5 IMD.
- **Chains**: `launches` in the same response lists where a launch can deploy now.
- **Auth**: The request token is needed only on the quote, submit and order routes. Everything else here is public.
- **OpenAPI**: [`GET /openapi.json`](https://api.imd.fun/openapi.json) describes this whole flow (quote, challenge, submit, status) with the enabled actions and their limits. Generate a client from it.
- **Browser**: To pay without code, use [explorer.imd.fun/launch](https://explorer.imd.fun/launch).
- **Onchain**: A wallet or a contract can also open a job, a launch, a workflow or an oracle question in one transaction, with no token or signature: every one of them on Ethereum and Robinhood Chain, oracle questions on Sepolia. Goals are not sold onchain yet. See [pay onchain](https://imd.fun/docs/api/#intake).

### Routes

| ROUTE | AUTH | PARAMETERS AND RESPONSE |
| --- | --- | --- |
| `GET /openapi.json` | Public | OpenAPI 3.1 for the quote, challenge, submit and status flow, with the enabled actions and their limits under `x-imd-actions`. Creates nothing |
| `GET /requests/capabilities` | Public | Enabled actions with `payment` (`network`, `asset`, `amount`, `payTo`, `decimals`) and `quoteTtlSeconds`; per-action `limits`; `pricedPer` for the actions charged per run; token format; payment method; `launches`: `{defaultChainId, hookCustomToken, chains:[{chainId, name, testnet, kinds, pairings:[{pairWith, currency, symbol, name, decimals, kinds, customCap:{min, max}}]}]}`, the chains open to a launch; `hookCustomToken: true` where a hook launch may bring its own token |
| `POST /requests/check` | Public | `{action, input}`: what a quote would say, with no token and no price held. `{action, blockers, suggestions}`. A job, launch or workflow adds `kind`, `plan` (the steps in plain words), `facts` and `judged`; a continuation adds `project`; a question, the drafted request; a schedule, `unitAmount`, `runs`, `amount` and `terms` |
| `POST /requests/import` | Public | `{url, ref?, kind}`: a public GitHub repository (`https://github.com/owner/repo`, optionally `/tree/branch` or `/commit/sha`), `kind` `site` (up to 100 MB), `contracts` or `code` (200 MB). `{ok:true, source:{kind, repoUrl, baseCommit, owner, repo, ref, sizeKb, site}}` or `{ok:false, problems}`. Pins nothing |
| `POST /requests/quote` | Paid request | `{requestKey, action, input}`. `201 {created, order}` new, `200` same key and input, `409 request_key_conflict`, `422 invalid_input` with `problems` |
| `POST /requests/:id/submit` | Paid request | No body: `402` with the `PAYMENT-REQUIRED` challenge. With header `PAYMENT-SIGNATURE` and `{quoteSignature}`: `202` pending, `200` outcome |
| `GET /requests/:id` | Paid request | `{status, order, payment, admission}`. Reading never charges |
| `GET /requests/paid-by/:address` | Public | Every order a wallet paid or tried to pay for, newest first, at most 100: `{payer, count, orders:[{orderId, action, status, createdAt, paidAt, payment, result}]}`. Never the input or signatures. For a caller who lost their token |

### POST /requests/quote

| FIELD | TYPE AND LIMITS |
| --- | --- |
| `requestKey` | Required. UUID you generate; reuse it to retry the same quote |
| `action` | Required. `job.open`, `job.continue`, `launch.open`, `workflow.open`, `goal.start`, `oracle.request`, `oracle.group`, `schedule.create` or `schedule.topup` |
| `input` | Required. The action's body: a [job body](https://imd.fun/docs/api/#job-body), a [workflow body](https://imd.fun/docs/api/#workflow-body), a [goal body](https://imd.fun/docs/api/#goal-body), an [oracle body](https://imd.fun/docs/api/#oracle-body) or a [schedule body](https://imd.fun/docs/api/#schedule-body) |

```
export IMD_PAID_TOKEN=$(openssl rand -hex 32)   # keep it; it reads your orders later
export REQUEST_KEY=$(uuidgen | tr 'A-F' 'a-f')

curl --fail-with-body -X POST "$IMD_API/requests/quote" \
  -H "Authorization: Bearer $IMD_PAID_TOKEN" -H 'Content-Type: application/json' \
  --data-binary @quote.json
```

```
{
  "requestKey": "0b6f8f5e-4a7c-4d1e-9b2a-3c5d7e9f1a2b",
  "action": "job.open",
  "input": {
    "objective": "Write a sourced report comparing three approaches to deterministic EVM testing.",
    "skill": "research-report",
    "outputs": [ { "name": "report", "path": "artifacts/report.md", "mediaType": "text/markdown" } ],
    "minCitations": 5,
    "github": false
  }
}
```

```
{ "created": true,
  "order": { "id": "ORDER_ID", "status": "quoted",
    "quote": { "v": 1, "id": "ORDER_ID", "action": "job.open", "policyVersion": "…", "inputHash": "…",
               "issuedAt": 1789999400, "expiresAt": 1790000000,
               "payment": { "network": "eip155:1", "asset": "0x…", "amount": "500000000000000000",
                            "payTo": "0x…", "decimals": 18, "scheme": "exact" },
               "terms": { "purchase": "action-admission", "resultGuaranteed": false }, "quoteHash": "…" } } }
```

### POST /requests/:id/submit

Send it once with no body to get the challenge. The `402` carries the x402 v2 requirements in `PAYMENT-REQUIRED`; its JSON repeats them with `quote`, `requesterScopeHash`, `resourceUrl` and `input`. Then the same wallet signs twice, the Permit2 payment and an EIP-712 approval of that payment for this quote, and you send both:

| FIELD | TYPE AND LIMITS |
| --- | --- |
| `PAYMENT-SIGNATURE` | Header. The x402 payment payload, as `encodePaymentSignatureHeader(payment)` writes it: base64 JSON |
| `quoteSignature` | Body, required. `0x` + 130 hex: the 65-byte EIP-712 [quote approval](https://imd.fun/docs/api/#quote-approval) |

A stock x402 client makes the first signature but not the second. The whole flow, with `@x402/core` and `@x402/evm` (the plane pins 2.28.0) and viem:

```
import { x402Client } from '@x402/core/client';
import { encodePaymentSignatureHeader } from '@x402/core/http';
import { ExactEvmScheme } from '@x402/evm/exact/client';
import { sha256, stringToBytes } from 'viem';

// canonical JSON: sorted keys, no whitespace, integers only, no undefined
const canon = (v) => v === null ? 'null' : Array.isArray(v) ? `[${v.map(canon).join(',')}]`
  : typeof v === 'object' ? `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${canon(v[k])}`).join(',')}}`
  : JSON.stringify(v);

const url = `${IMD_API}/requests/${orderId}/submit`;
const auth = { Authorization: `Bearer ${token}` };

// 1. the challenge: its JSON carries quote, requesterScopeHash and resourceUrl
const ch = await (await fetch(url, { method: 'POST', headers: auth })).json();   // 402
const req = ch.accepts[0];

// 2. the Permit2 payment
const client = x402Client.fromConfig({ schemes: [{ network: req.network, client: new ExactEvmScheme(signer) }] });
const { extensions, ...generated } = await client.createPaymentPayload({ x402Version: 2, resource: ch.resource, accepts: [req] });
const payment = JSON.parse(JSON.stringify({ ...generated, accepted: req }));

// 3. the quote approval of that exact payment
const q = ch.quote;
const quoteSignature = await signer.signTypedData({
  domain: { name: 'IdentityMD Paid Action', version: '1', chainId: Number(q.payment.network.slice(7)) },
  primaryType: 'QuoteApproval',
  types: { QuoteApproval: [
    { name: 'resource', type: 'string' },
    { name: 'requesterScopeHash', type: 'bytes32' },
    { name: 'quoteId', type: 'string' },
    { name: 'quoteHash', type: 'bytes32' },
    { name: 'paymentHash', type: 'bytes32' },
    { name: 'action', type: 'string' },
    { name: 'asset', type: 'address' },
    { name: 'amount', type: 'uint256' },
    { name: 'payTo', type: 'address' },
    { name: 'expiresAt', type: 'uint256' },
  ] },
  message: {
    resource: ch.resourceUrl,
    requesterScopeHash: `0x${ch.requesterScopeHash}`,
    quoteId: q.id,
    quoteHash: `0x${q.quoteHash}`,
    paymentHash: sha256(stringToBytes(canon(payment))),
    action: q.action,
    asset: q.payment.asset,
    amount: BigInt(q.payment.amount),
    payTo: q.payment.payTo,
    expiresAt: BigInt(q.expiresAt),
  },
});

// 4. submit; if the response is lost, send the same bytes again
await fetch(url, {
  method: 'POST',
  headers: { ...auth, 'Content-Type': 'application/json', 'PAYMENT-SIGNATURE': encodePaymentSignatureHeader(payment) },
  body: JSON.stringify({ quoteSignature }),
});
```

The wallet needs the IMD balance and a Permit2 allowance for IMD, and the payment window must end before the quote expires. Retries reuse the order and never charge twice. The wallet must sign with its own key: an ordinary account or an EIP-7702 account. Contract wallets such as a Safe are not supported yet.

### The payment payload

Parsed strictly: a key not listed here, at any depth, fails as `invalid_payment_shape`, and the response's `detail` names the field. An SDK that attaches `extensions` is the usual cause; drop them. `accepted` must equal the challenge's `accepts[0]`, `resource.url` must be the order's `resourceUrl`, and the permit's `deadline` must fall before `quote.expiresAt`.

```
{ "x402Version": 2,
  "resource": { "url", "description", "mimeType" },                  // optional
  "accepted": { "scheme": "exact", "network", "asset", "amount", "payTo", "maxTimeoutSeconds",
                "extra": { "assetTransferMethod": "permit2" } },
  "payload": { "signature",
    "permit2Authorization": { "from", "permitted": { "token", "amount" }, "spender",
                              "nonce", "deadline", "witness": { "to", "validAfter" } } },
  "extensions": {} }                                                   // optional, empty
```

### The quote approval

EIP-712, domain `{name: "IdentityMD Paid Action", version: "1", chainId}`, primary type `QuoteApproval`, signed by the wallet that signs the payment. Every field comes from the challenge's JSON or the payment you send. `GET /openapi.json` carries the same types under `x-imd-quote-approval`.

| FIELD | TYPE AND LIMITS |
| --- | --- |
| `resource` | `string`. `resourceUrl` |
| `requesterScopeHash` | `bytes32`. `0x` + `requesterScopeHash` |
| `quoteId` | `string`. `quote.id` |
| `quoteHash` | `bytes32`. `0x` + `quote.quoteHash` |
| `paymentHash` | `bytes32`. SHA-256 of the canonical JSON (keys sorted, no whitespace) of the exact payment in `PAYMENT-SIGNATURE` |
| `action` | `string`. `quote.action` |
| `asset` | `address`. `quote.payment.asset` |
| `amount` | `uint256`. `quote.payment.amount` |
| `payTo` | `address`. `quote.payment.payTo` |
| `expiresAt` | `uint256`. `quote.expiresAt` |

`invalid_quote_approval` almost always means the payment that was hashed differs, by even one byte, from the one in the header.

### GET /requests/:id

Poll until `status` is `admitted`, then follow the URLs in `admission.result`.

- quoted
- payment_pending
- admission_pending
- admitted
- payment_failed
- expired

```
{ "status": "admitted",
  "order": { "id": "ORDER_ID", "status": "paid", "quote": { "action": "job.open", "expiresAt": 1790000000 } },
  "payment": { "status": "confirmed", "paid": true, "transactionHash": "0x…" },
  "admission": { "action": "job.open", "result": { "kind": "job", "jobId": "JOB_ID", "launch": false,
    "statusUrl": "/jobs/JOB_ID", "resultUrl": "/jobs/JOB_ID/result" } } }
```

- **job.open**: `{kind:"job", jobId, launch:false, statusUrl, resultUrl}`
- **job.continue**: `{kind:"job", jobId, continues, statusUrl, resultUrl}`; `continues` is the parent job
- **launch.open**: The same as `job.open`, with `launch: true`.
- **workflow.open**: `{kind:"workflow", workflowId, jobId, statusUrl, jobUrl}`
- **goal.start**: `{kind:"goal", jobId, submissionKey, orchestrated, items, workers, statusUrl, resultUrl}`, and `children:{list, owner}` when it bought other jobs; see [open a goal](https://imd.fun/docs/api/#goal-body)
- **oracle.request**: `{kind:"oracle", requestId, jobId, statusUrl, attestationUrl}`
- **oracle.group**: `{kind:"oracle-group", requests:[{requestId, jobId, questionHash, statusUrl, attestationUrl}]}`, one per question in the order given
- **schedule.create**: `{kind:"schedule", scheduleId, statusUrl}`
- **schedule.topup**: `{kind:"schedule", scheduleId, runsAdded, statusUrl}`
- **Refused**: `{kind:"refused", problems}` if the catalog changed between quote and payment; also a `job.continue` whose payer is not the owner or whose project moved (`payer_not_owner`, `invalid_parent`), a `schedule.topup` on a schedule cancelled before payment, or a workflow key conflict (`submission_key_conflict`).

### Errors and limits

Every code on this page, with its status, is in [the error index](https://imd.fun/docs/api/#errors-every-error-code).

- **`400`**: `invalid_request` with `detail`, `invalid_address` (`paid-by`), `action_not_enabled`, `invalid_payment_shape` with `detail`, `payment_terms_mismatch`, `invalid_quote_approval`, `invalid_payment_window`
- **`401`**: `request_token_required`
- **`402`**: `payment_rejected` with `reason`, e.g. `insufficient_funds`; or the challenge
- **`403`**: `origin_not_allowed`: call from a server, not a cross-origin browser. `payer_not_owner`: a `job.continue` paid from a wallet other than the project's, refused before anything moves
- **`404`**: `order_not_found`
- **`409`**: `request_key_conflict`, `quote_too_close_to_expiry`, `quote_not_yet_valid`, `payment_asset_not_enabled`, `order_not_payable`, `order_payment_already_started`, `payment_already_reserved`, `payment_attempt_conflict`, `payment_not_confirmed`
- **`410`**: `quote_expired`: quote again with a new `requestKey`
- **`422`**: `invalid_input` with `detail` and `problems`; nothing charged
- **`429`**: `request_limit`: 300 requests and 30 quotes a minute, per IP and per token. A check or an import counts as a quote
- **`413`**: `request_too_large`
- **`503`**: `paid_request_unavailable`: a provider or chain failed; the order is kept
- **Body**: 16 KiB max; 4 KiB on `/requests/import`. Quotes last 600 seconds.
