API Gemini-compatible
Đang hoạt động
Sử dụng các route mô hình, tạo nội dung, streaming và embedding theo giao thức Gemini-compatible khi đã được cấu hình.
GET /v1beta/models
Liệt kê các mô hình theo giao thức Gemini-compatible mà API Key hiện tại có thể xem.
Danh sách mô hình Gemini-compatible
curl https://www.token168.cc/v1beta/models \
-H "Authorization: Bearer $TOKEN168_API_KEY"
POST /v1beta/models/{model}:generateContent
generateContent chấp nhận nội dung Gemini native cùng các trường safety, tool, system instruction, cache và generationConfig. Ví dụ dùng mô hình tài liệu mới nhất đã chọn là gemini-3.1-pro.
Yêu cầu Gemini generateContent
curl https://www.token168.cc/v1beta/models/gemini-3.1-pro:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"contents": [{"role": "user", "parts": [{"text": "Summarize the release notes.", "thought": false}]}],
"safetySettings": [{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}],
"generationConfig": {
"temperature": 0.4,
"topP": 0.9,
"topK": 40,
"maxOutputTokens": 800,
"candidateCount": 1,
"stopSequences": ["END"],
"responseMimeType": "application/json",
"responseSchema": {"type": "object", "properties": {"summary": {"type": "string"}}},
"responseJsonSchema": {"type": "object"},
"presencePenalty": 0,
"frequencyPenalty": 0,
"responseLogprobs": false,
"logprobs": 0,
"enableEnhancedCivicAnswers": false,
"mediaResolution": "MEDIA_RESOLUTION_MEDIUM",
"seed": 123,
"responseModalities": ["TEXT"],
"thinkingConfig": {"includeThoughts": true, "thinkingBudget": 1024, "thinkingLevel": "medium"},
"speechConfig": {"voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Kore"}}},
"imageConfig": {"aspectRatio": "1:1"}
},
"tools": [{"functionDeclarations": [{"name": "lookup", "parameters": {"type": "object", "properties": {}}}]}],
"toolConfig": {"functionCallingConfig": {"mode": "AUTO", "allowedFunctionNames": ["lookup"]}, "retrievalConfig": {"languageCode": "en"}, "includeServerSideToolInvocations": false},
"systemInstruction": {"role": "system", "parts": [{"text": "Return concise JSON."}]},
"cachedContent": "cachedContents/example"
}'
POST /v1beta/models/{model}:streamGenerateContent
Streaming dùng cùng body yêu cầu với action streaming hoặc tham số truy vấn alt=sse.
Luồng Gemini
curl "https://www.token168.cc/v1beta/models/gemini-3.1-pro:streamGenerateContent?alt=sse" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"contents": [{"role": "user", "parts": [{"text": "Stream one paragraph."}]}],
"generationConfig": {"temperature": 0.4, "topP": 0.9, "topK": 40, "maxOutputTokens": 400, "candidateCount": 1}
}'
POST /v1beta/models/{model}:embedContent
Các đường dẫn Gemini kiểu embedding được định tuyến qua định dạng relay Gemini khi đã được cấu hình.
Embedding Gemini
curl https://www.token168.cc/v1beta/models/gemini-3.1-pro:embedContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN168_API_KEY" \
-d '{
"content": {"parts": [{"text": "Token168 docs"}]},
"taskType": "RETRIEVAL_DOCUMENT",
"title": "Docs"
}'