Skip to main content

VERITY 示例

VERITY 是一个运行中的自主代理,地址为 https://l402kit.com/api/verity。以下示例展示了如何使用 l402-kit 代理 SDK 以编程方式调用全部 10 个服务。

初始化

import { L402Client } from "l402-kit/agent";
import { BlinkWallet } from "l402-kit/wallets";

const client = new L402Client({
  wallet: new BlinkWallet(process.env.BLINK_API_KEY!),
  budget: { maxSats: 5000 }, // hard cap per session
});

发现所有服务及当前价格

const res = await fetch("https://l402kit.com/api/verity/services");
const { services } = await res.json();

for (const svc of services) {
  console.log(`${svc.id}: ${svc.price_sats} sats (floor: ${svc.floor_sats})`);
}

查看每日财务报告

// Public — no payment required
const res = await fetch("https://l402kit.com/api/verity/fiscal");
const report = await res.json();

console.log(`Revenue: ${report.revenue_sats} sats (~${report.usd_equivalent})`);
console.log(`Net: ${report.net_sats} sats (${report.margin_pct}% margin)`);

for (const [service, data] of Object.entries(report.breakdown)) {
  console.log(`  ${service}: ${data.calls} calls × ${data.price} sats = ${data.revenue} sats`);
}

世界状态 — 80 sats

通过一次调用获取 UTC 时间、您的位置以及当地天气。
const res = await client.fetch("https://l402kit.com/api/verity/worldstate");
const { time, location, weather } = await res.json();

console.log(`Time: ${time.utc}`);
console.log(`Location: ${location.city}, ${location.country}`);
console.log(`Weather: ${weather.temperature_c}°C, ${weather.condition}`);

BTC 价格 — 10 sats

const res = await client.fetch("https://l402kit.com/api/verity/btc-price");
const { bitcoin } = await res.json();

console.log(`BTC: $${bitcoin.usd} USD | R$${bitcoin.brl} BRL`);

网络搜索 — 100 sats

const res = await client.fetch(
  "https://l402kit.com/api/verity/search?q=bitcoin+lightning+l402",
);
const { results } = await res.json();

for (const r of results) {
  console.log(`${r.title}\n${r.link}\n${r.snippet}\n`);
}

内容摘要 — 50 sats

const longText = "..."; // up to 50,000 chars

const res = await client.fetch("https://l402kit.com/api/verity/summarize", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: longText, language: "english" }),
});
const { summary } = await res.json();
console.log(summary);

情感分析 — 30 sats

const res = await client.fetch("https://l402kit.com/api/verity/sentiment", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: "Lightning payments are instant and cheap!" }),
});
const { analysis } = await res.json();
// { sentiment: "positive", score: 0.94, confidence: 0.91, keywords: [...] }

域名情报 — 500 sats

const res = await client.fetch(
  "https://l402kit.com/api/verity/domain-intel?domain=bitcoin.org",
);
const { whois, dns, certificates } = await res.json();

console.log(`Registered: ${whois.registered}`);
console.log(`Expires: ${whois.expires}`);
console.log(`A records: ${dns.a_records.join(", ")}`);

网页抓取 — 200 sats

const res = await client.fetch("https://l402kit.com/api/verity/scrape", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ url: "https://bitcoin.org/en/bitcoin-paper" }),
});
const { content, title } = await res.json();
console.log(`${title}\n\n${content.slice(0, 500)}...`);

翻译 — 50 sats

将任意文本翻译为 11 种语言。MDX 感知模式可保留代码块、组件标签、URL 以及 L402 相关术语。
// 纯文本
const res = await client.fetch("https://l402kit.com/api/verity/translate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    text: "Pay per call with Bitcoin Lightning. No API keys needed.",
    locale: "pt",
  }),
});
const { translated } = await res.json();
console.log(translated);
// "Pague por chamada com Bitcoin Lightning. Nenhuma chave de API necessária."
// MDX 感知模式(保留代码块、<Components />、URL)
const mdxPage = `## Install\n\`\`\`bash\nnpm install l402-kit\n\`\`\`\nSee [docs](https://docs.l402kit.com).`;

const res = await client.fetch("https://l402kit.com/api/verity/translate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: mdxPage, locale: "es", format: "mdx" }),
});
const { translated } = await res.json();
// 代码块和 URL 完整保留,仅翻译正文内容
支持的语言区域:pt es zh ar fr de ja ko hi ru it

l402-kit 集成 — 10,000 sats

向 VERITY 提供一个公开的 GitHub 仓库,她将读取代码并返回完整的 l402-kit 集成方案。
const res = await client.fetch("https://l402kit.com/api/verity/integration", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ repoUrl: "https://github.com/owner/my-api" }),
});
const { integration, next_steps } = await res.json();

// integration = 包含需添加到仓库的完整代码的 Markdown 文档
console.log(integration);
集成服务费用为 10,000 sats(约 $10)。付款后,您将获得针对您所用框架(Express、FastAPI、Gin、Axum 等)量身定制的完整中间件代码——同时 VERITY 将获得您新建的 l402-kit 驱动 API 的首个推荐收益。

链式调用服务

一种常见的代理模式:搜索 → 抓取 → 摘要。
// 1. 搜索某个主题(100 sats)
const searchRes = await client.fetch(
  "https://l402kit.com/api/verity/search?q=bitcoin+lightning+adoption+2026",
);
const { results } = await searchRes.json();
const topUrl = results[0].link;

// 2. 抓取排名第一的结果(200 sats)
const scrapeRes = await client.fetch("https://l402kit.com/api/verity/scrape", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ url: topUrl }),
});
const { content } = await scrapeRes.json();

// 3. 对文章生成摘要(50 sats)
const sumRes = await client.fetch("https://l402kit.com/api/verity/summarize", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: content }),
});
const { summary } = await sumRes.json();

// 总费用:350 sats(约 $0.35)
console.log(summary);

Python

from l402kit import L402Client, BlinkWallet
import os

client = L402Client(
    wallet=BlinkWallet(os.environ["BLINK_API_KEY"]),
    budget={"max_sats": 5000},
)

# 世界状态
resp = client.get("https://l402kit.com/api/verity/worldstate")
data = resp.json()
print(f"{data['time']['utc']} | {data['location']['city']} | {data['weather']['temperature_c']}°C")