• Start

Languages

/

Kotlin

/

API Reference

/

Core

SurrealClientConfig

Configuration options for the SurrealDB Kotlin client, including reconnection and authentication.

SurrealClientConfig configures a SurrealClient. The only required field is url; everything else has a sensible default.

Source: surrealdb.kotlin

Import

import com.surrealdb.kotlin.SurrealClientConfig
FieldTypeDefaultDescription
url StringThe connection URL. The scheme (ws/wss/http/https) selects the transport.
jsonJsonlenientThe kotlinx.serialization instance used for encoding and decoding.
autoConnectBooleantrueConnect lazily on the first request.
autoAuthenticateBooleanfalseAuthenticate automatically using credentialProvider on connect and reconnect.
credentialProvider(suspend () -> SurrealAuthInput?)?nullSupplies credentials for automatic authentication and token renewal.
requestTimeoutMillisLong30_000Per-request timeout in milliseconds.
reconnectReconnectConfigReconnectConfig()WebSocket reconnection behaviour.
tokenRenewalLeadMillisLong60_000How long before token expiry to renew, in milliseconds.
httpClientFactory((SurrealClientConfig) -> HttpClient)?nullSupplies a custom Ktor HttpClient.

Example

import com.surrealdb.kotlin.SurrealAuthInput
import com.surrealdb.kotlin.SurrealClientConfig
import com.surrealdb.kotlin.engine.ReconnectConfig
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put

val config = SurrealClientConfig(
url = "wss://example.com",
requestTimeoutMillis = 30_000,
autoAuthenticate = true,
tokenRenewalLeadMillis = 60_000,
reconnect = ReconnectConfig(enabled = true, multiplier = 1.5),
credentialProvider = {
SurrealAuthInput.SignIn(buildJsonObject {
put("user", "root")
put("pass", "root")
})
},
)

Controls exponential-backoff reconnection on the WebSocket transport.

Import

import com.surrealdb.kotlin.engine.ReconnectConfig
FieldTypeDefaultDescription
enabledBooleantrueWhether reconnection is attempted.
initialDelayMillisLong250Delay before the first retry.
maxDelayMillisLong30_000Maximum delay between retries.
multiplierDouble1.5Backoff multiplier applied each attempt.
maxAttemptsInt?nullMaximum attempts; null retries indefinitely.

A sealed interface describing how credentialProvider should authenticate.

Import

import com.surrealdb.kotlin.SurrealAuthInput
VariantPayloadDescription
SurrealAuthInput.SignInparams: JsonObjectSign in with credentials.
SurrealAuthInput.Tokentoken: StringAuthenticate with an existing token.

Was this page helpful?