SuperAPI AI Directory

gemini-openai-api

Agents & models

View repository

Updated 10-15 21:40

About this skill

Gemini OpenAI-compatible API integration

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 to assist_api_providers
  • config/__init__.py - Add EXTRA_BODY_GEMINI and MODELS_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:

  1. Response was truncated (token limit too small)
  2. Response contains a markdown code block

Solution:

  1. Increase max_completion_tokens
  2. Add markdown code block handling logic