const visionAgentMetadata = {
name: 'Vision AI Pro',
tags: ['computer-vision', 'image-processing', 'ai'],
dateCreated: new Date(),
description: 'Advanced image analysis and object detection'
}
// Dynamic pricing based on image complexity
const dynamicCredits = {
creditsType: 'DYNAMIC',
minCreditsPerRequest: 1n, // Simple image detection
maxCreditsPerRequest: 50n, // Complex scene analysis
amount: 1000n // Total credits in plan
}
const { agentId, planId } = await payments.registerAgentAndPlan(
visionAgentMetadata,
visionAgentApi,
priceConfig,
dynamicCredits
)
// In your agent endpoint
app.post('/api/analyze', async (req, res) => {
// Validate access
const isValid = await payments.isValidRequest(
planId,
agentId,
req.body.subscriberAddress,
req.headers['x-nvm-query-signature']
)
if (!isValid) {
return res.status(402).json(await payments.getAgentPaymentCard(agentId))
}
// Process image and calculate complexity
const result = await analyzeImage(req.body.imageData)
const complexity = calculateImageComplexity(req.body.imageData, result)
// Redeem credits based on complexity
const creditsUsed = Math.min(Math.max(complexity, 1), 50)
await payments.redeemCredits(planId, BigInt(creditsUsed), generateProof(req, result))
res.json({ result, creditsUsed })
})