Exposes tex402_status (free), tex402_lint ($0.002), and tex402_compile ($0.008 — writes decoded PDF directly to local disk and attaches multimodal 150-DPI PNG page previews without bloating LLM context).
TypeScript / Node.js (@x402/fetch)npm i @x402/fetch @x402/evm viem
import fs from "node:fs";
import { wrapFetchWithPayment, x402Client, decodePaymentResponseHeader } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { toClientEvmSigner } from "@x402/evm";
import { createPublicClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
const BASE_URL = process.env.TEX402_BASE_URL ?? "https://tex.x.gl";
const account = privateKeyToAccount(process.env.TEX402_PRIVATE_KEY as `0x${string}`); // Base USDC only (0 ETH gas)
const publicClient = createPublicClient({ chain: base, transport: http() });
const client = new x402Client();
registerExactEvmScheme(client, { signer: toClientEvmSigner(account, publicClient) });
const fetchWithPay = wrapFetchWithPayment(fetch, client);
const res = await fetchWithPay(`${BASE_URL}/v1/compile`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
engine: "pdflatex",
include_page_previews: true,
main_tex: "\\documentclass{article}\\begin{document}\\section{Hello TeX402}Paid via x402 v2.\\end{document}"
})
});
const receipt = decodePaymentResponseHeader(res.headers.get("payment-response")!);
const data = await res.json();
if (data.success && data.pdf_base64) {
fs.writeFileSync("output.pdf", Buffer.from(data.pdf_base64, "base64"));
console.log(`Saved output.pdf (${data.page_count} pages, ${data.compile_time_ms}ms) — tx: ${receipt.transaction}`);
}
Automatically negotiates the HTTP 402 challenge, signs a gasless EIP-3009 USDC authorization on eip155:8453, and returns the settled transaction hash in payment-response.
Returns HTTP 402 Payment Required with base64-encoded JSON PAYMENT-REQUIRED advertising exact scheme pricing and Bazaar input/output JSON Schemas.
Paste into Claude Code, Cursor, Codex, or AntigravitySelf-configuring agent bootstrap prompt
Read https://tex.x.gl/skill.md (and https://tex.x.gl/llms-full.txt for full JSON schemas) to integrate with the TeX402 LaTeX compilation ($0.008 USDC) and <300ms linting ($0.002 USDC) API on Base Mainnet (eip155:8453).
Configure the MCP server via `npx -y tex402-mcp` (using TEX402_PRIVATE_KEY from my environment, 0 ETH gas required) or call HTTP x402 via `@x402/fetch` / `npx agentcash`.
Always follow Author -> Lint ($0.002, <300ms) -> Compile ($0.008, include_page_previews: true) -> Visually Inspect 150-DPI PNG Margins/Equations.
Settled via gasless EIP-3009 TransferWithAuthorization exact USDC authorizations on Base Mainnet (eip155:8453). Discovery, OpenAPI, and health endpoints are always free.
POST/v1/compile
$0.008 USDC
Full multi-pass LaTeX-to-PDF compilation inside a pre-warmed TeX Live container with optional 150-DPI PNG page previews and line-accurate diagnostics.
Engines: pdflatex & xelatex (Unicode + Noto CJK + fontspec)