ClawKit Logo
ClawKitReliability Toolkit

Fix: Gemini Models Return 400 (Request Formatting Issue)

Error: 400 Bad Request
Provider: google
[OpenClaw is sending OpenAI-format requests to Gemini, but Gemini expects a different structure]

Google Gemini uses a different API request format from OpenAI. If OpenClaw sends an OpenAI-formatted request to the Gemini endpoint โ€” because the model name lacks the google/ prefix or the provider is misconfigured โ€” Gemini returns a 400 error. This guide covers all the config fixes to get Gemini working correctly.

Next Step

Fix now, then reduce repeat incidents

If this issue keeps coming back, validate your setup in Doctor first, then harden your config.

Step 1: Fix the Model Name Prefix

The google/ prefix tells OpenClaw to use the Gemini request formatter. Without it, OpenClaw may assume OpenAI format and produce a 400 error:

Correct model name in openclaw.json
{
  "model": "google/gemini-2.0-flash"

  // NOT: "gemini-2.0-flash" (missing prefix โ€” uses wrong formatter)
  // NOT: "gemini/gemini-2.0-flash" (wrong prefix)
}

Available Gemini model names with correct prefixes:

Modelopenclaw.json value
Gemini 2.0 Flashgoogle/gemini-2.0-flash
Gemini 2.0 Flash Thinkinggoogle/gemini-2.0-flash-thinking-exp
Gemini 1.5 Progoogle/gemini-1.5-pro
Gemini 1.5 Flashgoogle/gemini-1.5-flash

Step 2: Explicitly Configure the Google Provider

Google provider config in openclaw.json
{
  "model": "google/gemini-2.0-flash",
  "providers": {
    "google": {
      "enabled": true,
      "baseUrl": "https://generativelanguage.googleapis.com/v1beta"
    }
  }
}

Step 3: Add a Google AI Studio API Key

The CLI OAuth flow can cause authentication mismatches that lead to 400 errors. Using a direct API key is more reliable:

API key config (from aistudio.google.com/apikey)
{
  "model": "google/gemini-2.0-flash",
  "credentials": {
    "google": {
      "apiKey": "AIza..."
    }
  }
}

Get your API key at aistudio.google.com/apikey. The free tier includes generous quota for Gemini 1.5 Flash and 2.0 Flash.

Step 4: Verify Gemini is Working

Test Gemini with a direct API call
# Test your API key directly
curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=YOUR_KEY"   -H "Content-Type: application/json"   -d '{"contents":[{"parts":[{"text":"Hello"}]}]}'

# If this succeeds, restart OpenClaw gateway
openclaw gateway restart

A successful curl response confirms your API key and model name are correct. OpenClaw will use the same endpoint with the same credentials.

Did this guide solve your problem?