본문으로 건너뛰기
API 레퍼런스
API 레퍼런스

Gemini Generate Content

RunAPI의 Gemini 호환 Generate Content 작업을 통해 요청을 전송합니다.

01

개요

RunAPI의 Gemini 호환 Generate Content 작업을 호환 모델과 프로토콜의 요청 및 응답 형식에 맞게 사용하세요.

빠른 시작

  1. API 키를 만들고 RUNAPI_API_KEY로 설정합니다.
  2. 호환되는 모델을 선택한 후 문서화된 경로 매개변수와 JSON 본문을 전송합니다.
  3. 해당 작업에 대한 JSON 응답 또는 서버 전송 이벤트를 읽고 프로토콜 오류를 처리하세요.

엔드포인트

POST /v1beta/models/{model}:generateContent
Base URL
https://runapi.ai
계약 버전
v1
권장 인증 방식
x-goog-api-key: YOUR_API_TOKEN
02

인증 정보 전달 방식

RunAPI는 아래 나열된 각 캐리어를 허용합니다. 생성된 샘플은 프로토콜의 기본 헤더를 사용합니다.

header
Authorization: Bearer YOUR_API_TOKEN
header
x-api-key: YOUR_API_TOKEN
header - 권장
x-goog-api-key: YOUR_API_TOKEN
query
?key=YOUR_API_TOKEN
03

호환 모델

현재 가격, 속도 제한 및 상업적 이용 세부 정보는 모델 페이지를 여십시오.

호환 모델 56개 표시
04

요청 계약

JSON 본문

공개 프로토콜과 RunAPI 지원이 모두 확인된 필드만 나열됩니다. 추가 JSON 본문 필드는 그대로 전달됩니다.

JSON 본문필드 4개
contentsarray
필수

Gemini Content 및 Part 형식의 대화 콘텐츠.

generationConfigobject
선택

요청에 대한 Gemini 생성 구성.

systemInstructionobject
선택

Gemini Content으로 표현된 시스템 지침.

toolsarray
선택

모델이 호출할 수 있는 도구.

경로 매개변수필드 1개
modelstring
필수

와이어 경로에 배치된 RunAPI 모델 식별자.

요청 예시

JSON
{
  "contents": [
    {
      "parts": [
        {
          "text": "Summarize one practical improvement for an API deployment."
        }
      ],
      "role": "user"
    }
  ]
}
05

동기 응답

HTTP 200

스키마

JSON
{
  "additionalProperties": true,
  "properties": {
    "candidates": {
      "items": {
        "additionalProperties": true,
        "properties": {
          "content": {
            "additionalProperties": true,
            "properties": {
              "parts": {
                "type": "array"
              },
              "role": {
                "type": "string"
              }
            },
            "type": "object"
          },
          "finishReason": {
            "type": "string"
          },
          "index": {
            "type": "integer"
          }
        },
        "type": "object"
      },
      "type": "array"
    },
    "modelVersion": {
      "type": "string"
    },
    "responseId": {
      "type": "string"
    },
    "usageMetadata": {
      "additionalProperties": true,
      "properties": {
        "candidatesTokenCount": {
          "type": "integer"
        },
        "promptTokenCount": {
          "type": "integer"
        },
        "totalTokenCount": {
          "type": "integer"
        }
      },
      "type": "object"
    }
  },
  "type": "object"
}

예시

JSON
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Hello! How can I help today?"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "modelVersion": "gemini-3.5-flash",
  "responseId": "resp_example",
  "usageMetadata": {
    "candidatesTokenCount": 8,
    "promptTokenCount": 12,
    "totalTokenCount": 20
  }
}
06

프로토콜 오류: invalid_request

HTTP 400

스키마

JSON
{
  "additionalProperties": true,
  "properties": {
    "error": {
      "additionalProperties": true,
      "properties": {
        "code": {
          "type": "integer"
        },
        "message": {
          "type": "string"
        },
        "status": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message",
        "status"
      ],
      "type": "object"
    }
  },
  "required": [
    "error"
  ],
  "type": "object"
}

예시

JSON
{
  "error": {
    "code": 400,
    "message": "contents is required",
    "status": "INVALID_ARGUMENT"
  }
}
07

사용량

스키마

JSON
{
  "additionalProperties": true,
  "properties": {
    "candidatesTokenCount": {
      "type": "integer"
    },
    "promptTokenCount": {
      "type": "integer"
    },
    "totalTokenCount": {
      "type": "integer"
    }
  },
  "type": "object"
}

예시

JSON
{
  "candidatesTokenCount": 8,
  "promptTokenCount": 12,
  "totalTokenCount": 20
}
08

생성된 코드 샘플

각 cURL, JavaScript, Python 예제는 프로토콜별 SDK 없이도 이 계약에서 검증된 요청을 전송합니다.

설치

Shell
pip install requests
PYTHON
import requests

response = requests.post(
    "https://runapi.ai/v1beta/models/gemini-3.5-flash:generateContent",
    headers={"x-goog-api-key": "YOUR_API_TOKEN", "Content-Type": "application/json"},
    json={"contents": [{"role": "user", "parts": [{"text": "Summarize one practical improvement for an API deployment."}]}]}
)
response.raise_for_status()
print(response.json())