Fix: Gemini Models Return 400 (Request Formatting Issue)
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.
Jump to Fix
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:
{
"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:
| Model | openclaw.json value |
|---|---|
| Gemini 2.0 Flash | google/gemini-2.0-flash |
| Gemini 2.0 Flash Thinking | google/gemini-2.0-flash-thinking-exp |
| Gemini 1.5 Pro | google/gemini-1.5-pro |
| Gemini 1.5 Flash | google/gemini-1.5-flash |
Step 2: Explicitly Configure the Google Provider
{
"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:
{
"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 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 restartA successful curl response confirms your API key and model name are correct. OpenClaw will use the same endpoint with the same credentials.
Related Gemini & API errors
Fix It Faster With Our Tools
Did this guide solve your problem?