DEV Community

GoldBean
GoldBean

Posted on

How to Build a Pay-Per-Call AI API Market with x402 and MCP Protocol

Why Pay-Per-Call?

Most AI API platforms force you into monthly subscriptions. But what if you only need to call an OCR endpoint once? Or run a single image recognition task?

That's why I built GoldBean — a pay-per-call AI API market where you only pay for what you use ($0.01-$0.03 per call).

Architecture Overview

GoldBean runs on a single VPS with:

  • Node.js server handling API requests (port 9879)
  • MCP HTTP bridge for Model Context Protocol compatibility (port 3099)
  • Nginx reverse proxy with SSL termination
  • Three payment gateways: PayPal, Alipay, USDC (on-chain via x402)

The x402 Payment Protocol

x402 is the key innovation. Here's how it works:

  1. Client sends an API request with an EIP-3009 signed transfer
  2. Server verifies the signature and checks the payment amount
  3. If valid, server executes the API call and returns the result
  4. The entire flow takes less than 2 seconds with near-zero fees
// Client side: signing the payment
const transfer = {
  to: merchantAddress,
  value: priceInWei,
  validAfter: 0,
  validBefore: Math.floor(Date.now() / 1000) + 3600,
  nonce: randomNonce()
};
const signature = await signer._signTypedData(domain, types, transfer);
Enter fullscreen mode Exit fullscreen mode

MCP Server Integration

GoldBean is fully compatible with the Model Context Protocol. You can plug it directly into Claude, Cursor, or any MCP-capable AI tool:

{
  "mcpServers": {
    "goldbean": {
      "url": "https://goldbean-api.xyz/sse"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Once connected, your AI assistant can call 47 different AI endpoints — OCR, image recognition, speech synthesis, LLM chat, image generation — without writing any code.

47 Endpoints

Here are some of the key API categories:

  • OCR: general text, handwriting, table recognition, medical documents
  • Image Recognition: object detection, scene analysis, logo recognition
  • Speech: text-to-speech with multiple voices, speech-to-text
  • LLM: chat completions, text generation, summarization
  • Image Generation: AI-powered image creation

All accessible via a single API key with pay-per-call pricing.

Free Tier

Every user gets 50 free API calls per day. No credit card required to start.

Links

If you're building AI-powered apps and want flexible, affordable API access without subscriptions, give GoldBean a try.

Top comments (0)