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.
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.
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.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: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 likegetTokenEvents 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.