Summary
When using OpenAI-compatible proxy endpoints that route to Google Gemini models, the finish_reason field is returned as uppercase ("STOP", "MAX_TOKENS") instead of the OpenAI-standard lowercase ("stop", "max_tokens"). OpenClaw treats these as errors due to case-sensitive matching.
Steps to reproduce
- Configure a Gemini model (e.g.,
gemini-3-pro-preview) via an OpenAI-compatible proxy endpoint
- Send any chat completion request
- Observe the response is rejected with
Unhandled stop reason: STOP
Expected behavior
OpenClaw should normalize finish_reason to lowercase before matching, so "STOP" is treated the same as "stop".
Actual behavior
The response content is valid, but OpenClaw rejects it:
Unhandled stop reason: STOP
Raw API response from the proxy:
{"choices":[{"message":{"role":"assistant","content":"Hi!"},"index":0,"finish_reason":"STOP"}]}
Environment
- Clawdbot version: 2026.2.13
- OS: macOS Darwin 24.3.0 (arm64)
- Install method: pnpm
Logs or screenshots
Affected values observed:
- STOP → should map to stop
- MAX_TOKENS → should map to max_tokens
- Potentially other Google-native values: SAFETY, RECITATION, etc.
Suggested fix:
const reason = rawFinishReason?.toLowerCase?.() ?? rawFinishReason;
Models affected: gemini-3-pro-preview, gemini-3-flash-preview, gemini-2.5-pro-06-17, gemini-2.5-flash-06-17
Summary
When using OpenAI-compatible proxy endpoints that route to Google Gemini models, the
finish_reasonfield is returned as uppercase ("STOP","MAX_TOKENS") instead of the OpenAI-standard lowercase ("stop","max_tokens"). OpenClaw treats these as errors due to case-sensitive matching.Steps to reproduce
gemini-3-pro-preview) via an OpenAI-compatible proxy endpointUnhandled stop reason: STOPExpected behavior
OpenClaw should normalize
finish_reasonto lowercase before matching, so"STOP"is treated the same as"stop".Actual behavior
The response content is valid, but OpenClaw rejects it:
Raw API response from the proxy:
{"choices":[{"message":{"role":"assistant","content":"Hi!"},"index":0,"finish_reason":"STOP"}]}Environment
Logs or screenshots
Affected values observed:
Suggested fix:
Models affected: gemini-3-pro-preview, gemini-3-flash-preview, gemini-2.5-pro-06-17, gemini-2.5-flash-06-17