Documentation
Documentation · React Native

All SDKs React Native

Gate/AI for React Native

Add device authentication and authenticated AI requests to your React Native app, using the native Gate/AI SDKs on iOS and Android.

iOS + Android

@gateai/react-native

Install the SDK

React Native 0.81 is the development baseline. The SDK is distributed from its public GitHub repository and pinned to a release tag; it is not on the npm registry. Install pods and rebuild the native app after adding the SDK. Expo requires a custom development build; Expo Go cannot load this native module.

From your app directory:

npm install github:GateAI-net/gate-react-native#1.0.0
cd ios && pod install

npm builds the package from source on install, so Node 22 or later is required on the machine running npm install. Releases are listed at github.com/GateAI-net/gate-react-native/releases.

Configure a client

Replace the tenant URL, Apple Team ID, and Android signing fingerprint with your registered values. Supply both platform configurations for a shared app. The Google Cloud project number is a decimal string.

import { GateAIClient, GateAIError } from '@gateai/react-native';

const client = await GateAIClient.create({
  baseUrl: 'https://your-team.in.gate-ai.net',
  ios: { teamIdentifier: 'ABCDE12345' },
  android: {
    signingCertSha256: 'YOUR_64_HEX_CHARACTER_SHA256_FINGERPRINT',
    cloudProjectNumber: '123456789012',
  },
});

iOS detects the bundle identifier automatically; Android uses the host app’s package name. On Android, deviceIdentifierEnabled is false by default. Use the native setup checklist below for attestation and development tokens.

Make your first request

Choose a model enabled for your gate and send a JSON request. The SDK adds authentication and signs the request on-device.

try {
  const response = await client.request({
    path: 'openai/chat/completions',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      model: 'your-enabled-model',
      messages: [{ role: 'user', content: 'Hello from Gate/AI' }],
    }),
    context: { userTier: 'pro', appFeature: 'chat' },
  });
  const completion = JSON.parse(response.body);
  // Use completion in your app.
} catch (error) {
  if (error instanceof GateAIError && error.status === 429) {
    const retryAfter = error.header('Retry-After');
    // Show a usage-limit message or schedule a retry.
  }
  throw error;
}

// When the owning service is permanently torn down:
await client.dispose();

For GET requests, set method to 'GET' and omit the body. Reuse the client across requests.

Prepare your native app

Every SDK needs the same platform registration. Create a gate in the portal, add your provider credentials there, and register the app identifiers you ship.

iOS · App Attest

  • Target iOS 16 or later and use Xcode 16 or later.
  • Register your bundle identifier and Apple Team ID in Gate/AI.
  • Enable App Attest for the app and configure its entitlement.
  • On the simulator, set GATE_AI_DEV_TOKEN in Xcode’s Edit Scheme (⌘⇧,) → Run → Arguments → Environment Variables. Physical devices use App Attest. Step-by-step simulator token setup →

iOS setup details →

Android · Play Integrity

  • Target Android API 24 or later.
  • Register your package name and signing certificate SHA-256 in Gate/AI.
  • Link Play Integrity to a Google Cloud project and provide its project number.
  • For Android emulator testing, use a development token. Set GATE_AI_DEV_TOKEN in the build environment or an ignored local properties file, add the Gradle configuration below, then rebuild and reinstall the debug app. The SDK reads the token automatically. Android development token setup →

Android setup details →

Set up a development token for the Android emulator

Use a development token when testing in an Android emulator. This applies to native Android, React Native, Capacitor, and Flutter apps. The development token lets your emulator app authenticate with Gate/AI without using Google Play Integrity.

Follow the steps below, then rebuild and reinstall your debug app. The SDK discovers the token automatically, so initialize your client normally without passing the token in Kotlin, JavaScript, or Dart. Requires Android SDK 1.2.0+; included in the React Native, Capacitor, and Flutter SDKs.

  1. Create a development token for your gate in the Gate/AI portal.
  2. Set GATE_AI_DEV_TOKEN in the Gradle build environment, or create gateai.local.properties beside the host app’s settings.gradle or settings.gradle.kts. For framework apps this is usually the android/ directory.
  3. Add gateai.local.properties to your .gitignore. In the local file, set GATE_AI_DEV_TOKEN=your-token without quotes. An environment variable takes precedence, including an explicitly empty value.
  4. Add the matching snippet below to the host app module’s build file. Put Kotlin imports at the top of the file and the configuration after plugins. Merge the android / buildTypes blocks with your existing configuration. Keep the resource in the debug build type.
  5. Sync Gradle, then rebuild and reinstall the debug app. Repeat this after changing the token.

Kotlin DSL · app/build.gradle.kts

// app/build.gradle.kts — put this import at the top of the file
import java.util.Properties

// Place the following after your existing plugins { ... } block.
val gateAILocalProperties = Properties().apply {
    val localFile = rootProject.file("gateai.local.properties")
    if (localFile.exists()) localFile.inputStream().use { load(it) }
}
val gateAIDevToken = providers.environmentVariable("GATE_AI_DEV_TOKEN")
    .orElse(gateAILocalProperties.getProperty("GATE_AI_DEV_TOKEN", ""))

android {
    buildTypes {
        getByName("debug") {
            resValue("string", "gate_ai_dev_token", gateAIDevToken.get())
        }
    }
}

Groovy · app/build.gradle

// app/build.gradle — place after plugins { ... }
def gateAILocalProperties = new Properties()
def gateAILocalFile = rootProject.file("gateai.local.properties")
if (gateAILocalFile.exists()) {
    gateAILocalFile.withInputStream { gateAILocalProperties.load(it) }
}
def gateAIDevToken = providers.environmentVariable("GATE_AI_DEV_TOKEN")
    .orElse(gateAILocalProperties.getProperty("GATE_AI_DEV_TOKEN", ""))

android {
    buildTypes {
        debug {
            resValue "string", "gate_ai_dev_token", gateAIDevToken.get()
        }
    }
}

Android Studio must inherit the environment variable when it starts; the ignored local file is convenient when launching the IDE from the Dock or launcher. These are build-time values, unlike iOS’s Xcode launch environment.

The SDK reads gate_ai_dev_token only in debuggable apps. If no token is configured, the SDK asks Google Play Integrity to verify the app and device instead. Explicit developmentToken configuration remains compatible and takes precedence in debug apps.

The token is present in the debug APK. Keep this resource out of defaultConfig and release build types so release APKs/AABs exclude it. The SDK also ignores all development tokens in non-debuggable apps.

Supported APIs & behavior

request
Send GET or POST requests with UTF-8 text or JSON bodies. Responses are buffered and include status, headers, and body. Authentication, token refresh, and one retry on a DPoP nonce challenge are handled for you.
authorizationHeaders
Generate headers for your own HTTP client using a relative path, method, and optional nonce. Send to the exact configured origin and path. Custom transports must handle a 401 DPoP-Nonce challenge and obtain a fresh proof for the retry; never cache or reuse proofs.
Per-request context
Set userStatus, userTier, userIdentifier, appFeature, and quotaAnchorDay (1–31). Use an opaque user ID. Explicit headers override context values; authentication headers cannot be overridden. Analytics reference →
clearCachedState & dispose
Clear the cached access token to authenticate again, or dispose of a client you no longer need. Neither operation deletes device keys. Requests already in flight can finish after disposal.
Current limits
Use an HTTPS origin and relative request paths. Query strings, fragments, percent escapes, and dot segments are not supported. The request API does not support binary payloads, streamed responses, or cancellation. These SDKs target native iOS and Android only.

Handle errors and usage limits

Non-2xx responses throw GateAIError with the HTTP status, response headers, and body. Inspect status for HTTP decisions; network and attestation errors may use different native codes. Quota and retry headers are preserved on responses and errors.

Configure rate limits and device budgets →