This page describes the following configuration options for hybrid experiences:

- [Set an inference mode.](https://firebase.google.com/docs/ai-logic/hybrid/web/configuration-options.md.txt#inference-modes)

- [Determine whether on-device or in-cloud inference was used.](https://firebase.google.com/docs/ai-logic/hybrid/web/configuration-options.md.txt#determine-inference-mode)

- [Override the default cloud-hosted fallback model.](https://firebase.google.com/docs/ai-logic/hybrid/web/configuration-options.md.txt#override-default-cloud-model)

- [Use model configuration to control responses.](https://firebase.google.com/docs/ai-logic/hybrid/web/configuration-options.md.txt#model-config)

You can also
[generate structured output (like JSON and enums)](https://firebase.google.com/docs/ai-logic/hybrid/web/generate-structured-output.md.txt).

**Make sure that you've completed the
[getting started guide for building hybrid experiences](https://firebase.google.com/docs/ai-logic/hybrid/web/get-started.md.txt#get-started).**

## Set an inference mode

The examples in the getting started guide show how to implement attempting
on-device inference first, and then falling back to the cloud-hosted model
(the `PREFER_ON_DEVICE` mode). However, this is only one of the available
[inference modes](https://firebase.google.com/docs/reference/js/ai.hybridparams.md.txt#hybridparamsmode).

> [!NOTE]
> **Note** : Keep the following in mind:
>
> - Before implementing hybrid or on-device inference, make sure to review the [list of not-yet-supported features](https://firebase.google.com/docs/ai-logic/hybrid/web/get-started.md.txt#features-not-yet-supported).
> - The default cloud-hosted model is `gemini-3.5-flash-lite`, but you can [override the default](https://firebase.google.com/docs/ai-logic/hybrid/web/configuration-options.md.txt#override-default-cloud-model).
> - As part of the response, the SDK tells you [whether on-device or in-cloud inference was used](https://firebase.google.com/docs/ai-logic/hybrid/web/configuration-options.md.txt#determine-inference-mode).

- **`PREFER_ON_DEVICE`** : Use the on-device model if it's available;
  otherwise, *fall back to the cloud-hosted model*.

  ```javascript
  const model = getGenerativeModel(ai, { mode: InferenceMode.PREFER_ON_DEVICE });
  ```
- **`ONLY_ON_DEVICE`** : Use the on-device model if it's available;
  otherwise, *throw an exception*.

  ```javascript
  const model = getGenerativeModel(ai, { mode: InferenceMode.ONLY_ON_DEVICE });
  ```
- **`PREFER_IN_CLOUD`** : Use the cloud-hosted model if it's available;
  otherwise, *fall back to the on-device model*.

  ```javascript
  const model = getGenerativeModel(ai, { mode: InferenceMode.PREFER_IN_CLOUD });
  ```
- **`ONLY_IN_CLOUD`** : Use the cloud-hosted model if it's available;
  otherwise, *throw an exception*.

  ```javascript
  const model = getGenerativeModel(ai, { mode: InferenceMode.ONLY_IN_CLOUD });
  ```

> [!NOTE]
> **Note:** **Downloading the on-device model can take several minutes.**   
> If you haven't yet [downloaded the model before your first request for on-device inference](https://firebase.google.com/docs/ai-logic/hybrid/web/get-started.md.txt#instructions-to-download-on-device-model), the request will automatically start the model download in the background (which can significantly delay receiving a response to that request).

## Determine whether on-device or in-cloud inference was used

If you use `PREFER_ON_DEVICE` or `PREFER_IN_CLOUD` inference modes, then it
might be helpful to know which mode was used for given requests. This
information is provided by the `inferenceSource` property of each response
(available starting with JS SDK v12.5.0).

When you access this property, the returned value will be either
`ON_DEVICE` or `IN_CLOUD`.

```javascript
// ...

console.log('You used: ' + result.response.inferenceSource);

console.log(result.response.text());
```

## Override the default fallback model

**The default cloud-hosted model is
`gemini-3.5-flash-lite`**
(starting with JS SDK v13.0.0).

This model is the fallback cloud-hosted model when you use the
`PREFER_ON_DEVICE` mode. It's also the default model when you use the
`ONLY_IN_CLOUD` mode or the `PREFER_IN_CLOUD` mode.

You can use the
[`inCloudParams`](https://firebase.google.com/docs/reference/js/ai.hybridparams.md.txt#hybridparamsincloudparams)
configuration option to specify an alternative default cloud-hosted model.

```javascript
const model = getGenerativeModel(ai, {
  mode: InferenceMode.INFERENCE_MODE,
  inCloudParams: {
    model: "GEMINI_MODEL_NAME"
  }
});
```

Find model names for all
[supported Gemini models](https://firebase.google.com/docs/ai-logic/models.md.txt).

## Use model configuration to control responses

In each request to a model, you can send along a model configuration to control
how the model generates a response. Cloud-hosted models and on-device models
offer different configuration options.

The configuration is maintained for the lifetime of the instance. If you want to
use a different config, create a new `GenerativeModel` instance with that
config.

> [!NOTE]
> **Note:** You can [generate structured output (like JSON and enums)](https://firebase.google.com/docs/ai-logic/hybrid/web/generate-structured-output.md.txt) by configuring the model to respond with structured output.

### Configure cloud-hosted model

Use the
[`inCloudParams`](https://firebase.google.com/docs/reference/js/ai.hybridparams.md.txt#hybridparamsincloudparams)
option to configure a cloud-hosted Gemini model. Learn about
[available parameters](https://firebase.google.com/docs/ai-logic/model-parameters.md.txt#parameters-descriptions-gemini).

```javascript
const model = getGenerativeModel(ai, {
  mode: InferenceMode.INFERENCE_MODE,
  inCloudParams: {
    model: "GEMINI_MODEL_NAME",
    generationConfig: {
      maxOutputTokens: 200,
      stopSequences: ["red"]
    }
  }
});
```

### Configure on-device model

Note that inference using an on-device model uses the
[Prompt API from Chrome](https://developer.chrome.com/docs/extensions/ai/prompt-api).

Use the
[`onDeviceParams`](https://firebase.google.com/docs/reference/js/ai.hybridparams.md.txt#hybridparamsondeviceparams)
option to configure an on-device model. Learn about
[available parameters](https://github.com/webmachinelearning/prompt-api?tab=readme-ov-file#configuration-of-per-session-parameters).

```javascript
const model = getGenerativeModel(ai, {
  mode: InferenceMode.INFERENCE_MODE,
  onDeviceParams: {
    createOptions: {
      expectedInputs: [{ type: "text", languages: ["en"] }],
      expectedOutputs: [{ type: "text", languages: ["en"] }],
      initialPrompts: [
        { role: "system", content: [{ type: "text", value: "You are a helpful and concise assistant." }] }
      ]
    }
  }
});
```

<br />

[Give feedback
about your experience with Firebase AI Logic](https://firebase.google.com/docs/ai-logic/feedback)

<br />