Get started

Starter examples

Copy-and-run code for a first call, in TypeScript, Python and over MCP.

1. Run a free check #

No account or key is needed. Save the file, then run it with a token id. The Python version needs nothing installed, and the TypeScript version runs through npx.

Run
npx tsx check-before-acting.ts chainlink
The file
// Check a token with CoinGraph before your agent acts on it. Needs Node 18 or later, and no packages.
//
//   npx tsx check-before-acting.ts chainlink            free check, no key needed
//   npx tsx check-before-acting.ts solana 5000          sized to your order, needs COINGRAPH_KEY, costs 5 credits
//
// Exit code: 0 proceed, 1 caution or avoid, 2 the check could not be completed.
// CoinGraph never executes, custodies or advises. Your agent decides what to do with the answer.

const API = process.env.COINGRAPH_API ?? "https://coingraph.ai/api/v1";
const KEY = process.env.COINGRAPH_KEY;

type Reason = { dimension: string; text: string; source: string };
type Check = {
  id: string;
  as_of: string;
  data: {
    token: { id: string; symbol: string };
    verdict: "proceed" | "caution" | "avoid";
    confidence: number;
    reasons: Reason[];
    size_check: { order_usd: number; estimated_impact_pct: number | string } | null;
  };
};

async function checkToken(token: string, sizeUsd?: number): Promise<{ check: Check; charged: string | null; left: string | null }> {
  if (sizeUsd !== undefined && !KEY) throw new Error("A sized check needs a key. Create one at https://coingraph.ai/account/keys, then set COINGRAPH_KEY.");
  const res = await fetch(sizeUsd === undefined ? `${API}/evaluate/${encodeURIComponent(token)}` : `${API}/evaluate`, {
    method: sizeUsd === undefined ? "GET" : "POST",
    headers: { "content-type": "application/json", ...(KEY ? { authorization: `Bearer ${KEY}` } : {}) },
    body: sizeUsd === undefined ? undefined : JSON.stringify({ token, size_usd: sizeUsd }),
    signal: AbortSignal.timeout(30_000),
  });
  const body = await res.json();
  if (!res.ok) throw new Error(`${res.status} ${body.error?.code ?? "error"}: ${body.error?.message ?? "request failed"}`);
  return { check: body, charged: res.headers.get("x-credits-charged"), left: res.headers.get("x-credits-remaining") };
}

async function main() {
  const [token = "chainlink", size] = process.argv.slice(2);
  const sizeUsd = size === undefined ? undefined : Number(size);
  if (sizeUsd !== undefined && !(sizeUsd > 0)) throw new Error("The order size must be a positive number of US dollars.");

  const { check, charged, left } = await checkToken(token, sizeUsd);
  const { verdict, confidence, reasons, size_check } = check.data;

  console.log(`${check.data.token.symbol}: ${verdict} (confidence ${confidence}), as of ${check.as_of}`);
  for (const r of reasons) console.log(`  ${r.dimension}: ${r.text} [${r.source}]`);
  if (size_check) console.log(`  order: $${size_check.order_usd}, estimated impact ${size_check.estimated_impact_pct}%`);
  console.log(`Proof: https://coingraph.ai/proof/${check.id}`);
  if (charged) console.log(`Credits: ${charged} charged, ${left} left`);

  // Your agent's decision goes here. Keep the proof id with whatever it does next.
  process.exitCode = verdict === "proceed" ? 0 : 1;
}

main().catch((e: Error) => {
  // Fail closed: if the check can't be completed, the agent shouldn't act as though it passed.
  console.error(`Check not completed: ${e.message}`);
  process.exitCode = 2;
});

2. Size it to your order #

A sized check compares your order with real liquidity. It costs 5 credits, and every account starts with 1,000.

  1. Get a key

    Sign in, then create a key under Account → API keys. It's shown once, so store it as a secret and never commit it.

  2. Run the same file with a size

    export COINGRAPH_KEY=cg_live_your_key_here
    npx tsx check-before-acting.ts solana 5000

3. Use the answer #

Exit codeMeaningWhat your agent should do
0proceedCarry on, and keep the proof id with what it does next
1caution or avoidRead the reasons, then reduce, wait or stop
2The check could not be completedStop. A failed check is not a pass

Every check has a public proof page with the exact answer, its fingerprint and its sources. CoinGraph never executes, custodies or advises: your agent decides.

4. Connect an AI app or your own agent #

In Claude Code, run this, or see Connect for Claude on the web and other apps. Your app opens a CoinGraph sign-in the first time, and calls spend credits at the same prices as the API.

claude mcp add --transport http coingraph https://coingraph.ai/mcp

Then ask: “Is it safe to buy $5K of LINK right now? Use CoinGraph.”

Your own agent connects with an account key instead of the sign-in:

agent.ts
// Your own agent, calling CoinGraph over MCP with an account key.
//
//   npm install @modelcontextprotocol/sdk
//   export COINGRAPH_KEY=cg_live_your_key_here
//   npx tsx agent.ts solana 5000
//
// Listing the tools costs nothing. check_token spends credits at the same prices as the API.
// Claude, Cursor and other AI apps don't need this file or a key: they open a sign-in when you connect them.
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const URL_ = process.env.COINGRAPH_MCP ?? "https://coingraph.ai/mcp";
const KEY = process.env.COINGRAPH_KEY;

async function main() {
  if (!KEY) throw new Error("Create a key at https://coingraph.ai/account/keys, then set COINGRAPH_KEY.");
  const [token = "solana", size = "5000"] = process.argv.slice(2);

  const client = new Client({ name: "my-agent", version: "1.0.0" });
  await client.connect(new StreamableHTTPClientTransport(new URL(URL_), { requestInit: { headers: { Authorization: `Bearer ${KEY}` } } }));
  try {
    const { tools } = await client.listTools();
    console.log(`Connected: ${tools.length} tools available`);

    const result = await client.callTool({ name: "check_token", arguments: { token, size_usd: Number(size) } });
    const text = (result.content as { type: string; text?: string }[]).find((c) => c.type === "text")?.text ?? "";
    if (result.isError) throw new Error(text);

    const check = JSON.parse(text);
    console.log(`${check.data.token.symbol}: ${check.data.verdict} (confidence ${check.data.confidence})`);
    console.log(`Proof: https://coingraph.ai/proof/${check.id}`);
    process.exitCode = check.data.verdict === "proceed" ? 0 : 1;
  } finally {
    await client.close();
  }
}

main().catch((e: Error) => {
  // Fail closed: if the check can't be completed, the agent shouldn't act as though it passed.
  console.error(`Check not completed: ${e.message}`);
  process.exitCode = 2;
});
i

Note

Stuck on your first call? Write to support@coingraph.ai with what you tried, and we'll help you get it working.