Skip to main content

Batch Queries Where Possible

Several Codex query endpoints accept multiple inputs in a single request. Each batched call counts as one request, so use these instead of making separate calls: One getTokenPrices call with 25 tokens = 1 request. Twenty-five individual calls = 25 requests.
Batching a subscription does not reduce usage. onPricesUpdated lets you watch up to 25 tokens in a single subscription (and onTokenBarsUpdated batches similarly), but each message still delivers a single token’s update and bills per message — and updates fire per swap no matter how you group tokens. Watching 25 tokens in one subscription costs the same in requests as watching them across 25 subscriptions. The benefit is operational, not billing: fewer subscriptions and connections to open and manage. To actually cut subscription usage, see Manage Subscription Lifecycle and Use Subscriptions Instead of Polling.

Request Only the Fields You Need

GraphQL lets you specify exactly which fields to return. Requesting fewer fields means smaller payloads, faster responses, and less data to parse.

Use Subscriptions Instead of Polling

If you’re calling a query on a timer to check for updates, switch to a subscription. It’s faster and often more efficient.
Subscriptions are more efficient for low-to-medium frequency updates. For very high-frequency data (e.g. SOL trade events), subscriptions may actually generate more requests than polling — so consider your token’s volume when choosing.
See Queries vs Subscriptions to find the right approach for your use case.

Proxy Subscriptions Through Your Backend

If multiple users are viewing the same data, don’t create a separate subscription for each user. Instead, subscribe once on your backend and fan out the data to connected clients.
This applies to any shared data: charts, trade feeds, token stats, holder lists.

Cache Data That Doesn’t Change Often

Some data changes rarely and doesn’t need to be fetched on every request: Cache on your backend and serve from cache to avoid unnecessary API calls.

Use Filters to Reduce Noise

Codex indexes 75M+ tokens across 100+ networks — most of which aren’t useful for most applications. Always apply filters to narrow results:
Without filters, you’ll get results dominated by inactive, low-liquidity, or spam tokens.

Manage Subscription Lifecycle

Idle subscriptions still consume requests. Implement these patterns to avoid wasting your limit:
  • Idle detection — pause subscriptions when users are inactive using hooks like useIdle, and resume when they return
  • Page visibility — unsubscribe when the browser tab is hidden, resubscribe when it becomes visible
  • Component cleanup — always unsubscribe in cleanup/unmount handlers to prevent orphaned subscriptions

Use the Right Endpoint for the Job

Some endpoints are more efficient than others depending on what you need:

Paginate Large Result Sets

For endpoints that return many results, use cursor-based pagination rather than trying to fetch everything at once. Endpoints like getTokenEvents return a cursor alongside the results; pass it back on the next call to fetch the following page. A non-null cursor means more results are available.
Fetch only the pages you need. Don’t paginate through the entire dataset if you only need the first few pages.