Native Gemini Format
Chat & text
Native Gemini Format
Call GravitexAI using Google Gemini native format
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. thegoogle-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?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, randomnesstopP: nucleus samplingtopK: top-K samplingmaxOutputTokens: max output tokensstopSequences: stop sequencesresponseMimeType: e.g.text/plainresponseModalities: 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-streaminggenerateContent returns JSON:
data: and contains a JSON fragment (e.g. candidates[].content.parts).
Basic examples
- cURL (non-streaming)
- cURL (streaming)
- Python (google-generativeai)
- Node.js
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:- generationConfig.thinkingConfig (Gemini 2.5 Pro): use
thinkingBudget(token count) - thinkingConfig.thinkingLevel (Gemini 3 Pro): use
LOW/HIGH - Model suffix:
-thinking,-thinking-8192,-nothinking,-thinking-low,-thinking-high
- thinkingBudget (2.5 Pro)
- thinkingLevel (3 Pro)
Multimodal input
Mix text and media incontents[].parts:
- Image:
inlineDatawith base64data, orfileDatawithfileUri(e.g.gs://...) - Audio:
inlineDatawithmimeTypesuch asaudio/mp3
Tool calling (Function Calling)
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). AddgoogleSearch to tools:
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 includecachedContent. If the server returns a cache ID, subsequent requests can send:
Image generation (e.g. Gemini 2.5 Flash)
When the model supports image output, set ingenerationConfig:
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:
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:
Error handling
Errors are returned as HTTP status codes and JSON body, for example:
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.