İçeriğe geç
API Referansı
API Referansı

Gemini İçerik Oluşturma

RunAPI'nin Gemini uyumlu Generate Content işlemi aracılığıyla bir istek gönderin.

01

Genel Bakış

RunAPI'nin Gemini uyumlu İçerik Oluşturma işlemini, uyumlu bir model ve protokolün istek ile yanıt şekilleriyle kullanın.

Hızlı başlangıç

  1. Bir API anahtarı oluşturun ve RUNAPI_API_KEY olarak ayarlayın.
  2. Uyumlu bir model seçin, ardından belgelenen yol parametrelerini ve JSON gövdesini gönderin.
  3. Bu işlem için gösterilen JSON yanıtını veya sunucu tarafından gönderilen olayları okuyun ve protokol hatalarını işleyin.

Uç Nokta

POST /v1beta/models/{model}:generateContent
Temel URL
https://runapi.ai
Sözleşme sürümü
v1
Tercih edilen kimlik doğrulama
x-goog-api-key: YOUR_API_TOKEN
02

Kimlik doğrulama taşıyıcıları

RunAPI aşağıda listelenen her taşıyıcıyı kabul eder. Oluşturulan örnekler, protokolün tercih ettiği başlığı kullanır.

header
Authorization: Bearer YOUR_API_TOKEN
header
x-api-key: YOUR_API_TOKEN
header - Tercih edilen
x-goog-api-key: YOUR_API_TOKEN
query
?key=YOUR_API_TOKEN
03

Uyumlu modeller

Güncel fiyatlandırma, hız sınırları ve ticari kullanım ayrıntıları için bir model sayfası açın.

56 uyumlu model göster
04

İstek sözleşmesi

JSON gövdesi

Yalnızca hem genel protokol hem de RunAPI destek kanıtı olan alanlar listelenmektedir. Ek JSON gövde alanları doğrudan iletilir.

JSON gövdesi4 alan
contentsarray
Zorunlu

Gemini Content ve Part biçiminde konuşma içeriği.

generationConfigobject
İsteğe bağlı

İstek için Gemini üretim yapılandırması.

systemInstructionobject
İsteğe bağlı

Gemini Content olarak temsil edilen sistem talimatları.

toolsarray
İsteğe bağlı

Modelin çağırabileceği araçlar.

Yol parametreleri1 alan
modelstring
Zorunlu

Hat yoluna yerleştirilen RunAPI model tanımlayıcısı.

İstek örneği

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

Eş zamanlı yanıt

HTTP 200

Şema

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"
}

Örnek

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

Protokol hatası: invalid_request

HTTP 400

Şema

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"
}

Örnek

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

Kullanım

Şema

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

Örnek

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

Oluşturulan Kod Örnekleri

Her cURL, JavaScript ve Python örneği, protokole özgü bir SDK gerektirmeden bu sözleşmedeki doğrulanmış isteği gönderir.

Yükle

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())