DEV Community

AI Release
AI Release

Posted on Originally published at ai-release.org

Hybrid LLM routing on iPhone: local models plus cloud APIs with Shortcuts

Most of the prompts I type on my phone are trivial — a quick rewrite, a two-line summary, a "what does this mean" question. Sending all of those to a paid cloud endpoint felt wasteful, and some of them contained things I would rather not upload at all. So I built a small router in Apple Shortcuts that keeps the light and sensitive requests on a local model and only sends the heavy lifting to a cloud API.

No Xcode, no full iOS app. Just Shortcuts, an HTTP request, and one length check.

What this setup actually does

The idea is simple: one shortcut, two branches.

  • Short or sensitive prompts go to a local model running on the iPhone itself.
  • Long, complex, or "I need the good model" prompts go to a cloud provider.

Everything happens inside Shortcuts, Apple's built-in automation app, which chains actions into a single runnable script. You can trigger it from the app, from Siri, or from the Share Sheet.

Prerequisites and a pre-flight checklist

Before touching Shortcuts, make sure the pieces talk to each other:

  • iPhone with iOS 17 or later. Shortcuts ships with the system. Verify under Settings → General → About → Software Version.
  • A local AI app that runs a model on the device or exposes a local HTTP endpoint — meaning a URL on your phone that accepts requests, such as http://127.0.0.1:8080/v1/chat/completions. The port depends on your app.
  • A cloud provider account and API key. The key is the secret string (often starting with sk-) that identifies your account.
  • Internet access for the cloud branch. The local branch can work offline once the model is downloaded.
  • A routing rule you can state in one sentence.

My checklist before I started:

  • [ ] Shortcuts opens and I can create a new shortcut.
  • [ ] My local app answers in Safari at the local URL.
  • [ ] My cloud API key works when tested from a desktop (curl or the provider console).
  • [ ] I know the exact JSON field names each provider expects.

That last item matters more than it sounds. Two "OpenAI-compatible" endpoints can still disagree on field names, and you will only find out at runtime.

Step 1: Choose the routing rule first

Write the rule down before you build anything. Mine looked like this:

  • Prompts shorter than 200 characters → local.
  • Prompts containing "private" or "confidential" → local, no exceptions.
  • Everything else → cloud.

The 200-character threshold is a heuristic, not science. Short prompts are usually cheap and fast enough for a small on-device model. If yours handles more, raise the number.

Step 2: Create the shortcut and the length check

  1. Open Shortcuts, tap +, and name it Hybrid AI Router. You get an empty canvas.
  2. Add a Text action and put a sample prompt in it, for example: Summarize this note in three bullets: The meeting moved to Friday. Later you can swap this for Shortcut Input when you run it from Siri or the Share Sheet.
  3. Add Get Length of Text and point it at the Text action.
  4. Add an If action: Length → is less than → 200.

You now have two branches. A prompt like What is 2+2? is 8 characters, so it falls into the local branch. A request for a 500-word essay lands in the cloud branch. That is the whole routing logic — everything else is plumbing.

Step 3: Build the local branch

Inside the If branch:

  1. Add Get Contents of URL.
  2. Set the URL to your local endpoint, e.g. http://127.0.0.1:8080/v1/chat/completions.
  3. Set Method to POST.
  4. Add the header Content-Type: application/json.

Then add a Request Body in JSON. This template works for most local runtimes, since they tend to speak the OpenAI-compatible chat format:

{
  "model": "your-local-model",
  "messages": [
    {"role": "user", "content": "What is 2+2?"}
  ],
  "temperature": 0.7
}
Enter fullscreen mode Exit fullscreen mode

Replace your-local-model with the model name your app reports. If your app ignores the model field, delete that line entirely. A correct run ends with your local app returning a JSON response that the shortcut can read.

Step 4: Build the cloud branch

In the Otherwise branch, add a second Get Contents of URL:

  1. URL: your provider's chat completion endpoint, e.g. https://api.example.com/v1/chat/completions.
  2. Method: POST, header Content-Type: application/json.
  3. Body: the same JSON shape, but with your cloud model name in the model field and the actual prompt in content.
  4. Authentication: add the header exactly as your provider's docs describe it. The key usually goes into a request header, but the header name differs between vendors — check the docs rather than guessing.

One practical note: keeping the API key inside a shortcut is convenient but not a vault. Anyone with access to your unlocked phone can open the shortcut and read it. Treat a shortcut key as a low-limit throwaway credential, and rotate it if the phone is shared.

Step 5: Test both branches on purpose

Do not trust a single happy-path run. I tested by editing the Text action:

  • A 5-character prompt to confirm the local branch fires.
  • A 400-character prompt to confirm the cloud branch fires.
  • A short prompt containing the word "confidential" to confirm the keyword rule overrides the length rule.

If the local branch fails, open the local URL in Safari first — if Safari cannot reach it, Shortcuts will not either. If the cloud branch fails, re-test the key from a desktop curl call to separate an auth problem from a shortcut problem.

Two things I would change next time: switching the Text action to Shortcut Input so the router works from Siri and the Share Sheet, and adding a fallback so a failed cloud call retries locally instead of just erroring out.

Takeaway

You do not need a custom app to get hybrid AI on an iPhone. A length check and two HTTP actions in Shortcuts are enough to keep cheap, private prompts on-device and spend cloud tokens only where they buy you something. Start with a crude rule like 200 characters, run both branches deliberately, and tune the threshold based on what your local model actually handles well. If you are still choosing which local model to run, AI Release also has beginner guides for running models locally on a PC and on Android — worth a read before you hardcode a gateway.

This article was originally published on AI Release — https://ai-release.org

More practical AI guides and breakdowns: https://t.me/ai_release1

Top comments (0)