Skip to main content

Add x402 payment gating to any Python API -- list it in the Cinderwright index in minutes

Project description

cinderwright-server

PyPI

Monetize any Python API in minutes. Add x402 payment gating to a Flask or FastAPI endpoint with one decorator. Your service is automatically listed in the Cinderwright index where AI agents can discover and pay for it.


Install

pip install cinderwright-server

Quickstart

1. Register your service

cinderwright-server register \
    --name "My Weather API" \
    --url https://myapi.com \
    --key sk_cw_... \
    --wallet 0xYourBaseWallet \
    --price 0.01 \
    --description "Real-time weather for any city"

You'll receive a service_key and service_secret. Store the secret as an environment variable.

export CW_SERVICE_SECRET=ss_...

2. Add the decorator

Flask:

from flask import Flask, jsonify, request
from cinderwright_server import x402
import os

app = Flask(__name__)

@app.route('/weather')
@x402(
    price=0.01,
    service_key="svc_cw_...",
    service_secret=os.environ['CW_SERVICE_SECRET'],
    description="Real-time weather for any city",
)
def weather():
    city = request.args.get('city', 'London')
    return jsonify({'weather': get_weather(city), 'city': city})

if __name__ == '__main__':
    app.run(port=5000)

FastAPI:

from fastapi import FastAPI, Request
from cinderwright_server import x402
import os

app = FastAPI()

@app.get('/weather')
@x402(
    price=0.01,
    service_key="svc_cw_...",
    service_secret=os.environ['CW_SERVICE_SECRET'],
)
async def weather(request: Request, city: str = 'London'):
    return {'weather': get_weather(city), 'city': city}

3. Test it

cinderwright-server test --url https://myapi.com/weather

Output:

✓ Returns 402 Payment Required
✓ payment-required header present
✓ x402Version: 1
✓ price: $0.01
✓ service_key: svc_cw_...

4. Check earnings

cinderwright-server earnings

How it works

When an AI agent calls your service without payment:

  • Your endpoint returns 402 Payment Required with the price and routing info
  • The agent's Cinderwright proxy pays on their behalf
  • The proxy retries with an X-CW-Verify header
  • Your decorator verifies the HMAC token (no blockchain calls needed)
  • Request passes through, you earn per call

Earnings: You receive the price you set minus a $0.003 infrastructure fee. Earnings accumulate as Cinderwright credits, redeemable against API calls or future withdrawal.


Local development

Set CW_DEV_MODE=1 to skip payment verification during local development:

export CW_DEV_MODE=1
python app.py

Or pass it to the decorator:

@x402(price=0.01, service_key="...", service_secret="...", dev_mode=True)
def handler():
    ...

Pricing model

You set the price. We take $0.003 per verified call. You keep the rest.

Your price You receive Our fee
$0.01/call $0.007 $0.003
$0.005/call $0.002 $0.003
$0.05/call $0.047 $0.003

Minimum price: $0.005 (must exceed our fee).


Discovery

Once registered, your service appears in the Cinderwright index at: https://api.ideafactorylab.org/discover?q=your+service+name

AI agents using pip install cinderwright or the MCP server will automatically discover and call it.


CLI reference

# Register a new service
cinderwright-server register --name NAME --url URL --key CW_KEY --wallet WALLET [--price 0.01] [--description DESC]

# Check earnings
cinderwright-server earnings [--key svc_cw_...] [--secret ss_...]

# Test endpoint returns proper 402
cinderwright-server test --url https://myapi.com/endpoint

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cinderwright_server-1.0.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cinderwright_server-1.0.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file cinderwright_server-1.0.0.tar.gz.

File metadata

  • Download URL: cinderwright_server-1.0.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cinderwright_server-1.0.0.tar.gz
Algorithm Hash digest
SHA256 59661401cd36bee8ac41266d58c60b8160efc89856ad125cebfd86fb291beefd
MD5 9284a6a0fefd48e430df8c8be48ddd51
BLAKE2b-256 4930e3403f1de93cd55a145760d4e783794ebd7a92a81033d6a0afceb95deab0

See more details on using hashes here.

File details

Details for the file cinderwright_server-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cinderwright_server-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09ac31b4ede31e9473b9b409d4ac56ae114c9a445fecac96ca85c042ee0c25ad
MD5 9a39ce3e6fb250aab032e04e705a0a66
BLAKE2b-256 256ba532c1cf9a93816e9bc05f2a2f74dae0e5acae06f1e061559d0a2d1cb974

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page