模型API服务指南
模型API调用指南
语言模型 API文档
gemini兼容文档

Gemini 兼容 API 调用文档

UModelverse 平台提供了与 Google Gemini API 兼容的 Models 接口,开发者可以使用 Gemini SDK 或其他支持的工具直接调用 Modelverse 上的 Gemini 模型

本文将向您介绍如何快速在 UModelverse 平台发出您的第一个 Gemini API 请求。

快速开始

安装 Google GenAI SDK

安装 python 语言的 sdk

使用 Python 3.9 及更高版本,通过以下 pip 命令安装 google-genai 软件包:

pip install -q -U google-genai

示例

以下示例使用 generateContent 方法,通过gemini-2.5-flash模型向 UModelverse API 发送请求。

请确保将 $MODELVERSE_API_KEY 替换为您自己的 API Key,获取 API Key (opens in a new tab)

非流式调用

请注意,如果使用genai sdk我们需要通过http_options来指定 Modelverse 的 API 地址。

from google import genai
from google.genai import types
 
client = genai.Client(
    api_key="<MODELVERSE_API_KEY>",
    http_options=types.HttpOptions(
        base_url="https://api.modelverse.cn"
    ),
)
 
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents=[
        {"text": "How does AI work?"},
    ],
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(thinking_budget=0),
    ),
)
print(response.text)
curl "https://api.modelverse.cn/v1beta/models/deepseek-ai/DeepSeek-V3.1:generateContent" \
    -H "x-goog-api-key: $MODELVERSE_API_KEY" \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{
          "contents": [
            {
              "parts": [
                {
                  "text": "How does AI work?"
                }
              ]
            }
          ],
          "generationConfig": {
            "thinkingConfig": {
              "thinkingBudget": 0
            }
          }
        }'

流式调用

from google import genai
from google.genai import types
 
client = genai.Client(
    api_key="<MODELVERSE_API_KEY>",
    http_options=types.HttpOptions(
        base_url="https://api.modelverse.cn"
    ),
)
 
response = client.models.generate_content_stream(
    model="gemini-2.5-flash", contents=["Explain how AI works"]
)
for chunk in response:
    print(chunk.text, end="")
 
curl "https://api.modelverse.cn/v1beta/models/gemini-2.5-flash:GenerateContent?alt=sse" \
    -H "Authorization: Bearer $MODELVERSE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "contents": [
        {
          "role": "user",
          "parts": [
            {
              "text": "Explain how AI works"
            }
          ]
        }
      ]
    }'

模型ID说明

更多受支持的gemini模型,请参考获取模型ID

更多字段详情,见Gemini官方文档 (opens in a new tab)

Copyright © 2025 沪ICP备12020087号-61