App Integration

Connect your iOS app to the Ridex gateway in minutes.

App status

Loading…

Swift SDK

GetRidex / ridex-swift-sdk

Open source Swift SDK · iOS 16+ · macOS 13+

1

Install via Swift Package Manager

  • In Xcode, go to File → Add Package Dependencies
  • Enter the repository URL:
    https://github.com/GetRidex/ridex-swift-sdk
  • Select RidexSwiftSDK and add it to your app target
  • Requires iOS 16+ · macOS 13+ · Swift 5.9+ · Xcode 15+
2

Configure once at launch

Import the SDK and call Ridex.configure(_:) in your app's entry point before any requests are made. Use your production gateway key for this environment.

Swift
import SwiftUI
import RidexSwiftSDK

@main
struct MyApp: App {

    init() {
        Ridex.configure("rdx_live_••••••••••••••")
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

The environment is inferred automatically — rdx_live_… maps to production, rdx_test_… maps to development.

Never ship a rdx_test_ key in a production build. Production keys are protected by App Attest, which verifies every request comes from a real device. Development keys skip this for simulator testing — they have no device-level protection.

3

Send your first prompt

Call Ridex.prompt(_:) from anywhere in your app — a SwiftUI view, a ViewModel, or a service.

Swift
let reply = try await Ridex.prompt("Summarise this in one sentence.")

The gateway applies your routing strategy and usage analytics automatically on every call — no extra configuration needed.

4

Tag requests for analytics

Pass featureTag to group requests by product feature in the Ridex dashboard, and userTag to track per-user spend. Both are optional — use an opaque ID for userTag.

Swift
let reply = try await Ridex.prompt(
    userInput,
    featureTag: "document-summary", // groups by feature in analytics
    userTag: currentUser.id         // per-user spend tracking
)
5

Add a system prompt

Use the context parameter to set a persona, restrict the topic, or provide background knowledge. It is prepended to every conversation as a system message.

Swift
let reply = try await Ridex.prompt(
    "Review this function for memory safety issues.",
    context: "You are a senior Swift engineer doing a security-focused code review."
)
6

Handle errors

All errors thrown by prompt() are RidexNetworkError values. The ones most relevant to setup:

  • .unauthorizedInvalid or expired gateway key.
  • .bundleIdMismatchApp bundle ID not allowed for this key — check your key settings.
  • .serverErrorGateway returned an error — statusCode and message included.
  • .timedOutRequest timed out.
  • .cancelledEnclosing Task was cancelled — no action needed.
  • .networkErrorUnderlying URLSession error — check underlyingError.
Swift
do {
    let reply = try await Ridex.prompt("Hello!")
    print(reply)
} catch let error as RidexNetworkError {
    switch error {
    case .unauthorized:
        print("Check your gateway key")
    case .bundleIdMismatch:
        print("Bundle ID not allowed — update key settings")
    case .serverError(let statusCode, let message):
        print("Gateway error \(statusCode): \(message ?? "")")
    case .timedOut:
        print("Request timed out — try again")
    case .networkError(let underlying):
        print("Network issue: \(underlying.localizedDescription)")
    default:
        print(error.localizedDescription)
    }
}