For AI agents: visit https://docs-en.asleep.ai/llms.txt for an index of all pages formatted in Markdown and endpoints in OpenAPI. Append .md to any documentation page URL to get its markdown version.
interface AsleepLogger {
fun d(tag: String, msg: String, throwable: Throwable? = null)
fun e(tag: String, msg: String, throwable: Throwable? = null)
fun i(tag: String, msg: String, throwable: Throwable? = null)
fun w(tag: String, msg: String, throwable: Throwable? = null)
}
Inside the SDK, it is called when d(debug), e(error), i(info), and w(warn) occur, respectively.
Parameter Name
Type
Description
tag
String
"[Asleep SDK]"
msg
String
log message
throwable
Throwable?
A class that represents problems that can occur during SDK execution.
Set User ID
Asleep.setUserId()
Sets the userId the SDK uses directly. The value you set is used in the SDK's subsequent operations.
Asleep.setUserId(userId: String)
Parameter Name
Type
Description
userId
String
The userId to set
Preferred Mic
Asleep.setPreferredMicSelector()
Injects the microphone selection policy used for recording. It must be set before calling createSleepTrackingManager() / beginSleepTracking() to apply to that session.
When set, the SDK switches to STEREO capture so the preferred microphone selection can be trusted (devices that cannot do STEREO fall back to MONO, in which case the selection may be ignored depending on the device). When null, it works as before with MONO capture and the system's default routing.
The SDK keeps the reference, so pass null to release it when it is no longer used.
The new name of getSavedAsleepConfig(). The behavior is identical to getSavedAsleepConfig(): after the foreground service is forcibly terminated and restarted, it retrieves the previously saved asleepConfig.
Overloads are provided for the API Key method and the Token method (appId and appSecret).
App Secret issued from the dashboard (Token method)
User Metadata
Save and retrieve the user's date of birth, gender, height, and weight. These are called as methods of the AsleepConfig received from initAsleepConfig.
listener to receive the result. On success, the updated UserInfo is delivered
asleepConfig.fetchUserMetadata()
asleepConfig?.fetchUserMetadata(object : Asleep.FetchUserMetadataListener {
override fun onSuccess(metadata: UserMetadata?) {
// null if there is no saved information
}
override fun onFail(errorCode: Int, detail: String) { }
})
Parameter
Type
Description
listener
FetchUserMetadataListener
listener to receive the result. onSuccess(null) if there is no saved information
Listener
interface SaveUserMetadataListener {
fun onSuccess(userInfo: UserInfo)
fun onFail(errorCode: Int, detail: String)
}
interface FetchUserMetadataListener {
fun onSuccess(metadata: UserMetadata?)
fun onFail(errorCode: Int, detail: String)
}
UserMetadata
data class UserMetadata(
val birthYear: Int? = null,
val birthMonth: Int? = null,
val birthDay: Int? = null,
val gender: Gender? = null,
val height: Float? = null,
val weight: Float? = null
)
enum class Gender { MALE, FEMALE, NON_BINARY, OTHER, PREFER_NOT_TO_SAY }
Property
Type
Description
birthYear
Int?
Year of birth (1900~2100)
birthMonth
Int?
Month of birth (1~12)
birthDay
Int?
Day of birth (1~31)
gender
Gender?
Gender
height
Float?
Height in cm (1~500). Saved to one decimal place (the rest is truncated)
weight
Float?
Weight in kg (1~1000). Saved to one decimal place (the rest is truncated)
🚧
If you pass a value that is out of range, UserMetadata throws IllegalArgumentException at construction time. This is not a listener callback, so if you pass user input directly, validate it at the input stage or wrap it in try-catch.
Every property is optional. Properties that are null are not included in the request.
The combination of month and day (for example, February 31) is not validated.
UserInfo
Delivered when saveUserMetadata succeeds. The metadata field has been added since v3.3.0.
data class UserInfo(
val createdTimezone: String?,
val nickName: String?,
val toBeDeleted: Boolean?,
val userId: String?,
val metadata: UserMetadata? = null
)
Error Codes
Code
Name
Description
27000
ERR_SAVE_METADATA_FAILED
Failed to save (network · server error, userId not set, SDK not initialized)
27100
ERR_FETCH_METADATA_FAILED
Failed to fetch (network · server error, userId not set, SDK not initialized)
27400
ERR_SAVE_METADATA_VALIDATION
The server rejected the value (400). detail contains the reason