Manually set a verification key for authorization
When verifying a Privy access token to authorize requests to your servers, by default the Privy Client’sverifyAuthToken method will make a request to Privy’s API to fetch the verification key for your app. Although it is cached for reuse, you can avoid this API request entirely by copying your verification key from the Configuration > App settings > Basics tab of the Dashboard, under “Verify with key instead”:
Get user data with identity tokens
If you need access to the user object, especially on the server, this can be a costly action. To remove a network call from your critical path, we recommend using Privy’s identity tokens, which include the latest user information in token form. While it does not have the full user details (it omits certain lesser-needed fields for efficiency), it should have what you need to get started quickly.Set a custom API URL for HttpOnly cookies (react-auth only)
In the case where you have set up and enabled HttpOnly cookies, on initial page load, the Privy SDK will start by making a call to fetch app details on our default https://auth.privy.io API URL. In HttpOnly cookie mode however, all your requests are routed through https://privy.<customdomain.com>. To avoid an occasional extra call on page load, we recommend explicitly setting the apiUrl in your PrivyProvider:
HttpOnly cookies, you will need to remove this in order for your app to continue functioning properly. For a smooth transition, first remove the apiUrl, deploy, and then disable HttpOnly cookies.
Handling rate limits
When your application encounters rate limiting (HTTP 429 responses), implementing proper retry logic ensures a smooth user experience and optimal API usage.Understanding rate limit responses
When you exceed a rate limit, Privy’s API returns a429 Too Many Requests status code. Rate limits are applied per endpoint and are designed to ensure fair usage across all applications.
Best practices for handling rate limits
1. Implement exponential backoff
Exponential backoff is a standard error-handling strategy that gradually increases the wait time between retry attempts:2. Batch your requests
Instead of making individual API calls for each operation, batch multiple operations together when possible:3. Cache responses when appropriate
For data that doesn’t change frequently, implement caching to reduce API calls:4. Use identity tokens for authenticated users
For getting user data about authenticated users, use identity tokens instead of making API calls. This approach is rate-limit-free and provides user information directly from the token.5. Implement circuit breakers
For production applications, consider implementing a circuit breaker pattern to temporarily stop making requests when rate limits are consistently hit:Additional optimization tips
- Monitor your usage: Track your API call patterns to identify optimization opportunities
- Use webhooks: For real-time updates, consider using webhooks instead of polling endpoints
- Optimize query patterns: Review your query logic to eliminate unnecessary or redundant API calls
- Parallelize independent requests: Use
Promise.all()for independent requests to reduce total execution time while staying within rate limits

