Skip to content
Tài liệu API

Gemini Generate Content ​

Gọi trực tiếp các mô hình Google Gemini theo giao thức gốc với SDK chính thức @google/genai hoặc google-genai và Gemini CLI, giữ nguyên các thành phần đa phương thức gốc, systemInstruction và cấu hình suy luận.

POSThttps://api.vanix.io/v1beta/models/{model}:generateContent
POSThttps://api.vanix.io/v1beta/models/{model}:streamGenerateContent?alt=sse
Thử nghiệm trực tiếpPOST /v1beta/models/gemini-2.5-flash:generateContent

Xác thực ​

Truyền token Vanix AI của bạn qua header x-goog-api-key (khuyến nghị) hoặc tham số truy vấn ?key=$VANIX_API_KEY.

Tham số thân yêu cầu (Request Body) ​

contentsarray<object>bắt buộc
Danh sách theo thứ tự các lượt nội dung, mỗi lượt gồm role (user hoặc model) và parts (text, inlineData, functionCall, functionResponse).
systemInstructionobjecttùy chọn
Khối system prompt cấp cao nhất: {"parts": [{"text": "..."}]}.
generationConfigobjecttùy chọn
Các tùy chọn lấy mẫu và kiểm soát đầu ra bao gồm temperature, maxOutputTokens, responseMimeType và thinkingConfig.
toolsarray<object>tùy chọn
Khai báo hàm gốc của Gemini hoặc các công cụ từ nhà cung cấp như Google Search grounding khi kênh thượng nguồn hỗ trợ.

Ví dụ mã nguồn ​

bash
curl "https://api.vanix.io/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $VANIX_API_KEY" \
  -d '{
    "systemInstruction": {"parts": [{"text": "Reply in JSON only."}]},
    "contents": [{
      "role": "user",
      "parts": [{"text": "Return {\"status\":\"ok\",\"gateway\":\"vanix\"}"}]
    }],
    "generationConfig": {"responseMimeType": "application/json"}
  }'
bash
curl -N "https://api.vanix.io/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $VANIX_API_KEY" \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "Explain token buckets in 3 sentences."}]}]
  }'
python
import os
from google import genai
from google.genai import types

client = genai.Client(
    api_key=os.environ["VANIX_API_KEY"],
    http_options=types.HttpOptions(base_url="https://api.vanix.io"),
)

resp = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="Explain token buckets in 3 sentences.",
)
print(resp.text)

Vanix AI Cổng API Hợp Nhất · https://api.vanix.io