build strategy · Anyway

Real Anyway, one wallet, one build.

Every mega-prompt in this archive collapses into the same shape: a single TanStack server function talking to Anyway, with the agent paying per call in USDC. It's the only pattern that lets a Lovable account ship a working demo in one shot, inside the 5-credit budget.

Why Anyway and not vendor-by-vendor?

SuperAPI puts 60+ paid APIs — search, data, browser, markets, media — behind one x402 interface. No signup per vendor, no monthly minimums, no keys to rotate: the agent pays for the exact call it makes, in USDC, and the directory tells you the price before you spend a cent.

Why TanStack server functions?

Lovable's TanStack Start template makes secrets trivial. createServerFn runs on the server, reads process.env.ANYWAY_AGENT_WALLET_KEY inside the handler, signs the payment, and returns typed JSON. The wallet key never reaches the browser — no edge functions, no extra infra.

The pattern in code.

src/lib/anyway.functions.ts — SuperAPI
// src/lib/anyway.functions.ts — discover + call a paid API
// Built during the Anyway Creative Hackathon — StreetKode Fam · Indian Krump Festival 14
import { createServerFn } from "@tanstack/react-start";
import { z } from "zod";

const MARKETPLACE = "https://marketplace-prod.anyway.sh/v1/api";

export const ask = createServerFn({ method: "POST" })
  .inputValidator((d) => z.object({ query: z.string().min(1).max(400) }).parse(d))
  .handler(async ({ data }) => {
    // 1. Discover — the directory is the source of truth, never hardcode a URL.
    const services = await (await fetch(`${MARKETPLACE}/directory`)).json();
    const upstream = services.find((s) => s.category === "search") ?? services[0];

    // 2. Inspect — info returns the callable x402 endpoint.
    const info = await (await fetch(`${MARKETPLACE}/info/${upstream.id}`)).json();
    const x402Url = String(info.curl_x402).match(/https?:\/\/\S+/)?.[0] ?? "";

    // 3. Call — unpaid requests answer 402 with a price quote.
    const r = await fetch(`${x402Url}?q=${encodeURIComponent(data.query)}`);
    if (r.status === 402) return { quote: await r.json(), needsPayment: true };
    if (!r.ok) throw new Error(`SuperAPI failed: ${r.status}`);
    return { result: await r.json(), needsPayment: false };
  });
paying the 402 — Agent Wallet
// The Agent Wallet pays the 402, under a policy the owner sets once.
// Fastest hackathon path — let the CLI sign the payment:
//   anyway superapi call "<x402 url>" --yes
//
// In-app, runtime requests are signed with the wallet's P-256 key:
export const walletStatus = createServerFn({ method: "GET" }).handler(async () => {
  const key = process.env.ANYWAY_AGENT_WALLET_KEY!;      // never VITE_
  const headers = await signAgentRequest("GET", "/v1/agent-wallet", key);
  //   X-Agent-Pubkey     base64 SPKI public key
  //   X-Agent-Timestamp  unix seconds (within 300s)
  //   X-Agent-Signature  base64 DER ECDSA over sha256("METHOD\n/path\n<ts>")
  const me = await (await fetch("https://api.anyway.sh/v1/agent-wallet", { headers })).json();
  return { agent: me.data };
});
observability — Agent Traces
// Optional: make the run auditable with Agent Traces.
import { initialize, withWorkflow, withAgent, withTask }
  from "@anyway-sh/node-server-sdk";

initialize({
  appName: "my-app",
  apiKey: process.env.ANYWAY_API_KEY,
  baseUrl: "https://collector.anyway.sh",
});

await withWorkflow({ name: "run" }, () =>
  withAgent({ name: "critic" }, () =>
    withTask({ name: "respond" }, () => doWork())));

// Python is the same shape:
//   pip install anyway-sdk
//   Traceloop.init(app_name="my-app", api_key=os.environ["ANYWAY_API_KEY"],
//                  api_endpoint="https://collector.anyway.sh")
secrets + Lovable build
# Lovable -> Project Settings -> Secrets
ANYWAY_AGENT_WALLET_KEY=...   # app.anyway.sh/wallets?view=agent
ANYWAY_API_KEY=...            # Business profile -> Developers (payments + traces)

# How Lovable wires this up in one prompt:
# 1. Paste a mega-prompt from this archive.
# 2. Lovable
#    - writes a server function that talks to Anyway (SuperAPI / wallet / orders / traces)
#    - wires the client surface (search box, wallet panel, pay button, trace tree)
#    - keeps your keys on the server via process.env
# 3. Run it. Your demo is paying for real API calls in USDC.

Shipping a 5-credit demo

  • · Pick one idea. Paste its mega-prompt. Add ANYWAY_AGENT_WALLET_KEY. That's the whole build.
  • · Keep it to ONE route and ONE server function. No auth, no DB, no extra integrations.
  • · Always discover before you call: /v1/api/directory, then /v1/api/info/{id}.
  • · Set a spending policy on the wallet before demo day — organization credits are spent before wallet USDC.
  • · Add the footer credit: "Built during the Anyway Creative Hackathon — StreetKode Fam · Indian Krump Festival 14".