块乐Encore
扩展接入

Gemini 接入指南

Google Gemini 的 SDK、CLI 与 HTTP 接口说明。

通过 Encore API,您可以直接调用 Google 的 Gemini 系列模型。我们兼容 Google Generative Language API 规范。

SDK 与客户端配置

export GOOGLE_GEMINI_BASE_URL="https://api.stillhappy.cn"
export GEMINI_API_KEY="YOUR_API_KEY"

Gemini 的底层路由为 /v1beta/models/...,SDK 会自动处理路径拼接。

Gemini CLI 专用配置

# 1. 设置环境变量
export GOOGLE_GEMINI_BASE_URL="https://api.stillhappy.cn"
export GEMINI_API_KEY="YOUR_API_KEY"

# 2. 使用 CLI 发起请求
gemini generate --model gemini-2.5-pro "请用一句话解释什么是量子计算。"

HTTP 请求示例

生成内容 (generateContent)

curl -X POST "https://api.stillhappy.cn/v1beta/models/gemini-2.5-pro:generateContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "contents": [
      {
        "parts": [
          { "text": "你好,请用中文总结一下什么是向量数据库。" }
        ]
      }
    ]
  }'

流式输出 (streamGenerateContent)

curl -N -X POST "https://api.stillhappy.cn/v1beta/models/gemini-2.5-pro:streamGenerateContent?alt=sse" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "contents": [
      {
        "parts": [
          { "text": "请逐步说明如何搭建一个 Go Web 服务。" }
        ]
      }
    ]
  }'

On this page