Gemini Stream Inhalte generieren
Eine Anfrage über RunAPIs Gemini-kompatible Stream-Generate-Content-Operation senden.
Übersicht
Verwende RunAPI's Gemini-kompatible Stream Generate Content-Operation mit einem kompatiblen Modell sowie den Anfrage- und Antwortstrukturen des Protokolls.
Schnellstart
- Erstellen Sie einen API-Schlüssel und setzen Sie ihn als RUNAPI_API_KEY.
- Wählen Sie ein kompatibles Modell, senden Sie dann die dokumentierten Pfadparameter und den JSON-Body.
- Lesen Sie die für diesen Vorgang angezeigte JSON-Antwort oder die server-sent events und behandeln Sie Protokollfehler.
Endpunkt
- Basis-URL
https://runapi.ai- Vertragsversion
v1- Bevorzugte Authentifizierung
x-goog-api-key: YOUR_API_TOKEN
Authentifizierungsträger
RunAPI akzeptiert jeden der unten aufgeführten Träger. Generierte Beispiele verwenden den bevorzugten Header des Protokolls.
- header
Authorization: Bearer YOUR_API_TOKEN- header
x-api-key: YOUR_API_TOKEN- header - Bevorzugt
x-goog-api-key: YOUR_API_TOKEN- query
?key=YOUR_API_TOKEN
Kompatible Modelle
Öffnen Sie eine Modellseite für aktuelle Preise, Ratenlimits und Details zur kommerziellen Nutzung.
56 kompatible Modelle anzeigen
- claude-fable-5-1
- claude-fable-5
- claude-sonnet-5
- claude-opus-5
- claude-opus-4-8
- claude-opus-4-7
- claude-opus-4-6
- claude-sonnet-4-6
- claude-opus-4-5-20251101
- claude-sonnet-4-5-20250929
- claude-haiku-4-5-20251001
- claude-opus-4-1-20250805
- gpt-5.5
- gpt-5.5-pro
- gpt-5.4
- gpt-5.4-mini
- gpt-5.4-nano
- gpt-5.4-pro
- gpt-5.3-codex
- gpt-5.3-codex-spark
- gpt-5.2
- gpt-5.6-luna
- gpt-5.6-sol
- gpt-5.6-terra
- gpt-6-astra
- gemini-3.7-flash
- gemini-3.6-flash
- gemini-3.5-flash
- gemini-3.1-pro-preview
- gemini-3-flash-preview
- gemini-2.5-pro
- gemini-2.5-flash
- deepseek-v4-flash-vision-exp
- deepseek-v4-pro
- deepseek-v4-flash
- glm-5.2
- glm-5.1
- glm-5-turbo
- glm-5
- glm-4.7
- glm-4.6
- glm-4.5
- glm-4.5-air
- kimi-k3
- kimi-k2.7-code
- kimi-k2.6
- kimi-k2.5
- MiniMax-M3
- MiniMax-M2.7
- MiniMax-M2.7-highspeed
- MiniMax-M2.5
- MiniMax-M2.5-highspeed
- MiniMax-M2.1
- MiniMax-M2
- grok-4.5
- grok-4.3
Anfrage-Vertrag
Es werden nur Felder aufgeführt, für die sowohl öffentliche Protokoll- als auch RunAPI-Unterstützung belegt ist. Weitere JSON-Body-Felder werden durchgereicht.
JSON-Body4 Felder
contentsarrayGesprächsinhalt im Gemini Content and Part-Format.
generationConfigobjectGemini-Generierungskonfiguration für die Anfrage.
systemInstructionobjectSystemanweisungen als Gemini Content dargestellt.
toolsarrayTools, die das Modell aufrufen darf.
Pfadparameter1 Feld
modelstringRunAPI-Modellbezeichner, der im Wire-Pfad platziert wird.
Anfragebeispiel
{
"contents": [
{
"parts": [
{
"text": "Summarize one practical improvement for an API deployment."
}
],
"role": "user"
}
]
}
SSE-Ereignis: Chunk
Schema
{
"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"
}
Beispiel
{
"candidates": [
{
"content": {
"parts": [
{
"text": "Hello"
}
],
"role": "model"
},
"finishReason": "STOP",
"index": 0
}
],
"modelVersion": "gemini-3.5-flash",
"responseId": "resp_example",
"usageMetadata": {
"candidatesTokenCount": 8,
"promptTokenCount": 12,
"totalTokenCount": 20
}
}
Protokollfehler: invalid_request
Schema
{
"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"
}
Beispiel
{
"error": {
"code": 400,
"message": "contents is required",
"status": "INVALID_ARGUMENT"
}
}
Verwendung
Schema
{
"additionalProperties": true,
"properties": {
"candidatesTokenCount": {
"type": "integer"
},
"promptTokenCount": {
"type": "integer"
},
"totalTokenCount": {
"type": "integer"
}
},
"type": "object"
}
Beispiel
{
"candidatesTokenCount": 8,
"promptTokenCount": 12,
"totalTokenCount": 20
}
Generierte Code-Beispiele
Jedes cURL-, JavaScript- und Python-Beispiel sendet die validierte Anfrage aus diesem Vertrag, ohne ein protokollspezifisches SDK zu benötigen.
Installieren
pip install requests
import requests
response = requests.post(
"https://runapi.ai/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse",
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."}]}]},
stream=True
)
response.raise_for_status()
for line in response.iter_lines(decode_unicode=True):
if line:
print(line)