npx skills add ...
npx skills add google/skills --skill gemini-interactions-api
Guides the usage of Gemini Interactions API on Gemini Enterprise Agent Platform. Use when the user wants to use the stateful, server-managed Interactions API for multi-turn conversations, background execution, streaming, structured output, and function calling on the Agent Platform.
npx skills add google/skills --skill gemini-interactions-api
This skill provides instructions for authenticating, connecting to, and utilizing the stateful, server-managed Gemini Interactions API on Gemini Enterprise Agent Platform.
The Interactions API is the modern, recommended way to execute Generative AI agent conversations, background research tasks, multi-turn chats, and structured, multi-step workflows.
[!IMPORTANT] CRITICAL: Unified SDK, Latest Models & GEAP Targeting * Unified SDK: Use the Google Gen AI SDK (
google-genai >= 2.3.0for Python,@google/genai >= 2.3.0for JS/TS). SDK versions>= 2.0.0are the minimum floor at which the steps schema activates, but>= 2.3.0is the supported/recommended floor. Legacy SDKs likegoogle-cloud-aiplatform,@google-cloud/vertexai, andgoogle-generativeaiare strictly unsupported for Interactions. * Mandatory Instruction: When explaining client initialization or writing import code, you must explicitly state/warn the user that legacy packages likegoogle-cloud-aiplatformorgoogle-generativeaiare strictly unsupported for interactions. * Latest Models Only: Usegemini-3.5-flash(fast, balanced, multimodal — the recommended default),gemini-3.1-pro-preview(complex reasoning, coding, research), orgemini-3.1-flash-lite(cost-efficient, high-frequency lightweight tasks). Refer to the latest model versions to check for new updates. Legacy models (gemini-3-flash-preview,gemini-2.5-*,gemini-2.0-*,gemini-1.5-*) are deprecated and do not support interactions. * Mandatory Instruction: In any interaction response, you must warn the user that legacy models likegemini-2.5-*,gemini-2.0-*, orgemini-1.5-*are deprecated and unsupported for the Interactions API. * GEAP requires a provisioned agent (no direct base-model calls yet): On Gemini Enterprise Agent Platform (GEAP), direct/base-model calls (model="...") via the Interactions API are not supported yet. You must target a provisioned agent or endpoint with theagent="<AGENT_ID>"parameter instead ofmodel="...". The code examples in this skill useagent=...for this reason. (This is the primary difference from the ai.google.dev documentation for Interactions, which usesmodel=...— whilemodel=...is valid for other Gemini API contexts, it is not supported on the Agent Platform.) Provision an agent per the Agent Platform docs and pass its ID asagent. * Turn-Scoped Parameters: Parameters liketools,system_instruction, andgeneration_configare turn-scoped. They MUST be passed with each interaction request.
Before running any code, ensure you are authenticated with Application Default Credentials (ADC) and have the necessary API enabled.
Login:
Enable API (if not already enabled):
You can initialize the client using environment variables (recommended) or by passing explicit configuration parameters.
Configure environment variables to let the SDK automatically resolve settings:
Alternatively, pass configuration values directly inside your code:
Submit a single prompt and read the final text response. Under the modern schema, output content is retrieved from the steps list.
Interactions are stateful by default. Store the conversation state in the cloud and reference it in the subsequent turn using previous_interaction_id.
Stream responses in real-time. Passing stream=True returns an iterable chunk generator.
response_format)Retrieve structured, type-safe JSON matching a schema. Under the modern Interactions API, a polymorphic response_format argument directly takes the target schema structure.
Define local tools (functions) and submit execution results to the stateful interaction history.
For shell-based scripts, debugging, or non-Python/JS environments, you can communicate with the stateful Interactions API directly using raw HTTP/REST requests via curl.
The REST API endpoint for interactions is:
global (or custom region if required).Set your target agent ID (e.g., model or custom agent path) and access token generated from Application Default Credentials:
Send a request to start an interaction using the agent variable:
A synchronous POST request returns a JSON object containing the conversation step details and unique identifiers:
To continue an existing conversation statefully, specify the previous_interaction_id in the JSON payload:
To stream updates in real time (Server-Sent Events format), pass "stream": true in the payload:
The endpoint will return a chunked stream where each event begins with data: containing JSON updates with the event_type and step contents.
How
curlhandles streaming: By default, when"stream": trueis passed, the server responds withTransfer-Encoding: chunkedandContent-Type: text/event-stream(Server-Sent Events).curlwill automatically keep the connection open and print the incoming data chunks tostdoutin real time as they are pushed by the server. The user does not need to poll or pull further; the complete sequence of events streams continuously until completion.
An Interaction response contains steps, an array of typed step objects
representing a structured timeline of the interaction turn. Read the current
step type rather than assuming the last step is text — the trailing step may
be a function_call or a thought.
User steps:
user_input: User input (text, audio, multimodal). Contains a content
array. (This is why REST input payloads use "type": "user_input", not
"role": "user".)Model/server steps:
model_output: Final model generation. Contains a content array with
text, image, audio, etc. (REST responses use "type": "model_output",
not "role": "model".)thought: Model reasoning / chain of thought. Has a signature field and
optional summary.function_call: Tool call request, with flat id, name, and arguments
fields (there is no nested tool_calls list).function_result: Tool result you send back, with call_id, name, and
result fields.google_search_call / google_search_result, code_execution_call /
code_execution_result, url_context_call / url_context_result,
mcp_server_tool_call / mcp_server_tool_result, file_search_call /
file_search_result: built-in and remote tool steps.content array on model_output and user_input steps)text: Text content (text field).image / audio / document / video: Content with data, mime_type,
or uri.output_text: The combined text from the trailing model_output steps.
Prefer this over hand-walking steps[-1].content[0].text, which breaks when
the last step is a tool call or a thought.| Event | Description |
|---|---|
interaction.created | Interaction created; includes metadata. |
step.start | A new step begins. Contains the step type and |
| : : initial metadata. : | |
step.delta | Incremental data for the current step. Contains a |
: : typed delta object (e.g. delta.type == "text" : | |
: : with delta.text). : | |
step.stop | The step is complete. Contains index. |
interaction.completed | Interaction finished. Contains final usage. |
Interactions are stored by default (store=True), which enables stateful
features like previous_interaction_id and background execution. Passing
store=False disables server-side retention and therefore also disables
previous_interaction_id and background — in that mode you must pass the full
conversation history in input on each turn.