Delivery and retries
Codex sends webhook messages via HTTP POST and expects a 2xx response within 3 seconds. If your endpoint responds slowly or fails, the message will be retried up to two additional times with gradually increasing delays. If your service is down for long enough, some messages will be lost.- Processed means an event matched at a basic level (for example, maker, pair, or token address)
- Triggered means all conditions passed and Codex will try to publish
- Success means publishing was attempted and succeeded
- Failed means publishing was attempted and failed (usually a bad URL)
Creating a webhook
The fastest way to create and test a webhook is through the Codex Explorer, which provides a visual builder for every supported event type. To create one programmatically, use thecreateWebhooks mutation. Each event type has its own input field on the mutation (for example, tokenPairEventWebhooksInput or predictionTradeWebhooksInput). See the event type sections below for a ready-to-use creation example for each.
Organizing webhooks with bucketKey
You can optionally group and query your webhooks using a bucketKey. This is useful when you are managing many webhooks per user or per token, such as a price alert system.
bucketId and bucketSortKey must be provided together. If you don’t need to query webhooks by bucket, you can omit bucketKey entirely. Using both fields lets you independently query all alerts for a specific user and all alerts for a specific token.
bucketId and bucketSortKey fields on createWebhook are deprecated. Use the bucketKey object instead.Message structure
Every webhook message shares a common envelope. Thetype field tells you which event fired, and the data field contains the event-specific payload described in the event type sections.
TOKEN_PAIR_EVENT, TOKEN_PAIR_EVENT_BATCH, TOKEN_PRICE_EVENT, TOKEN_PRICE_EVENT_BATCH, TOKEN_TRANSFER_EVENT, TOKEN_TRANSFER_EVENT_BATCH, MARKET_CAP_EVENT, MARKET_CAP_EVENT_BATCH, PREDICTION_TRADE_EVENT, PREDICTION_TRADE_EVENT_BATCH, PREDICTION_MARKET_METRICS_EVENT, or PREDICTION_MARKET_METRICS_EVENT_BATCH.securityToken and deduplicationId. Prefer the X-Webhook-Timestamp and X-Webhook-Signature headers described in Verifying webhooks. The legacy hash does not cover the request body and is still emitted only for backwards compatibility.type. See the event type sections for each payload structure.Verifying webhooks
Every webhook delivery includes two signature headers that authenticate the exact request body bytes and provide a freshness signal for replay protection:X-Webhook-Timestamp: Unix timestamp in seconds.X-Webhook-Signature: lowercase hex HMAC-SHA256 over{timestamp}.{rawBody}, using your webhook’ssecurityTokenas the key.
- Read the raw request body bytes as received, before any JSON parsing.
- Build the signed payload string
{timestamp}.{rawBody}. - Compute
hex(hmac_sha256(securityToken, signedPayload))and compare it toX-Webhook-Signatureusing a constant-time comparison. - Reject the request if
abs(now - X-Webhook-Timestamp) > 300seconds, or if either header is missing or malformed.
- Next.js App Router: call
await request.text()once and use that exact string. - Next.js API routes: set
export const config = { api: { bodyParser: false } }, then read the request stream into a buffer. - Express: mount
express.raw({ type: "application/json" })on the webhook route, or capture the buffer inexpress.json({ verify }). - AWS Lambda + API Gateway: use
event.bodydirectly, base64-decoding whenevent.isBase64Encodedis true. - Rails/Rack: use
request.raw_post. Flask/Django:request.get_data()/request.body.
- Parsing and re-serializing JSON before verification.
- Verifying only
dataor the legacyhashfield instead of{timestamp}.{rawBody}. - Comparing signatures with
==instead of a constant-time helper. - Treating the timestamp as milliseconds.
X-Webhook-Timestampis Unix seconds. - Skipping the freshness check, which removes replay protection.
Hash verification (deprecated)
The legacyhash is a SHA256 digest of your webhook’s securityToken concatenated with the message’s deduplicationId:
Source IP addresses
Codex sends webhook deliveries from a fixed set of IP addresses. If you want to gate inbound webhook traffic at the network layer in addition to verifying the signature on each payload, allowlist these IPs at your firewall or load balancer:Event types
Each event type fires on a different kind of on-chain or market activity. Pick the one that matches what you want to react to, then jump to its section below for filter conditions, the input field, a copy-paste mutation, and a sample payload.| Event | Fires when |
|---|---|
| Token Pair Event | Swaps, mints, burns, and other liquidity events on a trading pair. The most common type. |
| Token Price Event | A token’s price crosses a threshold you set. |
| Token Transfer Event | Tokens move to or from a wallet you’re watching. |
| Market Cap Event | A token’s market cap — fully diluted or circulating — crosses a threshold. |
| Prediction Trade Event | Individual Polymarket or Kalshi trades, filterable by trader, market, event, side, or size. |
| Prediction Market Metrics Event | A prediction market’s rolling windowed stats — volume, price, or trade count — cross a threshold, at the market or per-outcome level. |
TOKEN_PAIR_EVENT
The TOKEN_PAIR_EVENT webhook fires when a swap, mint, burn, or other liquidity event occurs on a trading pair. It delivers the full Pair and Event objects so you can reconstruct exactly what happened on-chain. This is the most commonly used webhook.
When to use it
- Tracking every trade made by a specific wallet
- Monitoring high-value swaps on a single token or pair
- Feeding a live trade tape for a specific pool
- Alerting on liquidity events (mints, burns) for a pair
tokenAddress: fire for events involving this tokennetworkId: one or more network IDs to listen onswapValue: filter by USD value of the swapmaker: fire for events made by a specific walletpairAddress: fire for events on a specific pairexchangeAddress: fire for events on a specific exchangeeventType: filter to specific event types (SWAP,MINT,BURN,SYNC,BUY,SELL,COLLECT,COLLECT_PROTOCOL)
tokenPairEventWebhookConditionInput.
Creation example
Creation example
Message payload
Message payload
TOKEN_PRICE_EVENT
The TOKEN_PRICE_EVENT webhook fires when the price of a specific token crosses a threshold you define. Use it for price alerts on tokens you care about.
When to use it
- Price alerts for a single token (for example, “WETH above $4000”)
- Watchlist-style notifications for a small set of tokens
- Dashboard price tickers where polling is not acceptable
address: the token contract address (required)networkId: the network ID (required)priceUsd: price condition that must be met (required). Supportsgt,gte,lt,lte,eq
tokenPriceEventWebhookConditionInput.
Creation example
Creation example
Message payload
Message payload
TOKEN_TRANSFER_EVENT
The TOKEN_TRANSFER_EVENT webhook fires when a token is transferred to or from a wallet you are monitoring. Use it to track wallet inflows and outflows in real time.
When to use it
- Monitoring whale wallet movements
- Triggering on-chain alerts for your own wallets
- Watching known exchange hot wallets or bridge addresses
tokenAddress: the token contract to tracknetworkId: one or more network IDsaddress: the wallet address to monitordirection:TO(receiving),FROM(sending), or both
tokenTransferEventWebhookConditionInput.
Creation example
Creation example
Message payload
Message payload
MARKET_CAP_EVENT
The MARKET_CAP_EVENT webhook fires when a token’s market cap crosses a threshold you specify. Unlike token price webhooks, it factors in supply (both fully diluted and circulating).
When to use it
- Market cap milestone alerts (for example, “VIRTUAL crosses $1B FDV”)
- Large-cap filtering logic for automated tools
- Portfolio-level risk dashboards
tokenAddress: the token contract (required)networkId: the network ID (required)fdvMarketCapUsd: fully diluted market cap thresholdcirculatingMarketCapUsd: circulating market cap thresholdpairAddress: optional source pair constraintliquidityUsd,volumeUsd: optional pair-level liquidity and volume constraints
marketCapEventWebhookConditionInput.
Creation example
Creation example
Message payload
Message payload
PREDICTION_TRADE_EVENT
The PREDICTION_TRADE_EVENT webhook fires when a prediction market trade occurs. Use it to track trades by a specific trader, on a specific market or event, or matching conditions like trade value or volume.
When to use it
- Tracking copy-traded wallets on Polymarket or Kalshi
- Notifying on large trades in a specific market or event
- Feeding a live trade tape for a prediction market dashboard
traderId: fire for a specific tradermarketId: fire for a specific marketeventId: fire for a specific eventeventType: filter by trade event type (TRADE,BUY,SELL,BUY_COUNTERPARTY,SELL_COUNTERPARTY,PAYOUT_REDEMPTION)tradeValueUsd: filter by trade value in USDamountToken: filter by number of tokens or shares traded
predictionTradeWebhookConditionInput.
Creation example
Creation example
Message payload
Message payload
PREDICTION_MARKET_METRICS_EVENT
The PREDICTION_MARKET_METRICS_EVENT webhook fires when rolling, windowed statistics for a prediction market cross a threshold you define — at the whole-market level or for an individual outcome. Use it to react to volume spikes, price moves, or bursts of trading activity on a Polymarket or Kalshi market without polling.
When to use it
- Alerting on volume or trade-count spikes on a specific market
- Tracking a price move on a single outcome (for example, “Yes” climbing past 60%)
- Driving a live activity feed for a prediction market dashboard
min5, hour1, hour4, hour12, day1, and week1. Set a condition on one or more windows, and within a window match on:
- Market-level metrics (the
marketfield):volumeUsd,trades,volumeChange,tradesChange - Per-outcome metrics (
outcome0,outcome1, oranyOutcome): everything available at the market level pluspriceandpriceChange
marketId is required — each webhook is pinned to a single market. Every metric supports the standard gt, gte, lt, lte, and eq operators.
See the full input type at predictionMarketMetricsEventWebhookConditionInput.
Creation example
Creation example
Message payload
Message payload
data object carries the market, its lifecycle, one block per rolling window (statsMin5, statsHour1, statsHour4, statsHour12, statsDay1, statsWeek1), and trending / relevance / competitive score series. Each window holds market-level core totals, outcome0Stats / outcome1Stats (price, volume, orderbook), and a statsChange block whose volumeChange, tradesChange, and priceChange ratios are what your filter conditions compare against. The example shows the min5 window in full; the other windows share the same shape.FAQ
How many tokens can I add to a single webhook?
How many tokens can I add to a single webhook?
bucketKey field makes managing large sets straightforward).How do I push real-time buys via webhooks?
How do I push real-time buys via webhooks?
TOKEN_PAIR_EVENT webhook for the token and filter eventType to BUY. The webhook payload includes the full event object, so you don’t need a follow-up call to enrich the data. See the TOKEN_PAIR_EVENT section above for the full creation example.What is the `securityToken` field for, and how do I verify it?
What is the `securityToken` field for, and how do I verify it?
securityToken is your secret. Codex uses it as the HMAC key for the X-Webhook-Signature header on every delivery, which authenticates the exact raw request body. See Verifying webhooks for the full verification flow. The legacy body hash field is also derived from securityToken but is deprecated because it doesn’t cover the body.How is webhook usage measured against my plan's monthly request limit?
How is webhook usage measured against my plan's monthly request limit?