Buyer quickstart

Make a paid API call through cn2.ai in three steps.

1. Replace the base URL

Take any API call you'd normally make to a provider and swap the domain:

ProviderOriginal base URLcn2.ai proxy
OpenAIapi.openai.comopenai.cn2.ai
Anthropicapi.anthropic.comanthropic.cn2.ai
Groqapi.groq.com/openaigroq.cn2.ai
Mistralapi.mistral.aimistral.cn2.ai

2. Send a request

The request body is identical to what you'd send to the provider directly. Remove any provider API key — cn2.ai handles authentication via MPP.

curl https://openai.cn2.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

This returns HTTP 402 with a WWW-Authenticate header containing the payment challenge. The response body includes the price and instructions.

3. Pay and retry

Use an MPP-compatible client library to handle payment automatically:

import { Mppx } from 'mppx/client'

// mppx wraps fetch() and handles 402 challenges automatically
const mppx = Mppx.create({
  methods: [tempo({ wallet: myWallet })],
})

const response = await fetch('https://openai.cn2.ai/v1/chat/completions', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: 'Hello' }],
  }),
})

The mppx SDK intercepts the 402 response, pays the challenge amount, and retries with the payment credential — all in one fetch() call. SDKs are available in TypeScript, Python, and Rust.

Payment methods

  • Stripe — pay with any card (Visa, Mastercard, etc.)
  • Tempo — pay with USDC stablecoin. Supports both one-time charges and session-based streaming payments
  • Lightning — pay with Bitcoin over the Lightning Network

What you get back

On successful payment, you receive:

  • The upstream API response — exactly as the provider would return it
  • A Payment-Receipt header with proof of payment (use this for disputes if needed)
  • Streaming (SSE) is fully supported for providers that offer it