Skip to main content
POST
Native Gemini Format

Introduction

The Gemini Native API uses Google Gemini’s request and response format. It is suitable for Google official clients (e.g. the google-generativeai SDK) or when you need to work directly with Gemini data structures. The API follows the Gemini specification and supports thinking mode, multimodal input, tool calling, Google Search (Grounding), context caching, image generation, and other full capabilities.
If you use an OpenAI-compatible client (e.g. OpenAI SDK) for Gemini, see Gemini OpenAI format (Chat). For other models, use OpenAI Chat Completions.

Difference from OpenAI format

API endpoints

Replace {model} in the path with the actual model ID, e.g. gemini-2.5-pro, gemini-3-pro-preview.

Authentication

Any of the following is supported:
string
Bearer token: Bearer sk-xxxxxxxxxx (recommended, consistent with other GravitexAI endpoints)
string
Google-style API key: x-goog-api-key: sk-xxxxxxxxxx
You can also pass the key in the URL: ?key=sk-xxxxxxxxxx.

Request parameters

generateContent / streamGenerateContent

array
required
List of conversation contents. Each item has role (user or model) and parts. Each part can be: {"text": "..."}, {"inlineData": {"mimeType": "...", "data": "base64..."}}, or {"fileData": {"mimeType": "...", "fileUri": "gs://..."}}.
object
Generation config.
  • temperature: 0–2, randomness
  • topP: nucleus sampling
  • topK: top-K sampling
  • maxOutputTokens: max output tokens
  • stopSequences: stop sequences
  • responseMimeType: e.g. text/plain
  • responseModalities: e.g. ["TEXT"] or ["IMAGE"]
  • thinkingConfig: thinking mode (see below)
  • imageConfig: image generation config (see below)
object
System instruction: {"parts": [{"text": "..."}]}.
array
Safety levels, e.g. [{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "OFF"}].
array
Tool declarations (function calling), see advanced features.
object
Tool config, e.g. functionCallingConfig.mode: AUTO / ANY / NONE.
string
Context caching ID returned by the API; used to reuse cached context.

Response format

Non-streaming generateContent returns JSON:
The streaming endpoint returns SSE; each line starts with data: and contains a JSON fragment (e.g. candidates[].content.parts).

Basic examples

By default, google-generativeai calls Google’s API. To use GravitexAI, set api_endpoint to https://api.gravitex.ai via client_options or environment variables. See your SDK docs for details.

Advanced features

Thinking mode

Supported in three ways:
  1. generationConfig.thinkingConfig (Gemini 2.5 Pro): use thinkingBudget (token count)
  2. thinkingConfig.thinkingLevel (Gemini 3 Pro): use LOW / HIGH
  3. Model suffix: -thinking, -thinking-8192, -nothinking, -thinking-low, -thinking-high

Multimodal input

Mix text and media in contents[].parts:
  • Image: inlineData with base64 data, or fileData with fileUri (e.g. gs://...)
  • Audio: inlineData with mimeType such as audio/mp3

Tool calling (Function Calling)

The model may return a functionCall part; include the corresponding functionResponse in the next contents and send another request.

Google Search (Grounding)

When enabled, the model can use real-time web search to improve answers (e.g. weather, news). Add googleSearch to tools:
To use both function calling and Google Search, include googleSearch: {} and functionDeclarations as separate elements in the same tools array. Responses may include retrieval metadata (e.g. groundingMetadata).

Streaming

Use: POST /v1beta/models/{model}:streamGenerateContent?alt=sse. Request body is the same as generateContent. Response is SSE; each data: line is a JSON chunk.

Context caching

First request does not include cachedContent. If the server returns a cache ID, subsequent requests can send:
This reduces cost and latency for long repeated context.

Image generation (e.g. Gemini 2.5 Flash)

When the model supports image output, set in generationConfig:
Response candidates[].content.parts may include inlineData (e.g. base64 image).

Embedding API

Single: embedContent

Endpoint: POST https://api.gravitex.ai/v1beta/models/{model}:embedContent Request body example:
Or put model in the path: /v1beta/models/text-embedding-004:embedContent, with body containing only content.

Batch: batchEmbedContents

Endpoint: POST https://api.gravitex.ai/v1beta/models/{model}:batchEmbedContents Request body example:
Response is an array, one embedding per request.

Error handling

Errors are returned as HTTP status codes and JSON body, for example:
Common cases: Parse error.message in your client and handle retries or user messaging accordingly.

Comparison with OpenAI format

Use the native endpoint when you rely on Google Gemini tooling or need Gemini-specific fields (e.g. thinkingConfig, native multimodal parts). Use /v1/chat/completions when you want to stay within the OpenAI ecosystem.