Prerequisites
In the dashboard:- Create a project (its
developmentandproductionenvironments are created for you). - Connect a provider credential (BYOK) for the models you’ll call. Chat needs a chat provider such
as OpenAI or Anthropic; images use
gpt-image-1, so an OpenAI key. See Providers & BYOK. - Create a publishable key (
rd_pk_…). It ships in the app and can only mint device tokens — it cannot call model endpoints. - For local development, create a secret key (
rd_sk_…) or pre-mint a client token to use as a static bearer while you build. - For production device auth, enable Play Integrity device attestation on the project. See Android device auth setup.
1. Install the SDK
Add the SDK to your app module’sbuild.gradle.kts. roadie-playintegrity brings roadie-core in
transitively, so a production app needs only the one dependency:
build.gradle.kts
minSdk is below 26, enable core library
desugaring — see Requirements.
2. Configure the client
ARoadie client needs a RoadieConfig (where the gateway lives) and a token provider (how each
request is authenticated). Swap the provider between local development and production without changing
any call site:
StaticTokenProvider— a fixed bearer (anrd_sk_…key or a pre-minted client token). The working dev path; inject it through aBuildConfigfield rather than a committed literal.PlayIntegrityTokenProvider— silently mints a per-device client token via Google Play Integrity, using the publishable key. The production path; it needs a real device with Google Play Services (Play Integrity is unavailable on bare emulators).
3. Chat and embeddings
Chat and embeddings are the simplest calls.chat.create sends your message and returns the
normalized response. The assistant’s reply is on response.text (a convenience over
response.message), alongside token usage, an estimated cost, and the gateway requestId. It is
a suspend function, so call it from a coroutine:
roadie.chat.stream(...) — a cold Flow<ChatStreamEvent> —
and append each ContentDelta.delta. Embed text with roadie.embeddings.create(...). See
Chat in the SDK reference.
4. Generate an image
images.generate creates an image from a prompt alone and returns the generated image’s raw PNG
bytes:
The image model defaults to
gpt-image-1 (set RoadieConfig.imageModel to change it), and n
defaults to 1. size is one of AUTO, SQUARE, LANDSCAPE, PORTRAIT; background is
TRANSPARENT, OPAQUE, or AUTO (when omitted, generate defaults to OPAQUE and edit to
TRANSPARENT); quality is LOW, MEDIUM, HIGH, or AUTO.5. Edit an image
images.edit takes the source PNG bytes and a prompt and returns the edited image’s raw PNG bytes.
mask is optional; when present, only the masked region is regenerated:
6. Handle errors
Every HTTP or decoding failure is thrown as aRoadieException; a cancelled coroutine surfaces
CancellationException. Branch on the sealed subclass:
401 (an expired client token) and retries transient network and 5xx
failures for you. A QuotaException is your cue to show the paywall — see
Free → Pro entitlements.
Next steps
Android SDK reference
The full chat, embeddings, image, and token-provider API.
Android device auth setup
Configure Google Play Integrity for production device auth.
Send a message
The end-to-end tutorial for a first chat call.
Mobile device auth
How anonymous device attestation mints client tokens with no account.