By default, SDKs check for updates to your flag logic in the background. When you save and activate a new commit from the Hypertune UI, SDKs will fetch your new flag logic and use it on the next flag evaluation.
You can change the frequency at which the SDK checks for updates by setting initDataRefreshIntervalMs in your createSource options:
src/lib/getHypertune.ts
import { createSource } from"../generated/hypertune";consthypertuneSource=createSource({ token:process.env.HYPERTUNE_TOKEN!, initDataRefreshIntervalMs:5_000,});exportdefaultasyncfunctiongetHypertune() {// Get flag updates in serverless environments// await hypertuneSource.initIfNeeded();returnhypertuneSource.root({ args: { context: { environment:process.env.NODE_ENV==="development"?"development":"production", user: { id:"1", name:"Test", email:"hi@test.com" }, }, }, });}
When using initIfNeeded, the initDataRefreshIntervalMs option specifies the minimum time between initialization requests.
For example, if you set this to 5_000, initIfNeeded will only trigger a new initialization request if the last one was over 5 seconds ago.
So you can await initIfNeeded on every backend request to ensure flag values are fresh while minimizing network latency and bandwidth.
This is particularly useful in serverless and edge environments like Vercel deployments, Cloudflare Workers, AWS Lambdas, etc, where background SDK tasks like fetching updates aren't guaranteed to execute.
Subscribing to flag updates
You can add and remove listeners to be notified of updates with: