Use this skill to let your AI agent search global news via:
https://www.x402api.app/POST /api/v1/news/searchThis is a news aggregation capability: your agent can search across web-indexed news sources, including major US and European outlets, and can filter by source domain and publication time.
cnn.com, bloomberg.com, ft.com)time_published)EVM_PRIVATE_KEY=0x_your_private_key
API_BASE_URL=https://www.x402api.app/
Endpoint:
POST /api/v1/news/search
Body example:
{
"query": "Federal Reserve rates",
"limit": 10,
"time_published": "7d",
"source": "bloomberg.com",
"country": "US",
"lang": "en"
}
query (required): search keywordslimit (optional): 1-500, default 10time_published (optional): time filter (for example anytime, 1h, 1d, 7d, 1y)source (optional): source domain filter, for example cnn.comcountry (optional): 2-letter country code, default USlang (optional): 2-letter language code, default en402 Payment Required.import { x402Client, x402HTTPClient } from "@x402/core/client";
import { ExactEvmScheme, toClientEvmSigner } from "@x402/evm";
import { createPublicClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
const baseUrl =
process.env.X402_API_BASE_URL ??
process.env.API_BASE_URL ??
"https://www.x402api.app/";
const endpoint = `${baseUrl.replace(/\/$/, "")}/api/v1/news/search`;
async function main() {
const privateKey = process.env.EVM_PRIVATE_KEY;
if (!privateKey) throw new Error("Missing EVM_PRIVATE_KEY");
if (!privateKey.startsWith("0x")) throw new Error("EVM_PRIVATE_KEY must start with 0x");
const account = privateKeyToAccount(privateKey as `0x${string}`);
const publicClient = createPublicClient({ chain: base, transport: http() });
const signer = toClientEvmSigner(account, publicClient);
const client = new x402Client().register("eip155:*", new ExactEvmScheme(signer));
const httpClient = new x402HTTPClient(client);
const payload = {
query: "AI chip demand",
limit: 10,
time_published: "7d",
source: "reuters.com",
country: "US",
lang: "en",
};
const unpaid = await fetch(endpoint, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(payload),
});
if (unpaid.status !== 402) {
const text = await unpaid.text();
throw new Error(`Expected 402, got ${unpaid.status}. body=${text}`);
}
const required = httpClient.getPaymentRequiredResponse(
(name) => unpaid.headers.get(name),
{},
);
const paymentPayload = await httpClient.createPaymentPayload(required);
const paid = await fetch(endpoint, {
method: "POST",
headers: {
"content-type": "application/json",
...httpClient.encodePaymentSignatureHeader(paymentPayload),
},
body: JSON.stringify(payload),
});
const result = await paid.json();
if (!paid.ok) throw new Error(`Request failed: ${paid.status} ${JSON.stringify(result)}`);
console.log(result);
}
void main().catch((error) => {
console.error(error);
process.exit(1);
});
The search can cover web-indexed mainstream media, including but not limited to:
nytimes.com)washingtonpost.com)wsj.com)bloomberg.com)reuters.com)apnews.com)cnn.com)foxnews.com)nbcnews.com)abcnews.go.com)cbsnews.com)usatoday.com)latimes.com)politico.com)axios.com)businessinsider.com)forbes.com)theatlantic.com)time.com)newsweek.com)ft.com)economist.com)bbc.com)reuters.com)theguardian.com)thetimes.co.uk)telegraph.co.uk)news.sky.com)euronews.com)politico.eu)lemonde.fr)lefigaro.fr)afp.com)spiegel.de)zeit.de)faz.net)handelsblatt.com)elpais.com)elmundo.es)corriere.it)repubblica.it)ansa.it)nrc.nl)telegraaf.nl)swissinfo.ch)> Note: Coverage depends on upstream indexing and availability; this list represents major outlets that are commonly discoverable.
source.time_published (like 1d or 7d) and then sort/compare timestamps.source first, then expand time range.402 Payment Required: generate payment payload and retry.invalid_json_body (400): send valid JSON.invalid_news_request (400): fix query/limit/source format.news_upstream_auth_failed (502): server-side upstream auth issue.news_upstream_rate_limited (429): retry with backoff.news_upstream_error (502): transient upstream failure, retry.共 1 个版本