Gemini provides an OpenAI-compatible endpoint that can be used as an auxiliary API.
Base URL
https://generativelanguage.googleapis.com/v1beta/openai/
Model Configuration
| Purpose | Recommended Model |
|---|---|
| Summary / Correction / Vision | gemini-3-flash-preview |
| Emotion Analysis | gemini-2.5-flash |
Control Thinking
Gemini 2.5+ models need to pass through extra_body to control thinking behavior.
Disable Thinking (for gemini-2.5-flash)
extra_body = {
"extra_body": {
"google": {
"thinking_config": {
"thinking_budget": 0
}
}
}
}
Low-level Thinking (for gemini-3-flash-preview)
extra_body = {
"extra_body": {
"google": {
"thinking_config": {
"thinking_level": "low",
"include_thoughts": False
}
}
}
}
[!IMPORTANT] extra_body requires double nesting: the outer
"extra_body"is the parameter name passed to the OpenAI client, and the inner{"google": {...}}is Gemini's actual configuration.
Response Format Handling
Gemini may return JSON wrapped in a markdown code block:
```json
{"emotion": "happy", "confidence": 0.8}
处理方法:
```python
if result_text.startswith("```"):
lines = result_text.split("\n")
if lines[0].startswith("```"):
lines = lines[1:]
if lines and lines[-1].strip() == "```":
lines = lines[:-1]
result_text = "\n".join(lines).strip()
Configuration File Location
config/api_providers.json- Add gemini toassist_api_providersconfig/__init__.py- AddEXTRA_BODY_GEMINIandMODELS_EXTRA_BODY_MAP
api_providers.json example
"gemini": {
"key": "gemini",
"name": "Gemini(Google)",
"description": "Google AI 辅助模型,国内无法使用",
"openrouter_url": "https://generativelanguage.googleapis.com/v1beta/openai/",
"summary_model": "gemini-3-flash-preview",
"correction_model": "gemini-3-flash-preview",
"emotion_model": "gemini-2.5-flash",
"vision_model": "gemini-3-flash-preview"
}
Common Issues
"Unknown name 'google': Cannot find field"
Cause: incorrect extra_body format, missing the outer "extra_body" wrapper.
Solution: use the double-nested format {"extra_body": {"google": {...}}}。
JSON parsing failed
Cause:
- Response was truncated (token limit too small)
- Response contains a markdown code block
Solution:
- Increase
max_completion_tokens - Add markdown code block handling logic