.claude/skills/api-route/SKILL.md
Create a new Next.js API route with x402 micropayment middleware
npx skillsauth add tadams95/kardashev-network api-routeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Create a new API route: $ARGUMENTS
| Endpoint | Price | Description |
|----------|-------|-------------|
| /api/solar/irradiance | 0.001 USDC | Real-time solar data |
| /api/grid/carbon | 0.002 USDC | Carbon intensity |
| /api/buildings/area | 0.005 USDC | Building footprints |
| /api/geocode/search | 0.001 USDC | Address geocoding |
| /api/premium/analytics | 0.01 USDC | Premium aggregated data |
src/pages/api/
├── solar/
│ └── irradiance.ts
├── grid/
│ └── carbon.ts
├── buildings/
│ └── area.ts
├── geocode/
│ └── search.ts
└── premium/
└── analytics.ts
// src/pages/api/{path}.ts
import type { NextApiRequest, NextApiResponse } from "next";
// Types for this endpoint
interface ResponseData {
// Define response shape
}
interface ErrorResponse {
error: string;
message: string;
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<ResponseData | ErrorResponse>
) {
// Only allow GET requests (or POST if needed)
if (req.method !== "GET") {
return res.status(405).json({
error: "Method not allowed",
message: "Only GET requests are supported"
});
}
try {
// Extract query parameters
const { lat, lng } = req.query;
// Validate required parameters
if (!lat || !lng) {
return res.status(400).json({
error: "Bad request",
message: "Missing required parameters: lat, lng"
});
}
// TODO: Add x402 middleware check here
// const paymentValid = await verifyX402Payment(req);
// if (!paymentValid) {
// return res.status(402).json({ error: "Payment required" });
// }
// Fetch from upstream API
const data = await fetchUpstreamData(
parseFloat(lat as string),
parseFloat(lng as string)
);
// Return response with caching headers
res.setHeader("Cache-Control", "s-maxage=300, stale-while-revalidate");
return res.status(200).json(data);
} catch (error) {
console.error("API error:", error);
return res.status(500).json({
error: "Internal server error",
message: "Failed to fetch data"
});
}
}
async function fetchUpstreamData(lat: number, lng: number): Promise<ResponseData> {
// Implement upstream API call
throw new Error("Not implemented");
}
// src/lib/x402/middleware.ts
import { X402_PRICING } from "./config";
export async function withX402(
req: NextApiRequest,
res: NextApiResponse,
endpoint: string,
handler: () => Promise<void>
) {
const pricing = X402_PRICING[endpoint];
// Check for valid payment header
const paymentHeader = req.headers["x-402-payment"];
if (!paymentHeader && !pricing.freeTier) {
return res.status(402).json({
error: "Payment required",
price: pricing.price,
description: pricing.description,
});
}
// Verify payment signature...
return handler();
}
Create corresponding client in src/lib/api/:
openMeteo.ts - Solar irradiance dataelectricityMaps.ts - Carbon intensityoverpass.ts - Building footprints (OSM)nominatim.ts - Geocodingsrc/pages/api/src/lib/api/ if neededdevelopment
Web3 integration with wagmi and viem - wallet connection, contract interactions, transactions, RainbowKit. Use when implementing wallet features, reading/writing contracts, or handling blockchain transactions.
content-media
Three.js textures - loading, configuration, UV mapping, environment maps. Use when loading images, configuring texture properties, or working with HDR environments.
data-ai
Three.js shaders - GLSL, ShaderMaterial, uniforms, custom effects. Use when creating custom visual effects, modifying vertices, writing fragment shaders, or extending built-in materials.
testing
Three.js post-processing - EffectComposer, bloom, depth of field, custom passes. Use when adding visual effects, screen-space effects, or enhancing rendered output.