smithery.ai

gemini-openai-api

Gemini 模型通过 OpenAI ?

First seen Mar 26, 2026

Installation

$ npx skills add https://smithery.ai

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery.ai · top by installs.

npx skills add https://smithery.ai

Browse all from smithery.ai

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 3,496 B
  • docs SUMMARY.md 361 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 1 installs

SKILL.md

Gemini OpenAI 兼容 API 接入

Gemini 提供 OpenAI 兼容端点,可作为辅助 API 使用。

[!IMPORTANT]
memory/ + utils/ 下不要传 temperature。项目级约定:所有走
utils.llmclient.createchat_llm / ChatOpenAI 的调用一律不下发
temperature 字段(默认 None = 不写进请求体)。守门见
scripts/checknotemperature.py。extra_body(控制 thinking)/
maxcompletiontokens / timeout / max_retries 这类参数继续按需配置,但
不要为了"调风格"再加 temperature=...。

Base URL

https://generativelanguage.googleapis.com/v1beta/openai/

模型配置

用途 推荐模型
Summary / Correction / Vision gemini-3-flash-preview
Emotion Analysis gemini-2.5-flash

控制 Thinking

Gemini 2.5+ 模型需要通过 extra_body 控制 thinking 行为。

禁用 Thinking(用于 gemini-2.5-flash)

extra_body = {
    "extra_body": {
        "google": {
            "thinking_config": {
                "thinking_budget": 0
            }
        }
    }
}

低级别 Thinking(用于 gemini-3-flash-preview)

extra_body = {
    "extra_body": {
        "google": {
            "thinking_config": {
                "thinking_level": "low",
                "include_thoughts": False
            }
        }
    }
}

[!IMPORTANT]
extrabody 需要双层嵌套:外层 "extrabody" 是传给 OpenAI client 的参数名,内层 {"google": {...}} 是 Gemini 的实际配置。

响应格式处理

Gemini 可能返回 markdown 代码块包装的 JSON:

{"emotion": "happy", "confidence": 0.8}

处理方法:

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()

配置文件位置

  • config/apiproviders.json - 添加 gemini 到 assistapi_providers
  • config/init.py - 添加 EXTRABODYGEMINI 和 MODELSEXTRABODY_MAP

api_providers.json 示例

"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"
}

常见问题

"Unknown name 'google': Cannot find field"

原因:extrabody 格式错误,缺少外层 "extrabody" 包装。

解决:使用双层嵌套格式 {"extra_body": {"google": {...}}}。

JSON 解析失败

原因:

  1. 响应被截断(token 限制太小)
  2. 响应包含 markdown 代码块

解决:

  1. 增加 maxcompletiontokens
  2. 添加 markdown 代码块处理逻辑