# Kotlin

The Kotlin SDK targets the `antd` daemon over REST or gRPC.

## Install

```kotlin
dependencies {
    implementation("com.autonomi:antd-kotlin:0.1.0")
}
```

Until the package is published, use the project as a local dependency or composite build.

## Connect to the daemon

```kotlin
import com.autonomi.sdk.*
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    val client = AntdClient.createRest("http://localhost:8082")
    val status = client.health()
    println(status.network)
    client.close()
}
```

## Store and retrieve data

```kotlin
import com.autonomi.sdk.*
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    val client = AntdClient.createRest()
    val result = client.dataPutPublic("Hello, Autonomi!".toByteArray())
    println(result.address)

    val data = client.dataGetPublic(result.address)
    println(String(data))
    client.close()
}
```

## Type mappings

| Autonomi type  | Kotlin type       |
| -------------- | ----------------- |
| `HealthStatus` | Kotlin data class |
| `PutResult`    | Kotlin data class |
| Raw data       | `ByteArray`       |

## Error handling

```kotlin
try {
    val data = client.dataGetPublic("nonexistent")
} catch (e: NotFoundException) {
    println("Not found")
} catch (e: PaymentException) {
    println("Payment required")
} catch (e: AntdException) {
    println(e.message)
}
```

## Full API reference

For all available daemon endpoints, see the [REST API](/developers/sdk/install/reference/rest-api.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.autonomi.com/developers/sdk/install/reference/language-bindings/kotlin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
