Skip to content

Gemini Generate Content

/v1beta/models/{model}:generateContent is the Gemini-style protocol route on OmniRouters.

Use it when you already work with Gemini request bodies and want to preserve the contents / parts payload structure.

Official Documentation

OmniRouters Notes

There are a few important OmniRouters-specific differences:

  1. Authentication uses OmniRouters bearer auth, not x-goog-api-key
  2. The OmniRouters route lives under https://omnirouters.com/v1beta/...
  3. The current OmniRouters OpenAPI description notes that media uploads should use inlineData base64 content rather than fileData.fileUri
text
Authorization: Bearer <your-api-key>

All models can still be called through the OpenAI-compatible protocol. Choose Gemini Generate Content when preserving Gemini request structure is more important than using one universal request style.

Minimal Example

bash
curl https://omnirouters.com/v1beta/models/gemini-2.5-flash:generateContent \
  -H "Authorization: Bearer $OMNIROUTERS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash",
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Summarize OmniRouters in three concise bullets."
          }
        ]
      }
    ]
  }'

Common Fields

FieldRequiredPurpose
modelYesGemini-compatible model name enabled in your OmniRouters account
contentsYesThe Gemini-style content array
partsYesMessage parts such as text or inlineData
generationConfigNoSampling, max tokens, and output formatting
systemInstructionNoModel behavior guidance
safetySettingsNoSafety filter configuration

Request Body Parameters

In Gemini-native protocol, the OpenAI/Claude idea of messages maps to contents. Each contents[] object represents one message turn, and every message is composed of one or more parts[]. The current OmniRouters OpenAPI schema allows the model name in both the path and request body; keep them consistent.

FieldTypeRequiredDescription
modelstringYesGemini model name. It also appears in the path, for example /v1beta/models/gemini-2.5-flash:generateContent. Keep the body value aligned with the path.
contentsarrayYesGemini-style message array. Single-turn requests usually have one user content; multi-turn conversations include prior user and model contents.
generationConfigobjectNoGeneration configuration, including sampling, max output tokens, response MIME type, and JSON Schema. See ExtraContent below.
systemInstructionobjectNoSystem instruction. The current OpenAPI schema declares { "parts": [{ "text": "..." }] }.
safetySettingsarrayNoSafety filtering settings. Configure thresholds by harm category.
toolsarrayGemini-native fieldFunction calling, code execution, and other tool definitions. The current generic OmniRouters OpenAPI schema does not expand this field; validate support before relying on it.
toolConfigobjectGemini-native fieldTool invocation configuration, such as function-calling mode.
cachedContentstringGemini-native fieldReference to cached context, typically shaped like cachedContents/{id}. Platform support may vary.

contents Object Structure

FieldTypeRequiredDescription
rolestringYesMessage role. Common values are user for user input and model for model history. Defaults can be treated as user when omitted by higher-level SDKs.
partsPart[]YesContent parts. Text, images, audio, video, PDFs, tool calls, and tool results are all represented as Parts.

Multi-turn example:

json
{
  "contents": [
    {
      "role": "user",
      "parts": [{ "text": "Remember: the project codename is Aurora." }]
    },
    {
      "role": "model",
      "parts": [{ "text": "Got it." }]
    },
    {
      "role": "user",
      "parts": [{ "text": "What is the project codename?" }]
    }
  ]
}

Part Object Structure

The current OmniRouters OpenAPI schema explicitly declares Gemini Parts with text, inlineData, and fileData. For media uploads, OmniRouters specifically recommends inlineData with base64 content; fileData.fileUri and the Gemini File API are currently not supported on this route.

Part typeShapeSupportDescription
Text{ "text": "..." }SupportedText prompt, question, instruction, or system instruction content.
Inline file{ "inlineData": { "mimeType": "image/png", "data": "..." } }SupportedDirect base64 file content. Works for images, PDFs, audio, video, and similar supported media.
File reference{ "fileData": { "mimeType": "...", "fileUri": "..." } }Currently unsupportedGemini-native file reference via File API or gs://. On OmniRouters, use inlineData instead.
Function call{ "functionCall": { "name": "...", "args": {...} } }Model-dependentGemini-native tool-call output. Not expanded in the generic OpenAPI schema.
Function response{ "functionResponse": { "name": "...", "response": {...} } }Model-dependentTool result returned to the model by your application.
Executable code{ "executableCode": { "language": "...", "code": "..." } }Model-dependentGemini code-execution related content.
Code execution result{ "codeExecutionResult": { "outcome": "...", "output": "..." } }Model-dependentResult from a code-execution tool.

inlineData object:

FieldTypeRequiredDescription
mimeTypestringYesFile MIME type, such as image/png, image/jpeg, audio/mp3, audio/wav, video/mp4, or application/pdf.
datastringYesBase64-encoded file content. Do not include a data:...;base64, prefix unless the target model documentation explicitly allows it.

ExtraContent Object Structure

Gemini extension configuration mainly lives in generationConfig, systemInstruction, and safetySettings:

Object / fieldTypeDescription
generationConfig.temperaturenumberRandomness control. Current OpenAPI range is 0.0 to 2.0, default 1.
generationConfig.topPnumberNucleus sampling parameter, range 0 to 1, default 0.95.
generationConfig.topKintegerLimits candidate tokens, default 40, minimum 1.
generationConfig.maxOutputTokensintegerMaximum output tokens, default 8192, minimum 1.
generationConfig.responseMimeTypestringResponse MIME type, such as text/plain or application/json.
generationConfig.responseSchemaobjectJSON Schema for structured output when responseMimeType is application/json.
systemInstruction.parts[]Part[]System instruction content. Text Parts are recommended in the current schema.
safetySettings[].categorystringSafety category. Current OpenAPI values include HARM_CATEGORY_HARASSMENT, HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, and HARM_CATEGORY_DANGEROUS_CONTENT.
safetySettings[].thresholdstringBlocking threshold. Current OpenAPI values include BLOCK_NONE, BLOCK_ONLY_HIGH, BLOCK_MEDIUM_AND_ABOVE, and BLOCK_LOW_AND_ABOVE.
generationConfig.responseModalitiesstring[]Extension used by image/audio generation models, such as TEXT, IMAGE, or AUDIO. Generic text/vision calls usually do not need it.
generationConfig.imageConfigobjectImage-generation extension, such as aspectRatio and image_size. Only relevant models support it.

JSON output example:

json
{
  "generationConfig": {
    "responseMimeType": "application/json",
    "responseSchema": {
      "type": "object",
      "properties": {
        "summary": { "type": "string" },
        "tags": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "required": ["summary"]
    }
  }
}

Response Body Parameters

Non-streaming requests usually return a GenerateContentResponse object:

FieldTypeDescription
candidatesarrayCandidate responses. Usually contains at least one candidate; if the prompt is blocked, there may be no candidates and promptFeedback should be inspected.
candidates[].indexintegerCandidate index.
candidates[].contentobjectCandidate content, using the same Content shape as the request.
candidates[].content.rolestringUsually model.
candidates[].content.partsPart[]Output parts. Text responses usually appear in parts[].text.
candidates[].finishReasonstringWhy generation stopped, such as natural stop, token limit, or safety filtering.
candidates[].finishMessagestringAdditional explanation for the finish reason. Not always returned.
candidates[].safetyRatingsarraySafety categories and confidence for the candidate.
candidates[].citationMetadataobjectCitation metadata, when citations are returned.
candidates[].groundingMetadataobjectGrounding or retrieval metadata, depending on model and tool support.
candidates[].avgLogprobsnumberAverage log probability for the candidate, when supported.
candidates[].logprobsResultobjectDetailed token log probability result, when supported.
promptFeedbackobjectPrompt-level safety feedback. Check this first when there are no candidates.
promptFeedback.blockReasonstringReason the prompt was blocked.
promptFeedback.safetyRatingsarrayPrompt safety ratings.
usageMetadataobjectToken usage metadata.
usageMetadata.promptTokenCountintegerInput token count.
usageMetadata.candidatesTokenCountintegerCandidate output token count.
usageMetadata.totalTokenCountintegerTotal token count.
usageMetadata.cachedContentTokenCountintegerCached-content token count, when passed through.
usageMetadata.thoughtsTokenCountintegerThinking/reasoning token count, when passed through by reasoning models.
usageMetadata.promptTokensDetailsarrayInput token breakdown by modality.
usageMetadata.candidatesTokensDetailsarrayOutput token breakdown by modality.

Common finishReason values:

ValueMeaningHandling
STOPNormal stop.Read candidates[0].content.parts.
MAX_TOKENSThe output hit maxOutputTokens.Increase maxOutputTokens or ask the model to continue.
SAFETYStopped because of safety filtering.Inspect safetyRatings; do not blindly replay the same request.
RECITATIONStopped because of potential recitation/copyright risk.Adjust the prompt toward summary or original wording.
OTHEROther reason.Inspect finishMessage and platform logs.

For streaming interfaces, Gemini-native responses arrive as multiple incremental responses. Each response may contain partial candidates[].content.parts; clients should concatenate text by candidate index and part order.

When to Use This Route

Use this route if:

  • you are migrating an existing Gemini integration
  • your application already uses contents / parts
  • you want Gemini-style multimodal payloads

When Another Route May Be Better