Skip to content

feat(quickstarts-js): migrate Get_Started.js to Interactions API - #1413

Open
Giom-V wants to merge 3 commits into
google-gemini:mainfrom
Giom-V:sync-js-get-started
Open

Giom-V wants to merge 3 commits into
google-gemini:mainfrom
Giom-V:sync-js-get-started

Conversation

@Giom-V

@Giom-V Giom-V commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR migrates quickstarts-js/Get_Started.js to the Interactions API (ai.interactions), bringing it fully on par with the Python quickstart (quickstarts/Get_started.ipynb).

Key Migrations & Updates:

  • Interactions API Migration (ai.interactions):
    • Replaced legacy ai.models.generateContent with ai.interactions.create across text, multimodal, image generation, streaming, code execution, and grounding workflows.
    • Multi-turn conversation state is managed natively server-side using previous_interaction_id.
    • Added model switching mid-conversation across turns (MODEL_ID -> gemini-nano-banana-2.1).
    • Added conversation persistence: saving full interaction history via ai.interactions.get traversal and resuming with saved_steps.
  • Reasoning & Thought Inspection:
    • Control thinking depth using thinking_level ("high", "minimal", etc.) in generation_config.
    • Inspect internal reasoning steps (step.type === "thought") and access cryptographic step.signature.
  • Structured Outputs:
    • Migrated JSON generation to response_format: { type: "text", mime_type: "application/json", schema: ... }.
  • Tools & Grounding:
    • Enforced Interactions API tool schemas: { type: "google_search" }, { type: "google_maps" }, { type: "code_execution" }, and { type: "function", ... }.
    • Two-step tool calling loop handling function_call steps and returning function_result input steps.
  • Model Utilities (Non-interaction):
    • Token counting with ai.models.countTokens.
    • Embeddings (text and multimodal) with ai.models.embedContent using gemini-embedding-2.
    • Context caching: Documented automatic implicit caching server-side in Interactions API, alongside explicit caching via ai.caches.create for shared multi-session caches.
  • Deprecations:
    • Removed deprecated sampling parameters (temperature, top_k, top_p).

- Add Thinking controls (includeThoughts and thinkingBudget)
- Remove deprecated sampling parameters (temperature, topP, topK)
- Add Google Search and Google Maps grounding
- Add Context Caching workflow (create, list, query, delete)
- Add Text and Multimodal Embeddings with gemini-embedding-2
- Add Gemini 3 section (thinking levels, media resolution, thought signatures, migration guide)
- Modernize model selector with gemini-3.8-flash default
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request aligns the JavaScript quickstart guide with the existing Python documentation, ensuring feature parity across SDKs. It introduces advanced Gemini API capabilities, including support for thinking models, grounding, context caching, and embeddings. Additionally, the update modernizes the code by removing deprecated parameters and providing a clear migration path for users transitioning to Gemini 3.

Highlights

  • Thinking Process Controls: Added thinkingConfig examples to demonstrate how to inspect thought summaries and disable thinking on Flash models.
  • Grounding Integration: Implemented end-to-end examples for Google Search and Google Maps grounding, including retrieval configuration and source attribution.
  • Context Caching: Added full lifecycle management for context caching, covering creation, listing, querying, and deletion.
  • Embeddings: Introduced examples for generating text and multimodal embeddings using the gemini-embedding-2 model.
  • Gemini 3 & Migration: Added documentation and code samples for Gemini 3 features like thinkingLevel and mediaResolution, along with migration tips from Gemini 2.5.
  • Parameter Cleanup: Removed deprecated sampling parameters such as temperature, top_k, and top_p to encourage the use of model defaults.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added the status:awaiting review PR awaiting review from a maintainer label Oct 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the JavaScript quickstart guide to showcase new features of the Google GenAI SDK, including model parameter configuration, thinking process control, Google Search and Maps grounding, context caching, text and multimodal embeddings, and Gemini 3 features. It also updates the default model to gemini-3.8-flash and removes deprecated sampling parameters. The review feedback highlights several instances where iterating over response.candidates[0].content.parts directly could lead to runtime errors if the API returns an empty candidate list. It is recommended to use optional chaining and a fallback array to safely handle these scenarios.

Comment thread quickstarts-js/Get_Started.js Outdated
Comment thread quickstarts-js/Get_Started.js Outdated
Comment thread quickstarts-js/Get_Started.js Outdated
@Giom-V
Giom-V requested a review from kkorpal October 7, 2026 14:20
@Giom-V Giom-V changed the title feat(quickstarts-js): align Get_Started.js with Python quickstarts feat(quickstarts-js): migrate Get_Started.js to Interactions API Oct 9, 2026
type: "image",
data: imageDataUrl,
mime_type: "image/png",
media_resolution: "media_resolution_low",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

media_resolution: "media_resolution_low" isn't a field on ImageContent the type defines resolution?: "low" | "medium" | "high" | "ultra_high". Currently it's silently ignored.

console.log(response.text);
for (const step of interaction.steps) {
if (step.type === "thought") {
console.log("💭 Thought:", step.text || "(thinking...)");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ThoughtStep has no text field, only summary and signature, so this always prints the fallback. Should be step.summary?.[0]?.text, with thinking_summaries: "auto" added to generation_config.

and https://en.wikipedia.org/wiki/Apollo_12
`;

interaction = await ai.interactions.create({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ai.interactions.create call below has no tools: [{ type: "url_context" }], so the model answers from its own knowledge rather than fetching the pages.

---
for await (const chunk of stream) {
if (chunk.delta?.text) {
process.stdout.write(chunk.delta.text);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.stdout.write is Node-only and probably fails in the browser applet. No other JS quickstart uses it; console.log would match the rest.

@kkorpal kkorpal self-assigned this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:awaiting review PR awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants