# On-Device vs Cloud AI on iPhone: How to Set Up Hybrid LLM Routing

> AI Release · @ai_release1 · https://ai-release.org/guides/lokalnaya-model-ili-oblako-na-iphone-kak-nastroit-gibri_en.html

This guide shows you how to set up hybrid AI routing on an iPhone: short or private prompts stay on a local model, while heavy or complex requests go to a cloud API. It is for iPhone users who already have a local AI app and a cloud provider account, and who want to avoid sending every request to the cloud. The steps use Apple Shortcuts, a built-in automation app, so you do not need to write a full iOS app. If you only want to test local models first, read [How to run AI models locally on your PC: a beginner's guide](https://ai-release.org/guides/kak-zapustit-ii-model-lokalno-na-svoem-kompyutere-gayd.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide). For Android, see [How to Run an AI Model Locally on Android: Apps and Setup](https://ai-release.org/guides/kak-zapustit-ii-model-lokalno-na-android-prilozheniya-i.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide).

## Requirements and preparation

- iPhone with iOS 17 or later. Shortcuts comes preinstalled. Check Settings > General > About > Software Version.
- A local AI app that runs a model on your iPhone or exposes a local HTTP endpoint. "Local HTTP endpoint" means a URL on your phone that accepts requests, like `http://127.0.0.1:8080/v1/chat/completions`. The exact port depends on your app.
- A cloud AI provider account and API key. API key is a secret string, often starting with `sk-`, that identifies your account.
- Internet access for cloud requests. Local requests can work offline if the model is already downloaded.
- A clear routing rule. Example: requests shorter than 200 characters go local; requests containing "private" or "confidential" go local; all other requests go cloud.
- Optional: a model comparison source. Use [How to Use LMArena (arena.ai): Read the Leaderboard and Choose the Best Model for Your Task](https://ai-release.org/guides/kak-polzovatsya-lmarena-arena-ai-chitaem-reyting-i-vybi.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide) to pick a cloud model before you add its name to the shortcut.
- Checklist before you start:
  - [ ] Shortcuts app opens.
  - [ ] Local app responds in Safari at your local URL.
  - [ ] Cloud API key works in a desktop test (curl or provider console).
  - [ ] You know the exact JSON field names your providers expect.

## Step-by-step instructions

1. Open Shortcuts and create a new shortcut. Tap +, then name it "Hybrid AI Router". Expected result: an empty shortcut canvas. Shortcuts is Apple's automation app; it chains actions together.

2. Add a "Text" action. Type a sample prompt, for example: "Summarize this note in three bullets: The meeting moved to Friday." Expected result: the Text action holds your prompt. You will replace this with Shortcut Input later if you use Siri or the Share Sheet.

3. Add an "If" action to check the prompt. First add "Get Length of Text" and set its input to the Text action. Then add "If" > "Length" > "is less than" > 200. Expected result: the shortcut has two branches: short prompts and long prompts. Why: short prompts are usually cheap and fast enough for a local model.

**Example:** If the prompt is "What is 2+2?", the length is 8, so the local branch runs. If the prompt is a 500-word essay request, the cloud branch runs.

4. Build the local branch. Inside the "If" branch, add "Get Contents of URL". Set URL to your local endpoint, for example `http://127.0.0.1:8080/v1/chat/completions`. Set Method to POST. Add header `Content-Type: application/json`. Expected result: Shortcuts will send an HTTP POST request to your local app. Why: most local runtimes speak the same OpenAI-compatible chat format.

Use this JSON body as a template:

```json
{
  "model": "your-local-model",
  "messages": [
    {"role": "user", "content": "What is 2+2?"}
  ],
  "temperature": 0.7
}
```

Replace "your-local-model" with the model name your app reports. If your app does not require a model name, remove that line. Expected result: the local app returns a JSON response.

5. Build the cloud branch. In the "Otherwise" branch, add another "Get Contents of URL". Set URL to your cloud endpoint, for example `https://api.example.com/v1/chat
