Saltearse al contenido

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-username
gpr.token=ghp_your_PAT_with_read_packages_scope

In 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:

2026.07.2
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.Pipe2GraphQLClient
import ai.pipe2.graphql.Pipe2GraphQLConfig
import ai.pipe2.auth.email.EmailAuthClient
import ai.pipe2.auth.email.EmailAuthConfig
import 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 pipelines
client.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 active
auth.register(email = "user@example.com", password = "securepassword", name = "Jane Doe")
// 2. Verify with the 6-digit code from the inbox
auth.initVerification(email = "user@example.com")
val verified = auth.submitVerificationCode("123456")
// 3. Install the token
session.update(verified)

Sign in

val result = auth.login(email = "user@example.com", password = "securepassword")
session.update(result) // returns false if the account still needs verification

Password recovery

val flow = auth.initRecovery(email = "user@example.com") // sends a code
val reset = auth.submitRecovery(flow, newPassword = "a-new-password")
session.update(reset)

Available operations

Pipelines

import ai.pipe2.graphql.publictypes.PipelineInput
import ai.pipe2.graphql.adapters.JsonbValue
import kotlin.uuid.Uuid
// List / fetch one
val 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 outputs
val 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.uploadUrl
val target = client.requestUpload(filename = "photo.jpg", contentType = "image/jpeg")
// 2. Register the asset — use asset.id as an input to a pipeline run
val 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)