POST/v1beta/models/{model}:streamGenerateContent

Stream generated content (Gemini)

Google's streamGenerateContent. alt=sse is required (the google-genai SDK sends it); without it the call is a 400. The last frame carries finishReason, usageMetadata (with cost) and provider; a failure mid-stream arrives as a frame holding the Google error envelope.

認証: AuthorizationヘッダーにBearer形式のAPIキー

パスパラメータ

  • modelstring必須

    A model slug.

クエリパラメータ

  • altstring必須

    Must be sse.

リクエストボディ

  • contentsarray<object>必須

    Turns of parts: text, inlineData, public fileData URLs, functionCall, functionResponse.

  • systemInstructionobject
  • toolsarray<object>

    functionDeclarations only; Google server tools are refused.

  • toolConfigobject
  • generationConfigobject

    Sampling, maxOutputTokens, stopSequences, responseSchema or responseJsonSchema, thinkingConfig.

  • providerobject

    OpenRouter's routing-preference object, resolved against the model's own provider routes. Only tightens, never loosens, your organization's policy.

    provider
    • zdrboolean

      true serves only zero-data-retention routes for this request, or refuses with a 403 naming the excluded providers.

    • onlyarray<string>

      Keep only these providers.

    • ignorearray<string>

      Drop these providers.

    • orderarray<string>

      Try these providers first, in order; the rest stay as fallbacks.

    • allow_fallbacksboolean

      false with order serves only the listed providers; without order, only the first eligible route.

レスポンス

  • 200

    A stream of GenerateContentResponse frames.

  • 400

    Invalid request, in the Google envelope.

    レスポンス
    • errorobject
      error
      • codeinteger

        The HTTP status.

      • messagestring
      • statusstring

        For example INVALID_ARGUMENT, UNAUTHENTICATED, RESOURCE_EXHAUSTED.

      • detailsarray<object>
  • 401

    The key is missing or invalid.

    レスポンス
    • errorobject
      error
      • codeinteger

        The HTTP status.

      • messagestring
      • statusstring

        For example INVALID_ARGUMENT, UNAUTHENTICATED, RESOURCE_EXHAUSTED.

      • detailsarray<object>
  • 429

    Rate limited or out of credits. RetryInfo carries the wait when retrying helps.

    レスポンス
    • errorobject
      error
      • codeinteger

        The HTTP status.

      • messagestring
      • statusstring

        For example INVALID_ARGUMENT, UNAUTHENTICATED, RESOURCE_EXHAUSTED.

      • detailsarray<object>

リクエスト

curl "https://api.experientiallabs.ai/v1beta/models/gpt-6-luna:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"role": "user", "parts": [{"text": "Say hi."}]}]}'

レスポンス

data: {"candidates":[{"content":{"role":"model","parts":[{"text":"Hi"}]},"index":0}],"responseId":"resp_0b7e4f2a9c1d46e8b3a5f7c9e1d2b4a6","modelVersion":"gpt-6-luna"}

data: {"candidates":[{"content":{"role":"model","parts":[{"text":"!"}]},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":3,"candidatesTokenCount":2,"totalTokenCount":5,"cost":0.0000013,"is_byok":false},"responseId":"resp_0b7e4f2a9c1d46e8b3a5f7c9e1d2b4a6","modelVersion":"gpt-6-luna","provider":"openai"}

https://api.experientiallabs.ai/v1beta/models/gpt-6-luna:streamGenerateContent?alt=sse