Gemini Generating Content
Sử dụng định dạng API gốc của Gemini thông qua CometAPI để tạo văn bản, đầu vào multimodal, thinking/reasoning, function calling, Google Search grounding, chế độ JSON và streaming.
CometAPI hỗ trợ định dạng API gốc của Gemini, cho phép bạn truy cập đầy đủ vào các tính năng riêng của Gemini như điều khiển thinking, Google Search grounding, các modality tạo ảnh gốc và nhiều hơn nữa. Hãy dùng endpoint này khi bạn cần những khả năng không có trong OpenAI-compatible chat endpoint.Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
x-goog-api-key và Authorization: Bearer đều được hỗ trợ để xác thực.Bắt đầu nhanh
Để sử dụng bất kỳ Gemini SDK hoặc HTTP client nào với CometAPI, hãy thay thế base URL và API key:| Cài đặt | Mặc định của Google | CometAPI |
|---|---|---|
| Base URL | generativelanguage.googleapis.com | api.cometapi.com |
| API Key | $GEMINI_API_KEY | $COMETAPI_KEY |
Cấu hình thinking (reasoning)
Các model Gemini có thể thực hiện reasoning nội bộ trước khi tạo phản hồi. Phương thức điều khiển phụ thuộc vào thế hệ model.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel để kiểm soát độ sâu reasoning. Các mức khả dụng: MINIMAL, LOW, MEDIUM, HIGH.Sử dụng gemini-3-flash-preview làm model ví dụ mặc định trừ khi bạn thực sự cần một biến thể Gemini 3 khác.Stream phản hồi
Để nhận Server-Sent Events khi model đang tạo nội dung, hãy sử dụngstreamGenerateContent?alt=sse làm operator. Mỗi sự kiện SSE chứa một dòng data: với một đối tượng JSON GenerateContentResponse.
Đặt system instructions
Để định hướng hành vi của model trong toàn bộ cuộc trò chuyện, hãy sử dụngsystemInstruction:
Yêu cầu đầu ra JSON
Để buộc đầu ra JSON có cấu trúc, hãy đặtresponseMimeType. Bạn cũng có thể cung cấp responseSchema để xác thực schema nghiêm ngặt:
Ground với Google Search
Để bật tìm kiếm web theo thời gian thực, hãy thêm công cụgoogleSearch:
groundingMetadata với URL nguồn và điểm độ tin cậy.
Ví dụ phản hồi
Một phản hồi điển hình từ endpoint Gemini của CometAPI:thoughtsTokenCount trong usageMetadata cho biết mô hình đã dùng bao nhiêu tokens cho quá trình suy luận nội bộ, ngay cả khi đầu ra suy nghĩ không được đưa vào phản hồi.So sánh với endpoint tương thích OpenAI
| Tính năng | Gemini Native (/v1beta/models/...) | OpenAI-Compatible (/v1/chat/completions) |
|---|---|---|
| Điều khiển suy nghĩ | thinkingConfig với thinkingLevel / thinkingBudget | Không khả dụng |
| Ground bằng Google Search | tools: [\{"google_search": \{\}\}] | Không khả dụng |
| Ground bằng Google Maps | tools: [\{"googleMaps": \{\}\}] | Không khả dụng |
| Phương thức tạo hình ảnh | responseModalities: ["IMAGE"] | Không khả dụng |
| Header xác thực | x-goog-api-key hoặc Bearer | Chỉ Bearer |
| Định dạng phản hồi | Định dạng gốc Gemini (candidates, parts) | Định dạng OpenAI (choices, message) |
Ủy quyền
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer <key>) is also supported.
Tham số đường dẫn
Gemini model ID. Example: gemini-3-flash-preview, gemini-2.5-pro. See the Models page for current options.
The operation to perform. Use generateContent for synchronous responses, or streamGenerateContent?alt=sse for Server-Sent Events streaming.
generateContent, streamGenerateContent?alt=sse Nội dung
System instructions that guide the model's behavior across the entire conversation. Text only.
Tools the model may use to generate responses. Supports function declarations, Google Search, Google Maps, and code execution.
Configuration for tool usage, such as function calling mode.
Safety filter settings. Override default thresholds for specific harm categories.
Configuration for model generation behavior including temperature, output length, and response format.
The name of cached content to use as context. Format: cachedContents/{id}. See the Gemini context caching documentation for details.
Phản hồi
Successful response. For streaming requests, the response is a stream of SSE events, each containing a GenerateContentResponse JSON object prefixed with data:.
The generated response candidates.
Feedback on the prompt, including safety blocking information.
Token usage statistics for the request.
The model version that generated this response.
The timestamp when this response was created (ISO 8601 format).
Unique identifier for this response.