REST
ProductionREST API (Any HTTP Service) — Any HTTP API
Overview
SettleGrid supports any standard REST API as a first-class protocol. If your service exposes HTTP endpoints (Express, Fastify, Next.js, Hono, Flask, Rails — anything), you can add per-call billing with SettleGrid's REST middleware. No MCP server required, no protocol adapters needed — just HTTP request/response with billing built in.
How It Works
The REST integration uses SettleGrid's settlegridMiddleware() function, which wraps your HTTP route handler with billing logic. On every incoming request, the middleware extracts the API key from the x-api-key header (or Authorization: Bearer), validates the key and credit balance via SettleGrid's API, and either allows the request through or returns a 401/402 error.
After your handler processes the request and returns a response, the middleware fires an asynchronous metering event to record the invocation. The metering is non-blocking — it does not add latency to the response.
The REST middleware works with any Node.js HTTP framework. For Express, it attaches as standard middleware. For Next.js App Router, it runs at the top of your route handler. For other languages (Python, Go, Ruby), you can call the SettleGrid REST API directly.
How SettleGrid Integrates
Use settlegridMiddleware() from '@settlegrid/mcp/rest' to wrap any HTTP route handler. The middleware handles key extraction, validation, balance checking, and metering automatically. It works with Express, Fastify, Next.js, Hono, and any other Node.js framework. For non-Node environments, call POST /api/sdk/validate-key and POST /api/sdk/meter directly.
Key Specs
| Protocol | REST — REST API (Any HTTP Service) |
| Backer | Any HTTP API |
| Detection Header | x-api-key / Authorization: Bearer sg_* |
| Identity Type | api-key |
| Payment Type | credit-balance |
| Status | Production |
Code Example
Here is how a developer's tool works with REST via SettleGrid:
import { NextRequest, NextResponse } from 'next/server'
import { settlegridMiddleware } from '@settlegrid/mcp/rest'
const billing = settlegridMiddleware({
toolSlug: 'my-rest-api',
pricing: { defaultCostCents: 10 },
})
export async function POST(request: NextRequest) {
// Billing middleware — validates key + deducts credits
await billing(request)
const body = await request.json()
const result = await processRequest(body)
return NextResponse.json({ result, metered: true })
}Start monetizing with SettleGrid
Free forever — 50,000 ops/month, progressive take rate. Add billing to your REST tool in under 5 minutes.
Get Started Free