콘텐츠 생성
CometAPI를 통해 Gemini 네이티브 API 형식으로 텍스트 생성, 동영상 입력, 사고 요약, Google Search 그라운딩, JSON 출력 및 스트리밍(Streaming)을 사용합니다.
gemini-3.8-flash을 사용합니다.
x-goog-api-key 및 Authorization: Bearer 헤더를 모두 지원합니다.빠른 시작
Google Gen AI SDK 또는 HTTP 클라이언트를 CometAPI와 함께 사용하려면 기본 URL과 API 키를 구성하세요:generateContent 요청 형식을 유지하세요.
동영상 입력 전송
동영상을 콘텐츠 파트로 전송합니다. 동영상 저장 위치에 따라 입력 형식을 선택하세요:inlineData.mimeType 및 fileData.fileUri처럼 camelCase 필드 이름을 사용하세요.<base64-encoded-mp4>을 동영상의 base64 콘텐츠로 바꾸세요:
사고 설정 (추론)
thinkingConfig.thinkingLevel을 사용하여 추론 깊이를 조정하세요. 아래 예시에서는 LOW 및 MEDIUM을 사용합니다.
- 사고 수준
- 사고 요약
LOW로 설정합니다:thinkingBudget 는 Gemini 2.5를 포함한 호환 모델용 숫자 제어값입니다. Gemini 3 예시에서는 thinkingLevel을 사용하고 두 제어값을 모두 전송하지 마세요. 모델별 값은 Google의 사고 가이드 에서 확인하세요.응답 스트리밍
Server-Sent Events를 수신하려면streamGenerateContent?alt=sse을 사용하세요. 각 data: 줄에는 JSON GenerateContentResponse 객체가 포함됩니다:
시스템 지침 설정
응답을 안내하려면systemInstruction을 사용하세요. 이 예시에서는 추가 텍스트 없이 하나의 방정식을 요청합니다:
JSON 출력 요청
responseMimeType을 application/json로 설정하고 responseSchema을 제공하세요. 이 예시에서는 이름과 숫자 거리를 포함하는 행성 배열을 요청합니다:
Google Search로 그라운딩
검색 그라운딩을 요청하려면googleSearch 도구를 추가합니다. 이 예제는 UEFA EURO 2024 결승전 결과를 요청합니다:
groundingMetadata에서 검색 쿼리, 소스 URL, 소스와 응답 텍스트 간의 링크를 검사합니다.
대화 콘텐츠 유지
다중 턴 대화에서는 앞선user 및 model 콘텐츠를 contents에 전송합니다. SDK 채팅 예제는 이 기록을 자동으로 유지합니다.
함수 호출의 경우 각 functionResponse에 대해 일치하는 functionCall 및 반환된 name를 포함하는 id 하나를 반환합니다. 앞선 모델 콘텐츠는 thoughtSignature 필드를 포함해 변경하지 않고 다시 전달합니다. 서명은 불투명하므로 표시된 텍스트에서 재구성하지 마세요.
응답 예제
텍스트 응답에는 생성된 콘텐츠와 토큰(Token) 사용량이 포함됩니다. 이 축약된 예제에서는 선택적 필드를 생략합니다:thoughtsTokenCount 응답에 사고 요약이 포함되지 않은 경우에도 내부 사고 토큰(Token)을 보고합니다. 각 콘텐츠 부분을 검사하세요. 응답에는 텍스트, 요약 또는 함수 호출(Function Calling)이 포함될 수 있습니다.요청 형식 비교
Gemini 요청 및 응답 필드에는 네이티브 엔드포인트를 선택하세요. 자세한 내용은 채팅 완성 의 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. These examples use gemini-3.8-flash. See the Models page for available model IDs.
Operation to perform. Use generateContent for a JSON response. For Server-Sent Events, select streamGenerateContent and set the separate alt query parameter to sse.
generateContent, streamGenerateContent 쿼리 매개변수
Set to sse when the operator is streamGenerateContent. Omit this parameter for generateContent.
sse 본문
Conversation content. Each entry has an optional role (user or model) and a parts array. For tool results, preserve the complete preceding model content, including any thoughtSignature fields.
System instructions that guide the model's behavior across the entire conversation. Text only.
Tools available to the model during generation. Use googleSearch for search grounding.
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.