Everything you need to add metered billing to your API in under 5 minutes.
# Direct API call (without NexFlow)
curl https://api.example.com/v1/chat/completions \
-H "Authorization: Bearer sk_..." \
-d '{"model": "gpt-4", "messages": [...]}'
# 200 OK (no payment tracking)# Via NexFlow metered endpoint
curl https://api.nexflow.io/v1/metered/ep_xxx \
-H "Authorization: Bearer sk_..." \
-H "x-payment: 0x1234...abcd" \
-d '{"model": "gpt-4", "messages": [...]}'
# x-payment is obtained by following the x402 challenge (see x402 guide)
# 200 OK + payment verified + usage loggedHandle 402 challenges and x‑payment headers for autonomous agents.
Read guideChoose your language and follow along.
import { NexFlow } from '@nexflow/sdk'
const nexflow = new NexFlow({
apiKey: process.env.NEXFLOW_API_KEY
})
try {
// Create a metered endpoint
const endpoint = await nexflow.endpoints.create({
name: 'Chat Completions',
upstreamUrl: 'https://api.openai.com/v1/chat/completions',
pricePerCall: '0.001',
network: 'base',
token: 'USDC'
})
console.log('Metered URL:', endpoint.meteredUrl)
} catch (error) {
console.error('Failed to create endpoint:', error)
}