SDKs
Last updated
Last updated
To install an SDK, see one of the .
SDKs come with a CLI tool to auto-generate a client so you can access your flags with end-to-end type-safety. This ensures typos in flag names or incorrectly passed targeting attributes can be caught at build-time rather than runtime. It also improves the developer experience with code completion, comments, "find all references" and type-safe flag clean up.
You can optionally specify an SDK initialization query to:
Select which flags to fetch
Provide some targeting attributes upfront so that any flag logic that depends on those attributes can be on the edge
This is useful for:
Performance
You can limit which flags are fetched to reduce the network payload size
You can partially reduce flag logic on the edge to:
Reduce the network payload size
Reduce the logic that needs to be locally evaluated by the SDK
Security
You can eliminate sensitive logic, e.g. a list of user IDs, on the edge so it doesn't get leaked to publicly accessible clients, e.g. in the browser
The snapshot is particularly useful for single-page apps (SPAs) as you can use your flags in the first app render without any page load delay, UI flicker or layout shift.
It also enables using Hypertune in local-only, offline mode, e.g. for running unit tests or in isolated, secure, air-gapped environments.
Whenever you evaluate a flag, you pass a hard-coded fallback value, e.g.
This ensures that in the worst-case scenario, your app still works properly.
You can hydrate or "bootstrap" the SDK in the browser with the state of the SDK on your server so you can use your flags in the first app render without any page load delay, UI flicker or layout shift.
This works well with server-side rendering frameworks like Next.js, Nuxt, Remix and Gatsby.
You can disable server initialization and use a build-time fallback snapshot of your flag logic to use SDKs in local-only, offline mode. This is useful for running unit tests or using Hypertune in isolated, secure, air-gapped environments.
You can define targeting attributes at the:
root
level
individual flag level
And provide them during:
SDK initialization
local flag evaluation
a mix of both
SDKs evaluate flags locally, synchronously, in memory with no network latency. This includes flag logic that contains A/B tests, machine learning loops and analytics event logging.
So you can use an SDK on the backend to evaluate flags, including A/B tests, for different users without adding latency to every request.
And you can use an SDK on the frontend to evaluate flags, including A/B tests, without blocking renders.
See how often different parts of your flag logic are evaluated, e.g. to see how often different targeting rules are evaluated and passed in realtime
See any SDK errors from the Hypertune UI
You can also manually trigger and wait for logs to be flushed.
SDKs listen for updates to your flag logic in the background. When you save and activate a new commit from the Hypertune UI, the SDK will fetch your new flag logic and use it on the next evaluation.
You can also manually trigger and wait for a re-initialization from the server.
And you can add and remove listeners to be notified of updates, e.g. to trigger a re-render on the frontend after an update.
Hypertune SDKs have been uniquely architected to work optimally in serverless and edge environments like:
Vercel deployments
Cloudflare Workers
AWS Lambdas
Google Cloud Functions
Netlify Functions
DigitalOcean Functions
By default, SDKs output info and error logs to the console. But you can provide a custom logging callback to capture and forward logs elsewhere, e.g. to your monitoring infrastructure.
You can shut down an SDK to cleanly stop all its background processes and terminate all its connections.
To improve reliability, you can include a fallback snapshot of your flag logic in the at build time. The SDK will instantly initialize from the snapshot first before fetching the latest flag logic from .
You can keep the snapshot fresh by setting up a to regenerate the client on every Hypertune commit. In this case, you don't need to initialize from Hypertune Edge at all, eliminating network latency and bandwidth, improving both performance and efficiency.
If is unreachable and there's no build-time fallback snapshot of your flag logic, or there's an error evaluating the flag, you'll get this hard-coded fallback value instead.
Typically, you'll provide targeting attributes when locally evaluating the root
flag, passing it the context
argument you defined in your . You'll get back the Root
SDK node which will have type-safe methods to evaluate all your individual flags.
You can also provide when evaluating individual flags.
SDKs send logs to in the background. This allows you to:
Log
Log exposures, e.g. for , and
If you deploy on Vercel, you can initialize the SDK with near-zero latency in Vercel's edge environment when you set up our .
You can create and configure the SDK and code generation to use a specific branch.