Overview

This guide walks you through connecting Google Gemini to Matrix using OpenClaw. You'll learn how to configure authentication, set up the channel, and deploy your AI assistant.

Google Gemini Features

  • 1M token context window
  • Multimodal understanding
  • Fast inference
  • Competitive pricing

Matrix Capabilities

  • Direct messages
  • Group chats
  • Media support
  • Reactions
  • Thread support

Step 1: Configure Google Gemini

Google AI API key

  1. Go to ai.google.dev
  2. Create or select a project
  3. Enable the Gemini API
  4. Generate an API key
  5. Set GOOGLE_API_KEY environment variable

Environment variable: GOOGLE_API_KEY

Step 2: Configure Matrix

  1. Create a Matrix account on your preferred homeserver
  2. Generate an access token
  3. Configure matrix in openclaw.json
  4. Start the gateway
  5. Invite the bot to rooms

Step 3: Combined Configuration

Add both configurations to your openclaw.json:

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "google-gemini/gemini-2.0-flash-exp"
      }
    }
  },
  "models": {
    "providers": {
      "google-gemini": {
  "models": {
    "providers": {
      "google-gemini": {
        "apiKey": "${GOOGLE_API_KEY}
    }
  },
  "channels": {
    "matrix": {
      "homeserver": "https://matrix.org",
      "accessToken": "${MATRIX_ACCESS_TOKEN}",
      "userId": "@mybot:matrix.org"
    }
  }
}
}

Step 4: Start the Gateway

# Start the gateway
openclaw gateway start

# Check status
openclaw status

# View logs
openclaw logs --follow

Access Control

Matrix supports the following access control policies:

DM Policies

Policy Description
allowlist Only senders in allowFrom list are processed
pairing Unknown senders receive a pairing code; admin must approve
open All DMs are processed (requires allowFrom: ["*"])

Group Policies

Policy Description
allowlist Only groups in groupAllowFrom are processed
open All groups are processed

Deploy Options

Choose how to deploy your Google Gemini + Matrix setup:

Frequently Asked Questions

How do I set up Google Gemini with Matrix?
Configure Google Gemini as your AI provider and enable Matrix as a channel in openclaw.json. The gateway routes Matrix messages to Google Gemini for processing automatically.
Is Google Gemini a good choice for Matrix bots?
Google Gemini works great with Matrix. Extremely large context window and Very cost-effective make it well-suited for Privacy-focused teams and Open source communities.