跳轉到主要內容
LemonData 支援 Gemini 模型的原生 Google Gemini API 格式。這使得與 Google AI SDK 具有直接的相容性。

路徑參數

model
string
必填
模型名稱(例如:gemini-2.5-progemini-2.5-flash)。For production integrations, prefer URL-based fileData / file_data media parts with a public https URL. LemonData will route supported Gemini-native channels through the native path when possible and automatically fall back to the compatible internal conversion path when a native-ready route is unavailable for that multimodal request.

查詢參數

key
string
API key(標頭驗證的替代方案)。

驗證

Gemini 端點支援多種驗證方式:
  • ?key=YOUR_API_KEY 查詢參數
  • x-goog-api-key: YOUR_API_KEY 標頭
  • Authorization: Bearer YOUR_API_KEY 標頭

請求主體

contents
array
必填
對話內容。每個內容物件包含:
  • role (string):usermodel
  • parts (array):內容 part。LemonData 目前支援:
    • 文字 part:{ "text": "..." }
    • 內嵌媒體 part:inlineData / inline_data
    • 基於 URL 的檔案 part:fileData / file_data
對於媒體 part,LemonData 目前接受圖片、音訊、影片三類 MIME type,並透過 Gemini 相容公共契約向下游轉發。
systemInstruction
object
模型的系統指令。
generationConfig
object
生成配置:
  • temperature (number):取樣溫度
  • topP (number):核取樣機率
  • topK (integer):Top-K 取樣
  • maxOutputTokens (integer):最大輸出 token 數
  • stopSequences (array):停止序列
safetySettings
array
安全過濾器設定。

回應

candidates
array
生成的內容候選。
usageMetadata
object
Token 使用資訊。
curl -X POST "https://api.lemondata.cc/v1beta/models/gemini-2.5-pro:generateContent?key=sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [{"text": "Hello, Gemini!"}]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 1024
    }
  }'

多模態輸入範例

對於 Gemini 多模態請求,請把媒體放在 contents[].parts[] 中,可以使用「內嵌位元組」或「基於 URL 的檔案引用」兩種方式。 目前公共 Gemini 契約支援的媒體類別:
  • 圖片
  • 音訊
  • 影片
對於內嵌媒體,請使用 inlineDatainline_data,並傳入檔案位元組的 Base64 內容。 對於 URL 媒體,請使用 fileDatafile_data,並傳入可公開存取的 https URL。

圖片輸入範例

使用內嵌圖片位元組:
{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "請描述這張圖片。" },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "/9j/4AAQSkZJRgABAQ..."
          }
        }
      ]
    }
  ]
}
使用圖片 URL:
{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "請描述這張圖片。" },
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "https://example.com/demo.jpg"
          }
        }
      ]
    }
  ]
}

音訊輸入範例

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "請轉寫並摘要這段音訊。" },
        {
          "file_data": {
            "mime_type": "audio/mpeg",
            "file_uri": "https://example.com/sample.mp3"
          }
        }
      ]
    }
  ]
}

影片輸入範例

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "請簡要描述這段影片。" },
        {
          "fileData": {
            "mimeType": "video/mp4",
            "fileUri": "https://example.com/sample.mp4"
          }
        }
      ]
    }
  ]
}
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {"text": "Hello! How can I assist you today?"}
        ]
      },
      "finishReason": "STOP",
      "safetyRatings": [
        {"category": "HARM_CATEGORY_HARASSMENT", "probability": "NEGLIGIBLE"}
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 5,
    "candidatesTokenCount": 10,
    "totalTokenCount": 15
  }
}

Video Input Example

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this video." },
        {
          "fileData": {
            "mimeType": "video/mp4",
            "fileUri": "https://example.com/demo.mp4"
          }
        }
      ]
    }
  ]
}

Audio Input Example

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "Please describe this audio." },
        {
          "fileData": {
            "mimeType": "audio/mpeg",
            "fileUri": "https://example.com/demo.mp3"
          }
        }
      ]
    }
  ]
}