# Google (https://www.librechat.ai/docs/configuration/pre_configured_ai/google)

For the Google endpoint, you can use either the **Gemini API through Google AI Studio** or the **Vertex AI API**.

The Generative Language API uses an API key, which you can get from **Google AI Studio**.

For Vertex AI, you need a Service Account JSON key file, with appropriate access configured.

Instructions for both are given below.

## Generative Language API (Gemini)

**[See here for Gemini API pricing and rate limits](https://ai.google.dev/pricing)**

⚠️ While Google models are free, they are using your input/output to help improve the model, with data de-identified from your Google Account and API key.
⚠️ During this period, your messages “may be accessible to trained reviewers.”

To use Gemini models through Google AI Studio, you'll need an API key. If you don't already have one, create a key in Google AI Studio.

Get an API key here: **[aistudio.google.com](https://aistudio.google.com/app/apikey)**

Once you have your key, provide the key in your .env file, which allows all users of your instance to use it.

```bash filename=".env"
GOOGLE_KEY=mY_SeCreT_w9347w8_kEY
```

Or, you can make users provide it from the frontend by setting the following:

```bash filename=".env"
GOOGLE_KEY=user_provided
```

Some reverse proxies do not support the `X-goog-api-key` header. You can configure LibreChat to use the `Authorization` header instead:

```bash filename=".env"
GOOGLE_AUTH_HEADER=true
```

Since fetching the models list isn't yet supported, you should set the models you want to use in the .env file.

For example, the following current models can be configured for the Gemini API:

```bash filename=".env"
GOOGLE_MODELS=gemini-3.8-flash,gemini-3.7-flash,gemini-3.6-flash,gemini-3.5-flash,gemini-3.5-flash-lite,gemini-3.1-pro-preview,gemini-3.1-pro-preview-customtools,gemini-3.1-flash-lite-preview,gemini-2.5-pro,gemini-2.5-flash,gemini-2.5-flash-lite,gemini-2.0-flash,gemini-2.0-flash-lite
```

<Callout type="note" title="Notes:">

- Gemini 3.8 Flash, Gemini 3.7 Flash, Gemini 3.6 Flash, Gemini 3.5 Flash, and Gemini 3.5 Flash-Lite are supported through both Google AI Studio and Google Cloud Gemini Enterprise Agent Platform. LibreChat assigns each a 1,048,576-token context window; Gemini 3.8 Flash supports up to 65,536 output tokens.
- LibreChat defaults Gemini 3.8 Flash, Gemini 3.7 Flash, Gemini 3.6 Flash, and Gemini 3.5 Flash to `MEDIUM` thinking, and Gemini 3.5 Flash-Lite to `MINIMAL`. Gemini 3.8 and 3.7 Flash reject `MINIMAL`, so LibreChat substitutes `LOW` when that level is requested; other supported explicit `thinkingLevel` values are preserved.
- For these models, LibreChat removes unsupported sampling and penalty parameters (`temperature`, `topP`, `topK`, `presencePenalty`, and `frequencyPenalty`), ignores the older numeric `thinkingBudget`, and uses `thinkingLevel` instead.
- Gemini Flash models from 3.6 onward do not support assistant prefill. LibreChat prevents edited assistant replies from being resubmitted as an unsupported trailing model-role turn.
- Built-in cost estimates use the Gemini 3.6/3.7/3.8 Flash introductory rates through December 31, 2026: $0.75 input, $3.75 output, and $0.075 cached input per million tokens. From January 1, 2027, the rates are $1.50, $7.50, and $0.15 respectively.
- With the Google endpoint, you cannot use both Vertex AI and Generative Language API at the same time. You must choose one or the other.

</Callout>

Setting `GOOGLE_KEY=user_provided` in your .env file sets both the Vertex AI Service Account JSON key file and the Generative Language API key to be provided from the frontend like so:

![image](https://github.com/danny-avila/LibreChat/assets/110412045/728cbc04-4180-45a8-848c-ae5de2b02996)

## URL Context

Google's URL Context tool lets supported Gemini models read URLs included in the user message, such as web pages, images, and PDFs. In LibreChat, enable it with the Google endpoint parameter `url_context`.

```yaml filename="modelSpecs / list / preset"
preset:
  endpoint: google
  model: gemini-2.5-flash
  url_context: true
```

You can also enable it for a Google-shaped custom endpoint with `addParams` or parameter defaults:

```yaml filename="endpoints / custom"
custom:
  - name: 'Google Gateway'
    apiKey: '${GOOGLE_KEY}'
    baseURL: 'https://gateway.example.com/v1'
    models:
      default: ['gemini-2.5-flash']
    customParams:
      defaultParamsEndpoint: google
    addParams:
      url_context: true
```

`url_context` is available on supported Gemini text models, including Gemini 2.5+ and Gemini 3.x models. YouTube links are handled separately with Gemini's native video understanding when `url_context` is enabled, because Google's URL Context tool does not support YouTube URLs directly.

## Vertex AI

**[See here for Vertex API pricing and rate limits](https://cloud.google.com/vertex-ai/generative-ai/pricing)**

To setup Google LLMs (via Google Cloud Vertex AI), first, signup for Google Cloud: **[cloud.google.com](https://cloud.google.com/)**

You can usually get **$300 starting credit**, which makes this option free for 90 days.

1. Once signed up, Enable the Vertex AI API on Google Cloud:
   - Go to **[Vertex AI page on Google Cloud console](https://console.cloud.google.com/vertex-ai)**
   - Click on `Enable API` if prompted
2. Create a Service Account with Vertex AI role:
   - **[Click here to create a Service Account](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts/create?walkthrough_id=iam--create-service-account#step_index=1)**
   - **Select or create a project**
   - Enter a service account ID (required), name and description are optional
     - ![image](https://github.com/danny-avila/LibreChat/assets/110412045/0c5cd177-029b-44fa-a398-a794aeb09de6)
   - Click on "Create and Continue" to give at least the "Vertex AI User" role
     - ![image](https://github.com/danny-avila/LibreChat/assets/110412045/22d3a080-e71e-446e-8485-bcc5bf558dbb)
   - **Click on "Continue/Done"**
3. Create a JSON key to Save in your Project Directory:
   - **Go back to [the Service Accounts page](https://console.cloud.google.com/projectselector/iam-admin/serviceaccounts)**
   - **Select your service account**
   - Click on "Keys"
     - ![image](https://github.com/danny-avila/LibreChat/assets/110412045/735a7bbe-25a6-4b4c-9bb5-e0d8aa91be3d)
   - Click on "Add Key" and then "Create new key"
     - ![image](https://github.com/danny-avila/LibreChat/assets/110412045/cfbb20d3-94a8-4cd1-ac39-f9cd8c2fceaa)
   - **Choose JSON as the key type and click on "Create"**
   - **Download the key file and rename it as 'auth.json'**
   - **Save it within the project directory, in `/api/data/`**
     - ![image](https://github.com/danny-avila/LibreChat/assets/110412045/f5b8bcb5-1b20-4751-81a1-d3757a4b3f2f)

<Callout type="info" title="Alternative: Using GOOGLE_SERVICE_KEY_FILE">
  Instead of saving the key file to `/api/data/auth.json`, you can use the `GOOGLE_SERVICE_KEY_FILE`
  environment variable to specify the path to your service account key file. This provides more
  flexibility in how you manage your credentials. See the environment variable section below for
  more details.
</Callout>

**Saving your JSON key file in the project directory which allows all users of your LibreChat instance to use it.**

Alternatively, you can make users provide it from the frontend by setting the following:

```bash filename=".env"
# Note: this configures both the Vertex AI Service Account JSON key file
# and the Generative Language API key to be provided from the frontend.
GOOGLE_KEY=user_provided
```

You can also specify the service account key file using the `GOOGLE_SERVICE_KEY_FILE` environment variable:

```bash filename=".env"
# Path to the service account JSON key file
GOOGLE_SERVICE_KEY_FILE=/path/to/auth.json

# Or provide as a URL
GOOGLE_SERVICE_KEY_FILE=https://example.com/path/to/auth.json

# Or provide as stringified JSON
GOOGLE_SERVICE_KEY_FILE='{"type":"service_account","project_id":"your-project",...}'

# Or provide as base64 encoded JSON
GOOGLE_SERVICE_KEY_FILE=eyJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIsICJwcm9qZWN0X2lkIjogInlvdXItcHJvamVjdC1pZCIsIC4uLn0=
```

This is particularly useful for features that require Vertex AI authentication, such as OCR capabilities.

You can also specify the Google Cloud location for Vertex AI API requests:

```bash filename=".env"
# Google Cloud region for Vertex AI
GOOGLE_LOC=us-central1

# Alternative region for Gemini Image Generation (defaults to global)
GOOGLE_CLOUD_LOCATION=global
```

Since fetching the models list isn't yet supported, you should set the models you want to use in the .env file.

For Vertex AI, use the Vertex model IDs where they differ from the Gemini API:

```bash filename=".env"
GOOGLE_MODELS=gemini-3.8-flash,gemini-3.7-flash,gemini-3.6-flash,gemini-3.5-flash,gemini-3.5-flash-lite,gemini-3.1-pro-preview,gemini-3.1-pro-preview-customtools,gemini-3.1-flash-lite-preview,gemini-2.5-pro,gemini-2.5-flash,gemini-2.5-flash-lite,gemini-2.0-flash-001,gemini-2.0-flash-lite-001
```

Saved Agents using the `vertexai` provider also use this shared Google model catalog in the Agent Builder and at runtime. If the deployment supplies an explicit `vertexai` model catalog, that provider-specific list takes precedence; otherwise `GOOGLE_MODELS` is used for Vertex AI selection and validation.

<Callout type="note" title="If you are using Docker">
If you're using docker and want to provide the `auth.json` file, you will need to also mount the volume in docker-compose.override.yml

```yaml filename="docker-compose.override.yml"
version: '3.4'

services:
  api:
    volumes:
      - type: bind
        source: ./api/data/auth.json
        target: /app/api/data/auth.json
```

</Callout>

## Google Safety Settings

To set safety settings for both Vertex AI and Generative Language API, you can set the following in your .env file:

```bash filename=".env"
GOOGLE_SAFETY_SEXUALLY_EXPLICIT=BLOCK_ONLY_HIGH
GOOGLE_SAFETY_HATE_SPEECH=BLOCK_ONLY_HIGH
GOOGLE_SAFETY_HARASSMENT=BLOCK_ONLY_HIGH
GOOGLE_SAFETY_DANGEROUS_CONTENT=BLOCK_ONLY_HIGH
GOOGLE_SAFETY_CIVIC_INTEGRITY=BLOCK_ONLY_HIGH
```

You can also exclude safety settings by setting the following in your .env file, which will use the provider defaults. This can be helpful if you are having issues with specific safety settings.

```bash filename=".env"
GOOGLE_EXCLUDE_SAFETY_SETTINGS=true
```

NOTE: You do not have access to the BLOCK_NONE setting by default.
To use this restricted `HarmBlockThreshold` setting, you will need to either:

- (a) Get access through an allowlist via your Google account team
- (b) Switch your account type to monthly invoiced billing following this instruction:
  https://cloud.google.com/billing/docs/how-to/invoiced-billing

**Notes:**

- Google endpoint supports all [Shared Endpoint Settings](/docs/configuration/librechat_yaml/object_structure/shared_endpoint_settings) via the `librechat.yaml` configuration file, including `streamRate`, `headers`, `titleModel`, `titleMethod`, `titlePrompt`, `titlePromptTemplate`, and `titleEndpoint`
