Menu

Coroutines first: notes on nRouter's Kotlin SDK
πŸ“°

Coroutines first: notes on nRouter's Kotlin SDK

DEV Community: kotlinΒ·nRouterΒ·4 days ago
#30Ekm6Dw
#devtokotlin#devto#dev#nrouter#kotlin
Long article (487 words) β€” no AI summary yet.
Reading 0:00
15s threshold

A Kotlin client for an API gateway can be a thin wrapper around blocking HTTP calls, with a coroutine adapter bolted on. The nRouter Kotlin guide goes the other way: the SDK is coroutines-first from the start β€” suspend functions for calls, a cold Flow for streaming, and typed error subclasses you can branch on.

Full guide: https://nrouter.ai/docs/sdks/kotlin

Setup

The guide publishes the artifact to your local Maven cache ( ./gradlew clean check publishToMavenLocal ), then it's a normal Gradle dependency:

dependencies { implementation ( "ai.nrouter:nrouter-sdk-kotlin:3.1.2" ) }

Enter fullscreen mode

Exit fullscreen mode

NRouter() reads NROUTER_API_KEY from the environment, targets https://api.nrouter.ai/v1 , and dispatches on Dispatchers.IO , so calls don't block your caller's context. (For Android apps, the guide points to the separate nrouter-sdk-android artifact.)

A call, and what comes back

suspend fun main ( ) { val client = NRouter ( )

val result = client . chatCompletions ( JSONObject ( ) .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.