OhMyGPT
Chat

Stream generated content (Gemini)

POST
/v1/models/{creator}/{model}:streamGenerateContent

The streaming form of generateContent: the same request, answered as server-sent events, each data: line one GenerateContentResponse chunk. The stream has no terminal frame, so it carries no cost comment; the request's cost is in the usage records (GET /v1/generation).

授权

headerAuthorization<token>

路径参数

creator*string

The part of the model ID before the slash (google in google/gemini-3.1-flash-lite). To pin a provider, prefix it with provider:, as in google:google.

model*string

The part of the model ID after the slash (gemini-3.1-flash-lite).

查询参数

alt?"sse"

The Google Gen AI SDKs send alt=sse. The response is server-sent events either way.

值于"sse"

请求主体

application/json
  1. body

A Gemini GenerateContentRequest as sent over REST. The model is named in the path, so the body has no model; every other field is Google's.

cachedContent?string

A cached content name (cachedContents/{id}); Gemini models only.

contents*array<>

The conversation so far; one item for a single-turn request.

generationConfig?

Configuration options for model generation and outputs. Not all parameters are configurable for every model.

labels?
safetySettings?array<>
serviceTier?GeminiServiceTier
值于"unspecified""standard""flex""priority"
store?boolean
systemInstruction?

The base structured datatype containing multi-part content of a message.

A Content includes a role field designating the producer of the Content and a parts field containing multi-part data that contains the content of the message turn.

toolConfig?

The Tool configuration containing parameters for specifying Tool use in the request.

tools?array<>

响应主体

Server-sent events; each data: line is a GenerateContentResponse chunk

text/event-stream
  1. response

Response from the model supporting multiple candidate responses.

Safety ratings and content filtering are reported for both prompt in GenerateContentResponse.prompt_feedback and for each candidate in finish_reason and in safety_ratings. The API:

  • Returns either all requested candidates or none of them
  • Returns no candidates at all only if there was something wrong with the prompt (check prompt_feedback)
  • Reports feedback on each candidate in finish_reason and safety_ratings.
candidates?array<>

Candidate responses from the model.

modelStatus?

Output only. The current model status of this model.

modelVersion?string

Output only. The model version used to generate the response.

promptFeedback?

Returns the prompt's feedback related to the content filters.

responseId?string

Output only. response_id is used to identify each response.

usageMetadata?

Output only. Metadata on the generation requests' token usage.

示例请求
curl -X POST 'https://api.ohmygpt.com/v1/models/string/string:streamGenerateContent' \  -H 'Content-Type: application/json' \  -d '{  "contents": [    {}  ]}'
示例响应
{  "candidates": [    {      "avgLogprobs": 0.1,      "citationMetadata": {        "citationSources": [          {}        ]      },      "content": {        "parts": [          {            "audioTranscription": null,            "codeExecutionResult": null,            "executableCode": null,            "fileData": null,            "functionCall": null,            "functionResponse": null,            "inlineData": null,            "mediaProcessing": "MEDIA_PROCESSING_UNSPECIFIED",            "mediaResolution": null,            "partMetadata": {              "property1": null,              "property2": null            },            "speechMetadata": null,            "text": "string",            "thought": true,            "thoughtSignature": "string",            "toolCall": null,            "toolResponse": null,            "videoMetadata": null          }        ],        "role": "string"      },      "continuationToken": "string",      "finishMessage": "string",      "finishReason": "FINISH_REASON_UNSPECIFIED",      "groundingAttributions": [        {          "content": {            "parts": [              {                "audioTranscription": null,                "codeExecutionResult": null,                "executableCode": null,                "fileData": null,                "functionCall": null,                "functionResponse": null,                "inlineData": null,                "mediaProcessing": "MEDIA_PROCESSING_UNSPECIFIED",                "mediaResolution": null,                "partMetadata": {                  "property1": null,                  "property2": null                },                "speechMetadata": null,                "text": "string",                "thought": true,                "thoughtSignature": "string",                "toolCall": null,                "toolResponse": null,                "videoMetadata": null              }            ],            "role": "string"          },          "sourceId": null        }      ],      "groundingMetadata": {        "googleMapsWidgetContextToken": "string",        "groundingChunks": [          {}        ],        "groundingSupports": [          {}        ],        "imageSearchQueries": [          "string"        ],        "retrievalMetadata": null,        "searchEntryPoint": null,        "webSearchQueries": [          "string"        ]      },      "index": 0,      "logprobsResult": {        "chosenCandidates": [          {}        ],        "logProbabilitySum": 0.1,        "topCandidates": [          {}        ]      },      "safetyRatings": [        {          "blocked": true,          "category": "HARM_CATEGORY_UNSPECIFIED",          "probability": "HARM_PROBABILITY_UNSPECIFIED"        }      ],      "tokenCount": 0,      "urlContextMetadata": {        "urlMetadata": [          {}        ]      }    }  ],  "modelStatus": {    "message": "string",    "modelStage": "MODEL_STAGE_UNSPECIFIED",    "retirementTime": "2019-08-24T14:15:22Z"  },  "modelVersion": "string",  "promptFeedback": {    "blockReason": "BLOCK_REASON_UNSPECIFIED",    "safetyRatings": [      {        "blocked": true,        "category": "HARM_CATEGORY_UNSPECIFIED",        "probability": "HARM_PROBABILITY_UNSPECIFIED"      }    ]  },  "responseId": "string",  "usageMetadata": {    "cacheTokensDetails": [      {        "modality": null,        "tokenCount": 0      }    ],    "cachedContentTokenCount": 0,    "candidatesTokenCount": 0,    "candidatesTokensDetails": [      {        "modality": null,        "tokenCount": 0      }    ],    "promptTokenCount": 0,    "promptTokensDetails": [      {        "modality": null,        "tokenCount": 0      }    ],    "serviceTier": "unspecified",    "thoughtsTokenCount": 0,    "toolUsePromptTokenCount": 0,    "toolUsePromptTokensDetails": [      {        "modality": null,        "tokenCount": 0      }    ],    "totalTokenCount": 0  }}