> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twexapi.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin SDK

> Use the TwexAPI Kotlin SDK for tweet search, follower exports, DMs, and X automation with coroutine-friendly calls.

Use the Kotlin SDK when you want idiomatic Kotlin builders, nullable types, and coroutine `await()` over the generated Java client for TwexAPI REST workflows.

| Kotlin task    | SDK call                         | Save         |
| -------------- | -------------------------------- | ------------ |
| Search tweets  | `sdk.search().advanced()`        | `nextCursor` |
| Read profile   | `sdk.users().getAbout()`         | `screenName` |
| List followers | `sdk.users().followers().list()` | cursor       |

<Note>
  Use this client for Kotlin coroutines and typed builders. Use the [Java SDK](/sdks/java) for Java-first codebases.
</Note>

## Install

Gradle:

```kotlin theme={null}
implementation("io.twexapi:x-api-scraper-kotlin:0.1.0")
```

Maven:

```xml theme={null}
<dependency>
    <groupId>io.twexapi</groupId>
    <artifactId>x-api-scraper-kotlin</artifactId>
    <version>0.1.0</version>
</dependency>
```

Maven Central may still be catching up. Install from source:

```bash theme={null}
./gradlew publishToMavenLocal
```

Source: [twexapi-dev/x-api-scraper-kotlin](https://github.com/twexapi-dev/x-api-scraper-kotlin)

## Authenticate

```bash theme={null}
export X_API_SCRAPER_KEY="YOUR_API_KEY"
```

```kotlin theme={null}
import io.twexapi.sdk.kotlin.xapiScraper
import io.twexapi.sdk.models.components.AdvancedSearchCursorQuery

fun main() {
    val sdk = xapiScraper()

    val req = AdvancedSearchCursorQuery.builder()
        .searchTerms(listOf("from:elonmusk"))
        .sortBy("Latest")
        .nextCursor("")
        .build()

    val res = sdk.search().advanced().request(req).call()
    println(res)
}
```

## Use coroutines

`async()` returns the Java `CompletableFuture` client. Call `await()` from a coroutine:

```kotlin theme={null}
import io.twexapi.sdk.kotlin.async
import io.twexapi.sdk.kotlin.await
import io.twexapi.sdk.kotlin.xapiScraper
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    val sdk = xapiScraper().async()

    val req = AdvancedSearchCursorQuery.builder()
        .searchTerms(listOf("from:elonmusk"))
        .sortBy("Latest")
        .nextCursor("")
        .build()

    val res = sdk.search().advanced().request(req).call().await()
    println(res)
}
```

## Workflow: post a tweet

Write actions need a Twitter cookie or `auth_token` on the request:

```kotlin theme={null}
sdk.tweets().actions().create()
    .request(
        CreateTweetRequest.builder()
            .tweetContent("Hello from the TwexAPI Kotlin SDK.")
            .cookie(System.getenv("TWITTER_COOKIE"))
            .build()
    )
    .call()
```

## References

* [SDKs overview](/sdks)
* [Java SDK](/sdks/java)
* [Authentication](/authentication)
* [Advanced Twitter Search](/api-reference/search-endpoints/advanced-twitter-search)
* [Source Repository](https://github.com/twexapi-dev/x-api-scraper-kotlin)
