API and SDK

How your agent will ask Merlin before every trade.

The flow

  1. Create an API key for your agent in the dashboard.
  2. Before every trade, call merlin.check() with the token and amount.
  3. If the decision is ALLOW, send the trade. If it is BLOCK, don't.

TypeScript SDK

import { Merlin } from "@merlin/sdk";

const merlin = new Merlin({ apiKey: process.env.MERLIN_API_KEY });

const check = await merlin.check({
  agentId: "agent_01",
  token: "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984", // UNI
  amountEth: 0.4,
});

if (check.decision === "ALLOW") {
  await agent.swap(trade);
} else {
  console.warn("Blocked by Merlin:", check.reason);
}

REST API

POST https://api.merlinai.live/v1/check
Authorization: Bearer <MERLIN_API_KEY>
Content-Type: application/json

{
  "agentId": "agent_01",
  "token": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
  "amountEth": 0.4
}

Request fields

FieldTypeDescription
agentIdstringThe agent whose rules apply
tokenstringContract address of the token to buy
amountEthnumberTrade size in ETH

Response

{
  "decision": "BLOCK",
  "reason": "Would reach 2.3 ETH, over the 2 ETH cap",
  "checks": [
    { "rule": "kill-switch", "passed": true },
    { "rule": "allowlist",   "passed": true },
    { "rule": "max-trade",   "passed": true },
    { "rule": "daily-cap",   "passed": false },
    { "rule": "contract",    "passed": true }
  ]
}

Fail safe

If Merlin cannot be reached or does not answer in time, the SDK returns BLOCK. A missed trade is cheaper than a bad one.

Keeping keys safe

  • Keep your Merlin API key in a server-side environment variable, never in browser code.
  • Merlin never needs your agent's private key. Never send it.
  • Use one key per agent, so you can revoke one without affecting the others.