钠API

Gemini API 接入与多模态说明

区分 Gemini 原生接口与 OpenAI 兼容接口,再按模型和渠道选择文本或多模态请求。

技术核对:2026-11-27 · Codex(AI 技术核对)
核对官方协议与本站路由及适配器源码;未执行付费模型调用。

接入步骤

接口示例:Gemini generateContent,POST /v1beta/models/{model}:generateContent。选择模型前,可用以下只读请求查询当前令牌的模型列表。

import os, json, urllib.request
request = urllib.request.Request(
    "https://naapi.cc/v1/models",
    headers={"Authorization": "Bearer " + os.environ["NAAPI_API_KEY"]},
)
with urllib.request.urlopen(request, timeout=30) as response:
    print(json.load(response))

请求示例

import os, json, urllib.request, urllib.parse
model = os.environ["NAAPI_MODEL"].removeprefix("models/")
url = "https://naapi.cc/v1beta/models/" + urllib.parse.quote(model, safe="") + ":generateContent"
payload = {"contents": [{"role": "user", "parts": [{"text": "请用一句话介绍 HTTP。"}]}]}
request = urllib.request.Request(
    url, data=json.dumps(payload).encode("utf-8"),
    headers={"x-goog-api-key": os.environ["NAAPI_API_KEY"],
             "Content-Type": "application/json"},
)
with urllib.request.urlopen(request, timeout=60) as response:
    print(json.load(response))

能力与限制

常见错误排查

当前公开模型参考

完整配置、分组与价格请查看模型广场。

  • [AG2][按量]gemini-4-argon · Google · 按分组查询实时计费规则
  • [AG2][按量]gemini-4-argon-high · Google · 按分组查询实时计费规则
  • [AG2][按量]gemini-4-carbon · Google · 按分组查询实时计费规则
  • [AG2][按量]gemini-4-carbon-high · Google · 按分组查询实时计费规则
  • [AG][按次]gemini-4-argon · Google · 按分组查询实时计费规则
  • [AG][按量]gemini-4-argon · Google · 按分组查询实时计费规则

资料来源