Gemini Generating Content
Usa il formato API nativo di Gemini tramite CometAPI per la generazione di testo, input multimodale, thinking/reasoning, function calling, grounding con Google Search, modalità JSON e streaming.
CometAPI supporta il formato API nativo di Gemini, offrendoti pieno accesso a funzionalità specifiche di Gemini come il controllo del thinking, il grounding con Google Search, le modalità native di generazione di immagini e altro ancora. Usa questo endpoint quando hai bisogno di capacità non disponibili tramite l’endpoint chat compatibile con OpenAI.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 sia Authorization: Bearer.Avvio rapido
Per usare qualsiasi SDK Gemini o client HTTP con CometAPI, sostituisci l’URL di base e la chiave API:| Impostazione | Predefinito Google | CometAPI |
|---|---|---|
| URL di base | generativelanguage.googleapis.com | api.cometapi.com |
| Chiave API | $GEMINI_API_KEY | $COMETAPI_KEY |
Configurare il thinking (reasoning)
I modelli Gemini possono eseguire reasoning interno prima di generare una risposta. Il metodo di controllo dipende dalla generazione del modello.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel per controllare la profondità del reasoning. Livelli disponibili: MINIMAL, LOW, MEDIUM, HIGH.Usa gemini-3-flash-preview come model ID di esempio predefinito, a meno che tu non abbia bisogno specificamente di una variante diversa di Gemini 3.Trasmettere risposte in streaming
Per ricevere Server-Sent Events mentre il modello genera contenuto, usastreamGenerateContent?alt=sse come operator. Ogni evento SSE contiene una riga data: con un oggetto JSON GenerateContentResponse.
Impostare le istruzioni di sistema
Per guidare il comportamento del modello nell’intera conversazione, usasystemInstruction:
Output JSON della richiesta
Per forzare un output JSON strutturato, impostaresponseMimeType. Facoltativamente, fornisci un responseSchema per una rigorosa validazione dello schema:
Grounding con Google Search
Per abilitare la ricerca web in tempo reale, aggiungi uno strumentogoogleSearch:
groundingMetadata con gli URL delle fonti e i punteggi di confidenza.
Esempio di risposta
Una risposta tipica dall’endpoint Gemini di CometAPI:thoughtsTokenCount in usageMetadata mostra quanti token il modello ha speso per il ragionamento interno, anche quando l’output di thinking non è incluso nella risposta.Confronto con l’endpoint compatibile con OpenAI
| Funzionalità | Gemini nativo (/v1beta/models/...) | Compatibile con OpenAI (/v1/chat/completions) |
|---|---|---|
| Controllo del thinking | thinkingConfig con thinkingLevel / thinkingBudget | Non disponibile |
| Grounding di Google Search | tools: [\{"google_search": \{\}\}] | Non disponibile |
| Grounding di Google Maps | tools: [\{"googleMaps": \{\}\}] | Non disponibile |
| Modalità di generazione immagini | responseModalities: ["IMAGE"] | Non disponibile |
| Header di autenticazione | x-goog-api-key o Bearer | Solo Bearer |
| Formato della risposta | Formato nativo Gemini (candidates, parts) | Formato OpenAI (choices, message) |
Autorizzazioni
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer <key>) is also supported.
Parametri del percorso
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 Corpo
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.
Risposta
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.