Skip to content

Kotlin Configuration

val client = FlagsClient.builder()
.auth(Auth(
projectId = "your-project-id",
agentId = "your-agent-id",
environmentId = "your-environment-id"
))
.baseUrl("https://custom-api.flags.gg")
.maxRetries(5)
.failureThreshold(10)
.resetTimeout(Duration.ofMinutes(5))
.withMemoryCache()
.build()
Method Default Description
auth(Auth) — Required. Authentication credentials
baseUrl(String) https://api.flags.gg Custom API endpoint
maxRetries(Int) 3 Max retry attempts
failureThreshold(Int) 3 Circuit breaker failure threshold
resetTimeout(Duration) 10 seconds Circuit breaker reset timeout
withMemoryCache() Memory Use in-memory cache
withSQLiteCache(String) flags_cache.db Use a SQLite cache, so the last values survive a restart
httpClient(HttpClient) — Custom Ktor HTTP client
targetingKey(String?) — Stable user id for percentage rollouts. Without one, partial rollouts stay off
context(Map<String, String>) / context(Map<String, List<String>>) — User attributes for targeting rules

On Android, use your signed-in user’s id or a per-install id:

val prefs = context.getSharedPreferences("flags", Context.MODE_PRIVATE)
val installId = prefs.getString("install_id", null)
?: UUID.randomUUID().toString().also { prefs.edit().putString("install_id", it).apply() }
val client = FlagsClient.builder()
.auth(auth)
.targetingKey(user?.id ?: installId)
.context(mapOf("email" to listOf(user.email), "plan" to listOf(user.plan), "groups" to user.groups))
.build()
// later, e.g. after login or an upgrade; re-fetches flags
client.setTargetingKey(user.id)
client.setContext(mapOf("plan" to "pro"))

isEnabled already accounts for both. See Rollouts & Targeting Rules.

val client = FlagsClient.NewClient(
WithAuth(auth),
WithBaseURL("https://custom-api.flags.gg"),
WithMaxRetries(5),
WithMemory(),
WithSQLite("custom.db"),
WithHttpClient(customClient),
)
Method Returns Description
isEnabled(String) Boolean Check if a flag is enabled
flag(String) Flag Get a flag object
getAllFlags() List<FeatureFlag> Get all flags
close() Unit Close the client and release resources
Method Returns Description
Is(String) FlagResult Get a flag result
FlagResult.Enabled() Boolean Check if enabled

Always close the client when done to release HTTP connections:

client.close()