generateContent (Google 호환)
curl --request POST \
--url https://api.k-router.com/v1beta/models/{model}:generateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <x-goog-api-key>' \
--data '
{
"contents": [
{}
],
"generationConfig": {},
"systemInstruction": {}
}
'import requests
url = "https://api.k-router.com/v1beta/models/{model}:generateContent"
payload = {
"contents": [{}],
"generationConfig": {},
"systemInstruction": {}
}
headers = {
"x-goog-api-key": "<x-goog-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-goog-api-key': '<x-goog-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({contents: [{}], generationConfig: {}, systemInstruction: {}})
};
fetch('https://api.k-router.com/v1beta/models/{model}:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.k-router.com/v1beta/models/{model}:generateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
]
],
'generationConfig' => [
],
'systemInstruction' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-goog-api-key: <x-goog-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.k-router.com/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"contents\": [\n {}\n ],\n \"generationConfig\": {},\n \"systemInstruction\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-goog-api-key", "<x-goog-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.k-router.com/v1beta/models/{model}:generateContent")
.header("x-goog-api-key", "<x-goog-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {}\n ],\n \"generationConfig\": {},\n \"systemInstruction\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.k-router.com/v1beta/models/{model}:generateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<x-goog-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {}\n ],\n \"generationConfig\": {},\n \"systemInstruction\": {}\n}"
response = http.request(request)
puts response.read_bodyAPI Reference
generateContent (Google 호환)
Google Gemini generateContent API 호환 엔드포인트
POST
/
v1beta
/
models
/
{model}
:generateContent
generateContent (Google 호환)
curl --request POST \
--url https://api.k-router.com/v1beta/models/{model}:generateContent \
--header 'Content-Type: application/json' \
--header 'x-goog-api-key: <x-goog-api-key>' \
--data '
{
"contents": [
{}
],
"generationConfig": {},
"systemInstruction": {}
}
'import requests
url = "https://api.k-router.com/v1beta/models/{model}:generateContent"
payload = {
"contents": [{}],
"generationConfig": {},
"systemInstruction": {}
}
headers = {
"x-goog-api-key": "<x-goog-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-goog-api-key': '<x-goog-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({contents: [{}], generationConfig: {}, systemInstruction: {}})
};
fetch('https://api.k-router.com/v1beta/models/{model}:generateContent', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.k-router.com/v1beta/models/{model}:generateContent",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'contents' => [
[
]
],
'generationConfig' => [
],
'systemInstruction' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-goog-api-key: <x-goog-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.k-router.com/v1beta/models/{model}:generateContent"
payload := strings.NewReader("{\n \"contents\": [\n {}\n ],\n \"generationConfig\": {},\n \"systemInstruction\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-goog-api-key", "<x-goog-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.k-router.com/v1beta/models/{model}:generateContent")
.header("x-goog-api-key", "<x-goog-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"contents\": [\n {}\n ],\n \"generationConfig\": {},\n \"systemInstruction\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.k-router.com/v1beta/models/{model}:generateContent")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-goog-api-key"] = '<x-goog-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"contents\": [\n {}\n ],\n \"generationConfig\": {},\n \"systemInstruction\": {}\n}"
response = http.request(request)
puts response.read_bodyGoogle generateContent API
Google Gemini API와 호환되는 엔드포인트입니다. Google 네이티브 SDK를 사용하거나 직접 호출할 수 있습니다.대부분의 경우 OpenAI SDK로 전환하는 것이 더 간단합니다. 이 엔드포인트는 Google 네이티브 형식이 반드시 필요한 경우를 위한 것입니다.
엔드포인트
POST /v1beta/models/{model}:generateContent
POST /v1beta/models/{model}:streamGenerateContent
인증
kr-your-api-key. 쿼리 파라미터 ?key=kr-your-api-key로도 전달 가능합니다.요청 본문
대화 내용. 각 항목은
role (user, model)과 parts 배열을 포함합니다.생성 설정.
temperature, topP, maxOutputTokens, stopSequences 등을 포함합니다.시스템 프롬프트.
parts 배열로 전달합니다.응답
200 - 성공
{
"candidates": [
{
"content": {
"parts": [
{
"text": "안녕하세요! 무엇을 도와드릴까요?"
}
],
"role": "model"
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 15,
"totalTokenCount": 25
}
}
예시
Google 네이티브 SDK (Python)
from google import genai
client = genai.Client(
api_key="kr-your-api-key",
http_options=genai.types.HttpOptions(
api_version="v1beta",
base_url="https://api.k-router.com"
)
)
response = client.models.generate_content(
model="kr/gemini-25-pro",
contents="안녕하세요"
)
print(response.text)
cURL
# generateContent
curl -X POST "https://api.k-router.com/v1beta/models/kr%2Fgemini-25-pro:generateContent?key=kr-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "안녕하세요"}]
}
],
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 1024
}
}'
스트리밍 (cURL)
# streamGenerateContent
curl -X POST "https://api.k-router.com/v1beta/models/kr%2Fgemini-25-pro:streamGenerateContent?key=kr-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "안녕하세요"}]
}
]
}'
더 간단한 방법: OpenAI SDK를 사용하면 같은 Gemini 모델을 더 간단하게 호출할 수 있습니다.
from openai import OpenAI
client = OpenAI(api_key="kr-your-api-key", base_url="https://api.k-router.com/v1")
response = client.chat.completions.create(
model="kr/gemini-25-pro",
messages=[{"role": "user", "content": "안녕하세요"}]
)
⌘I