Code Examples
Code Examples
Ready-to-use snippets to get you started quickly.
List Markets
Fetch markets filtered by category and severity.
Pythonimport httpx
response = httpx.get(
"https://api.predictingapi.com/v1/markets",
headers={"X-API-Key": "your-api-key"},
params={"category": "WAR", "severity_min": 50}
)
for market in response.json():
print(f"{market['title']}: {market['price']}")
JavaScript
const response = await fetch(
"https://api.predictingapi.com/v1/markets?category=WAR&severity_min=50",
{ headers: { "X-API-Key": "your-api-key" } }
);
const markets = await response.json();
markets.forEach(m => console.log(m.title, m.price));
curl
curl -H "X-API-Key: your-api-key" \
"https://api.predictingapi.com/v1/markets?category=WAR&severity_min=50"
Get Single Market
Retrieve full metadata for a specific market.
Pythonimport httpx
market_id = "polymarket_0x1d54eb5eac2cee8f..."
response = httpx.get(
f"https://api.predictingapi.com/v1/markets/{market_id}",
headers={"X-API-Key": "your-api-key"}
)
market = response.json()
print(market['title'])
print(market['category'])
print(market['severity'])
Filter by Region
Get markets for a specific geographic region.
Pythonimport httpx
response = httpx.get(
"https://api.predictingapi.com/v1/markets",
headers={"X-API-Key": "your-api-key"},
params={"region": "EUROPE", "limit": 50}
)
print(f"Found {len(response.json())} European markets")
Database Stats
Get overall statistics about available markets.
curlcurl -H "X-API-Key: your-api-key" \
"https://api.predictingapi.com/v1/stats"
x402 Payment Flow
Pay $0.25 per query with USDC on Solana. No subscription required.
Pythonimport httpx
# Step 1: Make request without payment - get 402 response
response = httpx.get("https://api.predictingapi.com/v1/markets")
if response.status_code == 402:
payment_info = response.json()["paymentRequirements"]
# Payment details from 402 response:
# - payTo: Solana wallet address
# - maxAmountRequired: USDC micro-units (10000 = $0.01)
# - network: solana-mainnet
# Step 2: Send USDC payment on Solana (use your wallet SDK)
tx_signature = send_usdc_payment(
to=payment_info["payTo"],
amount=int(payment_info["maxAmountRequired"])
)
# Step 3: Retry with X-PAYMENT header
response = httpx.get(
"https://api.predictingapi.com/v1/markets",
headers={"X-PAYMENT": tx_signature}
)
markets = response.json()
JavaScript
// Using Solana wallet adapter
const response = await fetch("https://api.predictingapi.com/v1/markets");
if (response.status === 402) {
const { paymentRequirements } = await response.json();
// Send USDC via Phantom/Solflare
const txSignature = await sendUSDCPayment({
to: paymentRequirements.payTo,
amount: parseInt(paymentRequirements.maxAmountRequired)
});
// Retry with payment proof
const data = await fetch("https://api.predictingapi.com/v1/markets", {
headers: { "X-PAYMENT": txSignature }
}).then(r => r.json());
}
API Key Subscription (Coming Soon)
Unlimited access with your API key ($200/month).
curlcurl -H "X-API-Key: your-api-key" \
"https://api.predictingapi.com/v1/markets?category=WAR&limit=10"
Python
import httpx
# API key subscription - unlimited access
response = httpx.get(
"https://api.predictingapi.com/v1/markets",
headers={"X-API-Key": "your-api-key"},
params={"category": "WAR", "limit": 10}
)
markets = response.json()
print(f"Found {len(markets)} WAR markets")