api-route
Create a new Next.js API route with x402 micropayment middleware
Best use case
api-route is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Create a new Next.js API route with x402 micropayment middleware
Teams using api-route should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/api-route/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How api-route Compares
| Feature / Agent | api-route | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Create a new Next.js API route with x402 micropayment middleware
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Create API Route with x402
Create a new API route: **$ARGUMENTS**
## x402 Pricing Reference (from IMPLEMENTATION_CHECKLIST.md)
| 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 |
## File Structure
```
src/pages/api/
├── solar/
│ └── irradiance.ts
├── grid/
│ └── carbon.ts
├── buildings/
│ └── area.ts
├── geocode/
│ └── search.ts
└── premium/
└── analytics.ts
```
## API Route Template
```typescript
// 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");
}
```
## x402 Middleware Pattern (Future)
```typescript
// 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();
}
```
## Upstream API Clients
Create corresponding client in `src/lib/api/`:
- `openMeteo.ts` - Solar irradiance data
- `electricityMaps.ts` - Carbon intensity
- `overpass.ts` - Building footprints (OSM)
- `nominatim.ts` - Geocoding
## Checklist
- [ ] Create API route file in correct path under `src/pages/api/`
- [ ] Define TypeScript interfaces for request/response
- [ ] Add input validation
- [ ] Add error handling with proper status codes
- [ ] Add caching headers where appropriate
- [ ] Create upstream API client in `src/lib/api/` if needed
- [ ] Document x402 pricing in config
- [ ] Test with curl/PostmanRelated Skills
add-route-context
为Flutter页面添加路由上下文记录功能,支持日期等参数的AI上下文识别。当需要让AI助手通过"询问当前上下文"功能获取页面状态(如日期、ID等参数)时使用。适用场景:(1) 日期驱动的页面(日记、活动、日历等),(2) ID驱动的页面(用户详情、订单详情等),(3) 任何需要AI理解当前页面参数的场景
fastapi-router-py
Create FastAPI routers with CRUD operations, authentication dependencies, and proper response models. Use when building REST API endpoints, creating new routes, implementing CRUD operations, or add...
api-routes
Generate secure TanStack Start API routes with authentication, rate limiting, validation, and proper error handling. Use when creating API endpoints, REST resources, or backend logic.
api-route-scaffold
Create new Next.js API routes following project patterns. Use when user mentions "new endpoint", "add API", "create route", or "POST/GET handler".
api-route-creator
Creates Next.js 16 API routes with auth, validation, and tenant scoping. Use when creating API endpoints.
api-route-conventions
Expert knowledge on Next.js API route patterns, authentication with getAuthOrTest, error handling, response formats, rate limiting, and webhook verification. Use this skill when user asks about "create api endpoint", "api route", "error handling", "authentication", "next.js api", or "route handler".
agentbox-openrouter
Set up OpenRouter as your LLM provider. Guides through account creation, API key setup, config, and making it the default model. Use when a user wants to use OpenRouter models like Claude Sonnet 4.5.
bgo
Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.
humanizer-ko
Detects and corrects Korean AI writing patterns to transform text into natural human writing. Based on scientific linguistic research (KatFishNet paper with 94.88% AUC accuracy). Analyzes 19 patterns including comma overuse, spacing rigidity, POS diversity, AI vocabulary overuse, and structural monotony. Use when humanizing Korean text from ChatGPT/Claude/Gemini or removing AI traces from Korean LLM output.
huggingface-accelerate
Simplest distributed training API. 4 lines to add distributed support to any PyTorch script. Unified API for DeepSpeed/FSDP/Megatron/DDP. Automatic device placement, mixed precision (FP16/BF16/FP8). Interactive config, single launch command. HuggingFace ecosystem standard.
hr-pro
Professional, ethical HR partner for hiring, onboarding/offboarding, PTO and leave, performance, compliant policies, and employee relations. Ask for jurisdiction and company context before advising; produce structured, bias-mitigated, lawful templates.
hive-mind-advanced
Advanced Hive Mind collective intelligence system for queen-led multi-agent coordination with consensus mechanisms and persistent memory