Gemini Interactions API 入门:首调、多轮与 Google Search 工具

按 Google AI 官方 Getting Started(Interactions API),在 AI Studio 取 Key,用 pip/npm/curl 完成首次 interactions.create;再跑通 previous_interaction_id 多轮对话与 google_search 工具调用。模型示例与官方一致用 gemini-3.8-flash;含可抄命令与对照结果。

入门2 课时40 分钟图文实操

免费学习无需登录

Gemini Interactions API 入门:首调、多轮与 Google Search 工具 课程封面

你将学会

  • 在 Google AI Studio 创建 GEMINI_API_KEY,并用 pip install -U google-genai(或 curl REST)对 gemini-3.8-flash 完成首次 interactions.create
  • 用 previous_interaction_id 做服务端托管的多轮对话,理解 status=completed 与 output_text 对照结果
  • 给 Interaction 挂上 tools=[{"type":"google_search"}],读出带引用的回答,并知道 function calling 的下一步入口

适合谁

  • 要从 generateContent 迁到官方推荐 Interactions API 的应用开发者
  • 需要在 Python / Node / curl 里快速打通 Gemini 的后端与 Agent 工程师
  • 想在产品里接 Google Search grounding 与多轮状态的中文开发者

课前准备

  • 本机有 Python 3.9+(或 Node.js 18+);会用终端与环境变量
  • 能访问 aistudio.google.com 创建免费 API Key(本课不要求付费档,但免费档有速率限制)
  • 了解基本 HTTP / JSON;不要求已学过旧版 generateContent

课程目录

2 课时 · 40 分钟
  1. 01首调:AI Studio Key、SDK 安装与 interactions.create在 AI Studio 取 Key,设置 GEMINI_API_KEY;用 Python google-genai / curl REST 对 gemini-3.8-flash 发起首次 Interaction,核对 status、output_text 与 usage。图文18 分钟开始本课
  2. 02多轮对话与工具:previous_interaction_id + google_search用 previous_interaction_id 做服务端多轮;挂 Google Search 工具并读 citations;附官方 function calling 最小循环骨架。图文22 分钟开始本课

课程说明

本课按 Google AI 官方 Interactions API Getting Started 整理成中文可跟做讲义,不是原文搬运。

来源:Getting started(Interactions API)Gemini API 总览AI Studio quickstartInteractions overview。取 Key:AI Studio API keys

官方说明:自 2026 年 6 月起 Interactions API 已成为默认接口,新项目应优先使用;旧的 generateContent 仍可用但属 legacy。本课两课你会做完:用 GEMINI_API_KEY + google-genai(或 curl)对 gemini-3.8-flash 完成首次 interactions.create;再用 previous_interaction_id 做多轮,并挂上 google_search 工具读出带引用的回答。