> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Porting between platforms

> What each language forces on the shared API.

The namespaces, option names, and event shapes are the same everywhere. What differs is what
each language forces on the API. These are those differences, so you can port code without
finding them one compile error at a time.

## Async and streaming

| SDK          | Async          | Streaming               |
| ------------ | -------------- | ----------------------- |
| Swift        | `async throws` | `AsyncThrowingStream`   |
| Kotlin       | `suspend`      | `Flow`                  |
| React Native | `Promise`      | `AsyncIterable`         |
| Flutter      | `Future`       | `Stream`                |
| Web          | `Promise`      | `AsyncIterable`         |
| Electron     | `Promise`      | `AsyncIterableIterator` |

## Prompts and conversations

| SDK          | Prompt              | Conversation                 |
| ------------ | ------------------- | ---------------------------- |
| Swift        | `generate(prompt:)` | `generate(messages:)`        |
| Kotlin       | `generate(prompt)`  | `generate(messages)`         |
| React Native | `generate(input)`   | same method, union input     |
| Web          | `generate(input)`   | same method, union input     |
| Electron     | `generate(input)`   | same method, union input     |
| Flutter      | `generate(prompt)`  | **`generateChat(messages)`** |

Flutter is the outlier, because Dart has no method overloading. It also has
`generateChatStream` alongside `generateStream`.

## Input constructors

| SDK          | Names                            | Platform-native path                           |
| ------------ | -------------------------------- | ---------------------------------------------- |
| Swift        | `AudioInput`, `ImageInput`       | `uiImage`, `nsImage`, `cgImage`, `pixelBuffer` |
| Kotlin       | `AudioInput`, `ImageInput`       | `bitmap`                                       |
| React Native | **`AudioInputs`, `ImageInputs`** | `file`, `base64`                               |
| Flutter      | `AudioInput`, `ImageInput`       | `bytes`, `rawRgb`                              |
| Web          | `AudioInput`, `ImageInput`       | `element` (async)                              |
| Electron     | `audio`, `image` on the facade   | file and bytes                                 |

React Native's are **plural**. Flutter has no `AudioInput.file` and no `ImageInput.rawRgba`.
Web has no `AudioInput.file`; use `AudioFileLoader` from `@runanywhere/web/browser`.

## Streaming push handles

`openStream` returns a handle you push frames into.

| SDK          | `stt.openStream` | `vad.openStream` |
| ------------ | ---------------- | ---------------- |
| Swift        | async            | **synchronous**  |
| Kotlin       | synchronous      | synchronous      |
| Flutter      | async            | **synchronous**  |
| Web          | async            | async            |
| Electron     | async            | async            |
| React Native | **absent**       | **absent**       |

React Native has only the pull-shaped `transcribeStream` and `detectStream`.

## Where streaming errors surface

| SDK                                  | In-flight failure             |
| ------------------------------------ | ----------------------------- |
| Swift, Kotlin, Flutter, React Native | Thrown into the consumer      |
| Web, Electron                        | Delivered as a `failed` event |

Preflight failures throw from the call on every SDK. Do not share one error-handling helper
across the two groups without checking.

## Everything else

| Thing                      | Where it differs                                                                                                          |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `deviceId`                 | String on Swift, Kotlin, Web. `Promise` on React Native. **Throws** before init on Flutter. Empty until init on Electron. |
| `capabilities()`           | Live probe on Swift, Web, Electron. **Static literal** on React Native.                                                   |
| `models.list/get/register` | **Synchronous** on Web, async everywhere else.                                                                            |
| `models.get`               | Absent on React Native; use `models.loaded(category)`.                                                                    |
| `models.isResumable`       | Swift and Electron only.                                                                                                  |
| Download pause and resume  | Electron only.                                                                                                            |
| `vad.reset()`              | Swift and Electron only.                                                                                                  |
| `tts.speak`                | Synchronous on React Native and Flutter, async elsewhere.                                                                 |
| `tts.stop`                 | Synchronous on Web, async elsewhere.                                                                                      |
| `llm.tools.*`              | Synchronous on Web and Flutter, async on Kotlin and React Native.                                                         |
| `llm.tools.clear()`        | Swift and React Native only.                                                                                              |
| RAG sessions               | Single-session on Web, React Native, and Flutter.                                                                         |
| RAG `ingest` a list        | `ingestAll` on Flutter, an `ingest` overload elsewhere.                                                                   |
| Structured output schema   | A **`String`** on Flutter, an object elsewhere.                                                                           |
| Kotlin namespaces          | Extension properties. Need `import com.runanywhere.sdk.public.api.*`.                                                     |

## Structured output

Every SDK exposes three enforcement modes and only two of them work:

| Mode            | Behaviour                                                                   |
| --------------- | --------------------------------------------------------------------------- |
| Validation only | Generate freely, then validate. The default.                                |
| Repair          | Validate, then retry once with a repair instruction.                        |
| Constrained     | **Throws on every SDK.** Engine-level constrained decoding is not wired in. |
