One request, chosen execution
The router decides where a prompt runs. It weighs the caller's policy, what the browser can actually do, the plan's entitlements, the context budget and recent failures — and records the reason it chose.
Policies the router accepts
A policy is a preference. The decision is always derived, never assumed from the name of the mode.
| Policy | Intent |
|---|---|
| local-only | Route to the device or refuse. Never silently egress to cloud. |
| cloud-only | Route to Firebase AI Logic or fail with the entitlement or capability error. |
| prefer-local | Use the device when capable; fall back to cloud with prefer_local_fallback_cloud. |
| prefer-cloud | Use the cloud when available; fall back to local when it is the only option. |
| auto | Derive the target from capability, entitlement, context budget and failure history. |
| privacy-restricted | Treat configured privacy constraints as a hard filter on egress. |
| org-controlled | Defer to the organisation's policy; the decision still carries its own reason code. |
The two backends
Neither is simulated. Each reports its own state, including the state where it cannot serve.
- On-device model
- The browser adapter probes the built-in Prompt API (LanguageModel availability) and reports available, downloadable, downloading or unavailable with a reason. Without it, local generation is not offered.
- Cloud model
- Firebase AI Logic provides Gemini inference. The model id is deployment configuration (NEXT_PUBLIC_FIREBASE_AI_MODEL), not a constant in the UI.
A cloud call is preceded by beginInferenceExecution, which takes a token reservation inside a Firestore transaction and re-checks the entitlement for the requested mode. The client chooses an execution id, so a retry while the execution is still running returns alreadyStarted instead of reserving twice.
What the execution record answers
One row per inference, written by completeInferenceExecution. If a field has no value, it is null — never a placeholder.
| Field | Meaning |
|---|---|
| requestedMode | What the caller asked for: local, cloud or hybrid. |
| resolvedSource | Where the request actually ran. |
| status | The terminal state of the execution. |
| model | The model id the backend served, or none for local refusal. |
| latencyMs | Measured duration of the call. |
| tokenUsage | Token counts reported by the backend. |
| errorCode | A taxonomy code when the execution failed, otherwise null. |
See the router answer
Open the workspace and run an inference. When cloud inference is not configured, the execution fails with MODEL_UNAVAILABLE and says why.