콘텐츠 생성
텍스트 생성, 멀티모달 입력, 추론, 함수 호출, Google Search 그라운딩, JSON 모드, 스트리밍을 위해 CometAPI를 통해 Gemini 네이티브 API 형식을 사용하세요.
x-goog-api-key와 Authorization: Bearer 헤더를 모두 지원합니다.빠른 시작
CometAPI와 함께 Gemini SDK 또는 HTTP 클라이언트를 사용하려면 base URL과 API key를 교체하세요:비디오 입력 전송
GeminigenerateContent는 비디오를 콘텐츠 파트로 받을 수 있습니다. 비디오가 저장된 위치에 따라 입력 형식을 선택하세요:
inlineData.mimeType 및 fileData.fileUri와 같은 Gemini의 camelCase 필드 이름을 사용하세요. URL 미디어를 file_data.file_uri로 보내지 마세요.fileData.fileUri와 함께 공개 MP4 URL을 전송합니다:
inlineData 또는 fileData.fileUri를 사용해 generateContent 요청 자체에서 전송하세요.
사고(thinking) 구성하기
Gemini 모델은 응답을 생성하기 전에 내부 추론을 수행할 수 있습니다. 제어 방식은 모델 세대에 따라 달라집니다.- Gemini 3 (thinkingLevel)
- Gemini 2.5 (thinkingBudget)
thinkingLevel을 사용해 추론 깊이를 제어합니다. 사용 가능한 수준: MINIMAL, LOW, MEDIUM, HIGH.특별히 다른 Gemini 3 변형이 필요한 경우가 아니라면 기본 예시 모델로 gemini-3-flash-preview를 사용하세요.응답 스트리밍(Streaming)
모델이 콘텐츠를 생성하는 동안 Server-Sent Events를 받으려면 연산자로streamGenerateContent?alt=sse를 사용하세요. 각 SSE 이벤트에는 JSON GenerateContentResponse 객체가 들어 있는 data: 줄이 포함됩니다.
system instructions 설정
전체 대화에 걸쳐 모델의 동작을 안내하려면systemInstruction을 사용하세요:
JSON 출력 요청
구조화된 JSON 출력을 강제하려면responseMimeType을 설정하세요. 엄격한 스키마 검증을 위해 선택적으로 responseSchema를 제공할 수 있습니다:
Google Search로 grounding하기
실시간 웹 검색을 활성화하려면googleSearch 도구를 추가하세요:
groundingMetadata가 포함됩니다.
응답 예시
CometAPI의 Gemini 엔드포인트에서 반환되는 일반적인 응답:usageMetadata의 thoughtsTokenCount 필드는 thinking output이 응답에 포함되지 않더라도 모델이 내부 추론에 사용한 토큰 수를 보여줍니다.OpenAI 호환 엔드포인트와 비교
인증
Your CometAPI key passed via the x-goog-api-key header. Bearer token authentication (Authorization: Bearer $COMETAPI_KEY) is also supported.
경로 매개변수
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 본문
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.
응답
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.