Overview
Google provides two official SDKs —@google/genai (JavaScript / TypeScript) and google-genai (Python) — covering all Gemini API endpoints. By pointing the baseUrl to the AIHubMix gateway and replacing the API Key with your platform key, you can call native capabilities such as Interactions, Embeddings, and Context Caching that are not covered by the OpenAI-compatible layer, without modifying any business code.
Quick Start
Installation
Initialize the Client
Interactions API
Interactions is Gemini’s next-generation inference interface that returns structuredInteraction objects, supporting text generation, native image generation (Nano Banana), and multi-step reasoning. Synchronous mode (interactions.create()) is currently supported; asynchronous mode (Background Interactions: get / cancel / delete) is coming soon.
Text Generation
Callinteractions.create() to initiate inference. The returned Interaction object provides an output_text convenience property for directly accessing the model’s last text output.
Native Image Generation
Configure the output modality to image viaresponse_format. The returned Interaction object provides an output_image convenience property whose data field contains Base64-encoded image data.
response_format parameters:
| Field | Description | Possible values |
|---|---|---|
type | Output type | "image" |
aspect_ratio | Aspect ratio | "1:1" "3:4" "4:3" "9:16" "16:9" |
image_size | Output resolution | "1K" "2K" "4K" |
mime_type | Image format | "image/png" "image/jpeg" |
Streaming
Passstream: true to enable Server-Sent Events (SSE) streaming. Events arrive in the following order:
event.delta.text, and the event type field is event_type.
JavaScript
Embeddings
Obtain vector representations (embeddings) of text or multimodal content via theembedContent endpoint.
embedContent
Batch Embeddings
Pass aContent array to the contents parameter of embedContent to obtain embeddings for multiple texts in a single call:
JavaScript
Available Models and Parameters
| Model | Max Input Tokens | Default Output Dimensions | Input Modality | Notes |
|---|---|---|---|---|
gemini-embedding-2-preview | 8,192 | 3,072 (768 recommended) | Text, image, video, audio, PDF | Latest multimodal embedding model, supports outputDimensionality |
gemini-embedding-001 | 2,048 | 3,072 | Text only | Previous-generation text embedding model, supports taskType |
gemini-embedding-001 supports specifying the embedding purpose via config.taskType to optimize vector quality for specific downstream tasks:
taskType | Purpose |
|---|---|
SEMANTIC_SIMILARITY | Semantic similarity computation |
RETRIEVAL_DOCUMENT | Document indexing (retrieval target) |
RETRIEVAL_QUERY | Search query (retrieval source) |
CLASSIFICATION | Text classification |
CLUSTERING | Text clustering |
gemini-embedding-2-preview does not support the taskType parameter. Instead, specify the task type via a prefix in the prompt (e.g., search_query: ... or search_document: ...).Context Caching (Explicit Caching)
Explicit Caching allows developers to manually create, query, reference, and deleteCachedContent objects, suitable for scenarios that require reusing the same long context across multiple requests. Unlike implicit caching, explicit caching lets the application manage the lifecycle.
Explicit caching is only available for the
generateContent API. The Interactions API only supports implicit caching.Create CachedContent
Create a cache viacaches.create(). The ttl (Time-To-Live) controls the cache validity period; the cache is automatically cleared when it expires.
Reference Cache in generateContent
Passcache.name to the cachedContent (JS) or cached_content (Python) parameter to use the cache during inference. The number of cached tokens is reflected in usageMetadata.cachedContentTokenCount.
Query and Delete
Supported Capabilities Matrix
| Capability | Status | Notes |
|---|---|---|
generateContent | ✅ | Non-streaming + streaming |
systemInstruction / generationConfig | ✅ | temperature, maxOutputTokens, etc. |
Structured Output (responseSchema) | ✅ | JSON mode |
| Function Calling | ✅ | functionDeclarations tool declarations |
thinkingConfig | ✅ | Chain-of-thought output |
| Multimodal input | ✅ | Image / audio / video / PDF via inlineData + Files API |
| Google Search Grounding | ✅ | Search-augmented generation |
countTokens | ✅ | Token counting |
Imagen (generateImages) | ✅ | Imagen 3 image generation |
Veo (generateVideos) | ✅ | Video generation |
| TTS | ✅ | Text-to-speech output |
| Files API | ✅ | Large file upload and reference |
| Interactions API | ✅ | Next-gen inference interface (text + Nano Banana image generation) |
Embeddings (embedContent) | ✅ | Native vector embeddings |
| Context Caching CRUD | ✅ | Explicit cache management |
| Live API (WebSocket) | ❌ | Not yet supported |
FAQ
interactions.create() returns a legacy schema error
interactions.create() returns a legacy schema error
The SDK version is too old.
@google/genai must be >= 2.0.0, and google-genai must be >= 2.0.0. Run npm install @google/genai@latest or pip install -U google-genai to upgrade to the latest version.Model returns 404 Not Found
Model returns 404 Not Found
Some early model names (e.g.,
gemini-2.5-flash-image-preview) have been retired from the Interactions API. Use currently available model identifiers such as gemini-3.1-flash-image (Nano Banana 2). The generateContent API is not affected.response_modalities returns 400 Bad Request
response_modalities returns 400 Bad Request
The Interactions API requires
response_modalities values to be lowercase ("text", "image"). Uppercase "TEXT" / "IMAGE" is the generateContent API convention and is not accepted in the Interactions API.Can I use vertexai: true?
Can I use vertexai: true?
No. The SDK’s
vertexai: true mode requires GCP OAuth + project / location parameters, which are mutually exclusive with apiKey (the SDK throws Project/location and API key are mutually exclusive). When accessing through AIHubMix, use the Gemini Developer API form — the backend routes automatically.Cache creation returns 'context caching is not available for model'
Cache creation returns 'context caching is not available for model'
The gateway blocks
caches.create() requests for models without configured storage pricing to prevent storage cost leakage. Mainstream models (gemini-2.5-flash, gemini-2.5-pro, etc.) are already configured; if you encounter this error, verify that the model supports explicit caching.Last updated: 2026-07-07