API Documentation
Complete technical reference for the Syzy x402 prediction market APIs. All paid endpoints use the x402 micropayment protocol for pay-per-call access.
Quick Start
[1] Install dependencies
npm install @x402/fetch @x402/svm @solana/web3.js[2] Set up the client
import { wrapFetch } from "@x402/fetch";
import { createSvmSigner } from "@x402/svm";
import { Keypair } from "@solana/web3.js";
const keypair = Keypair.fromSecretKey(/* your secret key */);
const signer = createSvmSigner(keypair);
const fetchWith402 = wrapFetch(fetch, signer);
const BASE_URL = "https://api.oyrade.com";[3] Make your first call
// Health check (free)
const health = await fetchWith402(`${BASE_URL}/health`);
const { data } = await health.json();
console.log(data.status); // "ok"
// Create your first market ($0.50)
const res = await fetchWith402(`${BASE_URL}/api/v1/markets/create`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
token_mint: "DfnxGQUsXdDH7DYdroeeSBG8etqTy1kufxBikHwTTGTa",
question: "Will BTC reach $150K by March 2026?",
market_name: "BTC 150K",
slug: "btc-150k-march-2026",
category: "crypto",
end_date: 1740787200,
}),
});
const market = await res.json();
console.log("Market ID:", market.data.market_id);Payment Flow
The x402 protocol adds payment negotiation to standard HTTP. Here is what happens when you call a paid endpoint:
Client sends a request to a protected endpoint
Server returns 402 Payment Required with payment details (amount, recipient, token)
Client signs a USDC payment transaction on Solana
Client retries the request with X-PAYMENT header containing the signed payment
Server verifies the payment on-chain and processes the request
Server returns success response
@x402/fetch handles steps 2-4 automatically. Wrap the native fetch with wrapFetch(fetch, signer) and the library negotiates payment for you.
Paid Endpoints
/api/v1/markets/createCreate a new on-chain prediction market with optional oracle integration. Returns the market ID and token mint addresses.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| token_mint | string | Required | SPL token mint address (base58) |
| question | string | Required | The prediction question (1-100 chars) |
| market_name | string | Required | Short market name (1-32 chars) |
| slug | string | Required | URL slug for the market (1-128 chars) |
| category | string | Required | Market category (1-32 chars) |
| end_date | number | Required | Unix timestamp for market deadline (must be in the future) |
| image_url | string | Optional | Market image URL (max 256 chars) |
| source | string | Optional | Source identifier (max 32 chars, default: 'x402') |
| oracle_feed | string | Optional | Switchboard oracle feed pubkey for auto-resolution |
| price_target | number | Optional | Target price for oracle-based resolution |
| comparison_type | number | Optional | Oracle comparison: 0 = Greater Than, 1 = Less Than, 2 = Equal |
| market_version | number | Optional | 0 = Dynamic Parimutuel (default), 1 = Conditional Token Framework |
| collateral_per_pair | number | Optional | SOL per token pair (min 0.001, required if market_version is 1) |
Request Body
{
"token_mint": "DfnxGQUsXdDH7DYdroeeSBG8etqTy1kufxBikHwTTGTa",
"question": "Will BTC reach $150K by March 2026?",
"market_name": "BTC 150K",
"slug": "btc-150k-march-2026",
"category": "crypto",
"end_date": 1740787200,
"oracle_feed": "HNStfhaLnqwF2ZtJUizaA9uHDAVB976r2AgTUx9LrdEo",
"price_target": 150000,
"comparison_type": 0,
"market_version": 1,
"collateral_per_pair": 0.01
}Success Response
{
"success": true,
"data": {
"market_id": "7xKp...",
"yes_token_mint": "4rQz...",
"no_token_mint": "8mNp...",
"tx_signature": "5UBq...",
"question": "Will BTC reach $150K by March 2026?",
"end_date": 1740787200
}
}/api/v1/markets/:id/predictPlace a prediction on a market outcome. Requires a commitment hash for privacy-preserving predictions. Price is dynamic: base fee plus 3% of prediction amount.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| outcome | string | Required | "YES" or "NO" |
| amount | number | Required | SOL amount from fixed buckets: 0.1, 0.5, 1, 5, 10 |
| commitment_hash | string | Required | Poseidon hash for privacy (exactly 64 hex chars) |
Request Body
{
"outcome": "YES",
"amount": 0.5,
"commitment_hash": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"
}Success Response
{
"success": true,
"data": {
"prediction_id": "uuid",
"commitment": "abc123...",
"outcome": "YES",
"amount": 0.5,
"tokens_received": 0.312,
"effective_price": 0.62,
"yes_price_after": 0.65,
"no_price_after": 0.35
}
}- commitment_hash is REQUIRED and must be exactly 64 hex characters
- Amount must be one of the fixed buckets: 0.1, 0.5, 1, 5, or 10 SOL
- Returns 409 Conflict if a duplicate commitment_hash is submitted
/api/v1/markets/:id/sellSell prediction tokens back to the market. Specify the commitment hash of the position to sell. Omit amount to sell all tokens.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| commitment_hash | string | Required | Commitment hash from the original prediction |
| payout_address | string | Required | Solana wallet address for SOL payout |
| amount | number | Optional | Number of tokens to sell (omit to sell all) |
Request Body
{
"commitment_hash": "a1b2c3d4e5f6...",
"payout_address": "8mNp...",
"amount": 0.312
}Success Response
{
"success": true,
"data": {
"tx_signature": "3nKm...",
"tokens_sold": 0.312,
"sol_received": 0.28,
"payout_address": "8mNp..."
}
}/api/v1/markets/:id/claimClaim winnings from a resolved market. Returns the payout if your position won, or a reason if it lost.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| commitment_hash | string | Required | Commitment hash from the original prediction |
| payout_address | string | Required | Solana wallet address for SOL payout |
Request Body
{
"commitment_hash": "a1b2c3d4e5f6...",
"payout_address": "8mNp..."
}Success Response
{
"success": true,
"data": {
"claimable": true,
"tx_signature": "9pLq...",
"sol_received": 0.5,
"winning_outcome": "YES",
"payout_address": "8mNp..."
}
}Error / Alternative Response
{
"success": true,
"data": {
"claimable": false,
"reason": "Position lost — outcome was NO, market resolved YES"
}
}- Market must be resolved before claiming
- Loss response returns claimable: false with a reason string
/api/v1/markets/:id/resolveTrigger oracle-based resolution for a market. Returns the outcome if the market deadline has passed and oracle data is available.
Success Response
{
"success": true,
"data": {
"resolved": true,
"winning_outcome": "YES",
"oracle_price": "151234.50",
"oracle_source": "switchboard",
"tx_signature": "9pLq...",
"resolved_at": 1740787500
}
}Error / Alternative Response
{
"success": true,
"data": {
"resolved": false,
"reason": "Market deadline has not passed yet",
"end_date": 1740787200
}
}- Returns resolved: false if the market deadline has not passed
- Oracle resolution may take a few seconds after deadline
/api/v1/markets/:id/privacy-proof?commitment_hash=abc...Get a ZK Merkle inclusion proof for a shielded prediction. Proves prediction existence without revealing identity or exact amount.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| commitment_hash | string | Required | Commitment hash from the original prediction (query parameter) |
Success Response
{
"success": true,
"data": {
"position_exists": true,
"outcome": "YES",
"amount_range": "0.5-1",
"merkle_root": "9f8e...",
"proof_path": ["ab12...", "cd34...", "ef56..."]
}
}/api/v1/markets/:id/newsGet curated news articles related to a specific market.
Success Response
{
"success": true,
"data": {
"news": [
{
"id": "uuid",
"title": "BTC breaks $100K resistance",
"description": "Bitcoin surpassed...",
"image_url": "https://...",
"url": "https://x.com/...",
"published_at": "2026-02-20T10:00:00Z"
}
]
}
}Free Endpoints
/api/v1/marketsList all available prediction markets with current prices, volume, and status.
Success Response
{
"success": true,
"data": {
"markets": [
{
"market_id": "7xKp...",
"question": "Will BTC reach $150K?",
"market_name": "BTC 150K",
"category": "crypto",
"yes_price": 0.62,
"no_price": 0.38,
"total_volume_sol": 45.5,
"end_date": 1740787200,
"is_completed": false,
"winning_outcome": null,
"oracle_feed": "HNSt...",
"created_at": 1735689600,
"market_version": 1
}
]
}
}/api/v1/markets/:idGet full details for a single market including reserves, token supply, and oracle configuration.
Success Response
{
"success": true,
"data": {
"market_id": "7xKp...",
"question": "Will BTC reach $150K?",
"market_name": "BTC 150K",
"slug": "btc-150k",
"category": "crypto",
"source": "x402",
"image_url": "https://...",
"yes_price": 0.62,
"no_price": 0.38,
"yes_sol_reserves": 22.5,
"no_sol_reserves": 23.0,
"yes_token_supply": 36.3,
"no_token_supply": 60.5,
"total_volume_sol": 45.5,
"end_date": 1740787200,
"start_date": 1735689600,
"is_completed": false,
"winning_outcome": null,
"resolved_at": null,
"oracle_feed": "HNSt...",
"price_target": 150000,
"comparison_type": 0,
"metric_type": "price",
"market_version": 1,
"collateral_per_pair": 0.01,
"created_at": 1735689600
}
}/api/v1/markets/:id/history?range=1d|1w|allGet historical price snapshots for charting. Supports 1-day, 1-week, or all-time ranges.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| range | string | Optional | "1d", "1w", or "all" (query parameter) |
Success Response
{
"success": true,
"data": {
"snapshots": [
{
"timestamp": "2026-02-20T10:00:00Z",
"yes_price": 0.62,
"no_price": 0.38
}
]
}
}/api/v1/markets/:id/commentsGet comment threads for a market, including nested replies.
Success Response
{
"success": true,
"data": {
"comments": [
{
"id": "uuid",
"content": "Looking bullish!",
"author": "alice",
"avatar": null,
"reply_count": 2,
"replies": [
{
"id": "uuid",
"content": "Agree!",
"author": "bob",
"avatar": null,
"created_at": "2026-02-20T10:05:00Z"
}
],
"created_at": "2026-02-20T10:00:00Z"
}
]
}
}/api/v1/positions?commitment_hash=abc...,def...Look up open positions by commitment hashes. Pass multiple hashes as a comma-separated list.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| commitment_hash | string | Required | Comma-separated commitment hashes (query parameter) |
Success Response
{
"success": true,
"data": {
"positions": [
{
"commitment_hash": "abc123...",
"market_id": "7xKp...",
"outcome": "YES",
"tokens_remaining": "500000000",
"sol_spent": 0.5,
"current_value_sol": 0.62,
"payout_if_win": 0.5,
"status": "open",
"created_at": "2026-02-20T10:00:00Z"
}
]
}
}/api/v1/history?commitment_hash=abc...,def...Get trade history for given commitment hashes. Returns all buy, sell, and claim events.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| commitment_hash | string | Required | Comma-separated commitment hashes (query parameter) |
Success Response
{
"success": true,
"data": {
"trades": [
{
"type": "buy",
"commitment_hash": "abc123...",
"market_id": "7xKp...",
"outcome": "YES",
"amount_sol": "500000000",
"tokens": "312000000",
"tx_signature": "5UBq...",
"created_at": "2026-02-20T10:00:00Z"
}
]
}
}/healthHealth check endpoint. Returns service status, version, and network information.
Success Response
{
"success": true,
"data": {
"status": "ok",
"version": "0.1.0",
"network": "devnet",
"uptime": 84321000,
"market_count": 42
}
}/x402-infoDiscover all available x402 endpoints with their methods, prices, and descriptions.
Success Response
{
"success": true,
"data": {
"name": "Syzy Prediction Market API",
"description": "...",
"endpoints": [
{
"path": "/api/v1/markets/create",
"method": "POST",
"price": "$0.50",
"price_usdc": 0.50,
"description": "Create prediction market"
}
],
"network": "solana-devnet",
"payment_token": "USDC"
}
}Error Handling
All errors follow a standard format:
{
"success": false,
"error": {
"code": "INVALID_COMMITMENT",
"message": "commitment_hash must be exactly 64 hex characters"
}
}Status Codes
| Code | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad Request -- invalid parameters |
| 402 | Payment Required -- pay and retry with X-PAYMENT header |
| 404 | Not Found -- market does not exist |
| 409 | Conflict -- duplicate commitment or market already resolved |
| 429 | Rate Limited -- 100 requests/min per IP |
Environment & Network
Network
Solana Devnet
Base URL
Configurable (your backend)
Payment Token
USDC (Solana)
Protocol
x402 Micropayments