A minimal, production-quality FastAPI application demonstrating verifiable AI inference using the OpenGradient Python SDK with TEE (Trusted Execution Environment) verification and x402 on-chain settlement.
Opengradient VAOD/
├── .env.example # Environment variable template
├── requirements.txt # Python dependencies
├── README.md # ← You are here
└── app/
├── __init__.py
├── config.py # Settings & env loading
├── og_client.py # OpenGradient client wrapper
├── inference.py # Inference service layer
├── routes.py # FastAPI route handlers
├── main.py # Application entrypoint
└── templates/
└── index.html # Minimal UI
- Python 3.10+
- A Base Sepolia wallet funded with
$OPGtestnet tokens- Get tokens: https://faucet.opengradient.ai
cd "Opengradient VAOD"
pip install -r requirements.txtcp .env.example .envEdit .env and set your private key:
OG_PRIVATE_KEY=0xYOUR_ACTUAL_PRIVATE_KEYuvicorn app.main:app --reload --host 0.0.0.0 --port 8000Navigate to http://localhost:8000 in your browser.
┌─────────────┐ POST /infer ┌──────────────┐
│ Browser │ ──────────────────▶ │ FastAPI App │
│ (prompt) │ │ │
└─────────────┘ │ inference.py │
│ │ │
│ ▼ │
│ og_client.py │
└───────┬───────┘
│
client.llm.chat() via x402
│
▼
┌─────────────────────────┐
│ OpenGradient Network │
│ ┌───────────────────┐ │
│ │ TEE Node │ │
│ │ (Intel TDX) │ │
│ │ ┌─────────────┐ │ │
│ │ │ LLM Provider │ │ │
│ │ │ (OpenAI, etc)│ │ │
│ │ └─────────────┘ │ │
│ └───────────────────┘ │
│ │
│ x402 settlement │
│ on Base Sepolia │
└─────────────────────────┘
- User submits a prompt through the web UI.
- FastAPI backend calls
client.llm.chat()from the OpenGradient SDK. - The SDK signs an x402 payment with your wallet's private key.
- The request is routed to a TEE node on the OpenGradient network, which runs inside an Intel TDX enclave providing hardware-level attestation.
- The TEE node forwards the prompt to the upstream LLM provider (OpenAI, Anthropic, Google, or xAI).
- The response is returned with:
payment_hash— the x402 payment transaction hash on Base Sepoliatransaction_hash— the on-chain settlement transactionfinish_reason— why the model stopped generating
- The UI displays a Verification badge based on the presence of
payment_hash.
- TEE execution: Every inference runs inside a Trusted Execution Environment, giving cryptographic proof that the routing and verification code executed correctly.
- x402 on-chain settlement: Each call produces an on-chain receipt (
payment_hash) that anyone can verify on the OpenGradient Block Explorer. - No invented claims: The demo only surfaces fields actually returned by the SDK.
| Mode | Description |
|---|---|
SETTLE |
Most privacy-preserving — no data hashes on-chain |
SETTLE_METADATA |
Full transparency — all input/output data on-chain |
SETTLE_BATCH |
Cost-efficient — batches multiple calls together |
| Method | Path | Description |
|---|---|---|
| GET | / |
Web UI |
| POST | /infer |
Run inference (JSON body) |
| GET | /health |
Health check |
{
"prompt": "What is 2+2?",
"model": "GPT_4O",
"settlement_mode": "SETTLE_METADATA"
}