Kotlin SDK
Esta página aún no está disponible en tu idioma.
The official Pipe2.ai Kotlin SDK is a set of small Android libraries for building native apps against the Pipe2.ai backend. pipe2-graphql gives you a typed client for every pipeline operation; pipe2-auth-email handles sign-up and sign-in. Everything is suspend-based and returns typed Kotlin values.
Source: github.com/pipe2-ai/sdk-kotlin
Installation
Artifacts are published to GitHub Packages, which needs a Personal Access Token with read:packages scope.
In ~/.gradle/gradle.properties (never commit this — it holds a secret):
gpr.user=your-github-usernamegpr.token=ghp_your_PAT_with_read_packages_scopeIn your project’s settings.gradle.kts:
dependencyResolutionManagement { repositories { google() mavenCentral() maven { url = uri("https://maven.pkg.github.com/pipe2-ai/sdk-kotlin") credentials { username = providers.gradleProperty("gpr.user").getOrElse(System.getenv("GITHUB_ACTOR") ?: "") password = providers.gradleProperty("gpr.token").getOrElse(System.getenv("GITHUB_TOKEN") ?: "") } } }}In your app module’s build.gradle.kts — add the modules you need at the current release:
dependencies { implementation("ai.pipe2:pipe2-graphql:2026.07.2") implementation("ai.pipe2:pipe2-auth-email:2026.07.2") implementation("ai.pipe2:pipe2-auth:2026.07.2") implementation("ai.pipe2:pipe2-analytics:2026.07.2") implementation("ai.pipe2:pipe2-media:2026.07.2") implementation("ai.pipe2:pipe2-crash:2026.07.2") implementation("ai.pipe2:pipe2-design-tokens:2026.07.2") // pipe2-errors is pulled in transitively}Quick start
import ai.pipe2.graphql.Pipe2GraphQLClientimport ai.pipe2.graphql.Pipe2GraphQLConfigimport ai.pipe2.auth.email.EmailAuthClientimport ai.pipe2.auth.email.EmailAuthConfigimport ai.pipe2.auth.email.EmailSessionTokenProvider
val endpoint = "https://api.pipe2.ai/v1/graphql"
// Holds the access token and feeds it to the GraphQL client.val session = EmailSessionTokenProvider()
val client = Pipe2GraphQLClient.live( config = Pipe2GraphQLConfig( endpoint = endpoint, websocketEndpoint = "wss://api.pipe2.ai/v1/graphql", ), authProvider = session,)
// Sign in, then hand the token to the client.val auth = EmailAuthClient(EmailAuthConfig(graphqlEndpoint = endpoint))val result = auth.login(email = "user@example.com", password = "securepassword")session.update(result)
// List pipelinesclient.listPipelines().forEach { println("${it.name} — ${it.slug}") }Authentication
EmailAuthClient mints a token; EmailSessionTokenProvider.update(...) installs it so every later Pipe2GraphQLClient call is authenticated. Calling session.clear() signs out (subsequent requests go out anonymously).
Sign up
val auth = EmailAuthClient(EmailAuthConfig(graphqlEndpoint = endpoint))
// 1. Register — the account needs email verification before it's activeauth.register(email = "user@example.com", password = "securepassword", name = "Jane Doe")
// 2. Verify with the 6-digit code from the inboxauth.initVerification(email = "user@example.com")val verified = auth.submitVerificationCode("123456")
// 3. Install the tokensession.update(verified)Sign in
val result = auth.login(email = "user@example.com", password = "securepassword")session.update(result) // returns false if the account still needs verificationPassword recovery
val flow = auth.initRecovery(email = "user@example.com") // sends a codeval reset = auth.submitRecovery(flow, newPassword = "a-new-password")session.update(reset)Available operations
Pipelines
import ai.pipe2.graphql.publictypes.PipelineInputimport ai.pipe2.graphql.adapters.JsonbValueimport kotlin.uuid.Uuid
// List / fetch oneval pipelines = client.listPipelines()val detail = client.pipeline("image-generator")
// Run a pipeline. `requestId` is your idempotency key for the trigger.val ref = client.triggerPipeline( slug = "image-generator", input = PipelineInput.fromFields( mapOf( "prompt" to JsonbValue.Str("A cinematic sunset over mountains, wide angle"), "aspect_ratio" to JsonbValue.Str("16:9"), ), ), requestId = Uuid.random(),)println("Run id: ${ref.id}")
// Run history (newest first, paginated)val page = client.listRuns(limit = 12, offset = 0)Watch a run
observeRun returns a Flow<RunSnapshot> backed by a GraphQL subscription over WebSocket. PipelineRunStatus is a sealed class — status.isTerminal is true once the run succeeds, fails, or is cancelled.
import kotlinx.coroutines.flow.takeWhile
client.observeRun(ref.id) .takeWhile { !it.status.isTerminal } .collect { println("Status: ${it.status.rawToken}") }
// Fetch the final snapshot with its outputsval finished = client.run(ref.id)finished.outputs.firstOrNull()?.let { println("Result: ${it.url}") }Assets
// 1. Request a presigned upload target and PUT the bytes to target.uploadUrlval target = client.requestUpload(filename = "photo.jpg", contentType = "image/jpeg")
// 2. Register the asset — use asset.id as an input to a pipeline runval asset = client.createAsset(key = target.key, tags = listOf("input"))
val assets = client.listAssets(limit = 20)client.deleteAsset(asset.id)Credits & account
val balance = client.creditBalance()val me = client.currentUser()Personal access tokens
val created = client.createPersonalAccessToken("My Integration")println(created.token) // shown only once — store it now
val keys = client.listApiKeys()client.revokePersonalAccessToken(created.id)