Skip to main content

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

The Interactions API requires @google/genai >= 2.0.0 or google-genai >= 2.0.0. Requests from older SDK versions will be rejected by Google’s backend (legacy Interactions schema no longer supported).

Initialize the Client

The baseUrl is always https://aihubmix.com/gemini, which differs from the OpenAI-compatible endpoint https://aihubmix.com/v1.

Interactions API

Interactions is Gemini’s next-generation inference interface that returns structured Interaction 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

Call interactions.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 via response_format. The returned Interaction object provides an output_image convenience property whose data field contains Base64-encoded image data.
  • Recommended model: gemini-3.1-flash-image (Nano Banana 2, general-purpose image generation model).
  • response_modalities values must be lowercase ['text', 'image']; uppercase is the generateContent API convention and will return 400 in the Interactions API.
  • Do not pass delivery: 'inline' (400 Image delivery mode is not supported) — the Interactions API returns image data inline by default.
response_format parameters:

Streaming

Pass stream: true to enable Server-Sent Events (SSE) streaming. Events arrive in the following order:
Incremental text is obtained via event.delta.text, and the event type field is event_type.
JavaScript

Embeddings

Obtain vector representations (embeddings) of text or multimodal content via the embedContent endpoint.
For the OpenAI-compatible /v1/embeddings endpoint, see Embeddings.

embedContent

Batch Embeddings

Pass a Content array to the contents parameter of embedContent to obtain embeddings for multiple texts in a single call:
JavaScript

Available Models and Parameters

gemini-embedding-001 supports specifying the embedding purpose via config.taskType to optimize vector quality for specific downstream tasks:
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 delete CachedContent 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.
Models without configured storage pricing will have cache creation requests blocked by the gateway (context caching is not available for model) to prevent storage cost leakage. Mainstream models (gemini-2.5-flash, gemini-2.5-pro, etc.) are already configured.

Create CachedContent

Create a cache via caches.create(). The ttl (Time-To-Live) controls the cache validity period; the cache is automatically cleared when it expires.

Reference Cache in generateContent

Pass cache.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


FAQ

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.
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.
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.
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.
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