Generar contenido
Usa el formato nativo de la API de Gemini a través de CometAPI para generación de texto, entrada multimodal, razonamiento, Function Calling, anclaje con Google Search, modo JSON y Streaming.
x-goog-api-key como Authorization: Bearer para la autenticación.Inicio rápido
Para usar cualquier SDK de Gemini o cliente HTTP con CometAPI, reemplaza la URL base y la clave de API:Enviar entrada de video
GeminigenerateContent acepta video como una parte de contenido. Elige la forma de entrada según dónde esté almacenado el video:
inlineData.mimeType y fileData.fileUri. No envíes medios por URL como file_data.file_uri.fileData.fileUri:
generateContent con inlineData o fileData.fileUri.
Configurar thinking (reasoning)
Los modelos Gemini pueden realizar razonamiento interno antes de generar una respuesta. El método de control depende de la generación del modelo.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel para controlar la profundidad del razonamiento. Niveles disponibles: MINIMAL, LOW, MEDIUM, HIGH.Usa gemini-3-flash-preview como model de ejemplo predeterminado a menos que necesites específicamente una variante diferente de Gemini 3.Transmitir respuestas
Para recibir eventos enviados por el servidor a medida que el modelo genera contenido, usastreamGenerateContent?alt=sse como operador. Cada evento SSE contiene una línea data: con un objeto JSON GenerateContentResponse.
Establecer instrucciones del sistema
Para guiar el comportamiento del modelo durante toda la conversación, usasystemInstruction:
Solicitar salida JSON
Para forzar una salida JSON estructurada, estableceresponseMimeType. Opcionalmente, proporciona un responseSchema para una validación estricta del esquema:
Basarse en Google Search
Para habilitar la búsqueda web en tiempo real, agrega una herramientagoogleSearch:
groundingMetadata con URL de las fuentes y puntuaciones de confianza.
Ejemplo de respuesta
Una respuesta típica del endpoint de Gemini de CometAPI:thoughtsTokenCount en usageMetadata muestra cuántos tokens gastó el modelo en razonamiento interno, incluso cuando la salida de pensamiento no se incluye en la respuesta.Comparación con el endpoint compatible con OpenAI
Autorizaciones
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.
Parámetros de ruta
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 Cuerpo
Conversation content. Each entry has an optional role (user or model) and a parts array.
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.
Respuesta
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.