2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Google I/O 2025】 API の無料枠で Gemini・Gemma の新モデルを試す(Node.js を利用)

Last updated at Posted at 2025-05-21

はじめに

以下の記事に書いていた内容に引き続き、Google I/O 2025 で発表された話のお試しをやっていきます。

●Gemini API & SDK が MCP 対応したので試す(Node.js を利用)【Google I/O 2025】 - Qiita
 https://qiita.com/youtoy/items/fd1b123c3f7fc3516264

今回の内容

今回は、上記の記事の最後に少し触れていた「Gemini・Gemma の新モデル」のお試しです。これらを Node.js を使って、API経由で試します。

image.png

ちなみに、API の無料枠でのお試しです。

今回試すモデル

今回試すモデルは、Gemini 2.5 Flash Preview の新バージョン(05-20)と、Gemma の新モデル(3n)です。

  • モデル名(上記の Google AI Studio でも表示されている名称)
    • gemini-2.5-flash-preview-05-20
    • gemma-3n-e4b-it

それら公式のモデル情報は、以下の URL になります。

Gemini 2.5 Flash プレビュー

https://ai.google.dev/gemini-api/docs/models?hl=ja#gemini-2.5-flash-preview
image.png

Gemma 3n

https://ai.google.dev/gemma/docs/gemma-3n
image.png

Node.js で API を使う

Node.js で API を使って以下のモデルを試します。

  • gemini-2.5-flash-preview-05-20
  • gemma-3n-e4b-it

下準備

今回、Node.js のパッケージで、過去の Gemini のお試しでもよく使っている以下を用います(※ npm install @google/genai でインストール )。

●@google/genai - npm
 https://www.npmjs.com/package/@google/genai

それと、Gemini の APIキーを環境変数 GEMINI_API_KEY にセットしておきます。

コードと実行結果

Node.js のコードは、過去の Gemini のお試しでも用いた以下をベースにしました。
gemini-2.5-flash-preview-04-17 を試した時などにも使ったもの

import { GoogleGenAI } from "@google/genai";
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;

const ai = new GoogleGenAI({ apiKey: GEMINI_API_KEY });

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash-preview-05-20",
    // model: "gemma-3n-e4b-it",
    contents: "なぜ空は青い?",
  });
  console.log(response.text);
}

main();

あとは API を使った処理を実行してみます。

実行結果1: gemini-2.5-flash-preview-05-20

gemini-2.5-flash-preview-05-20 を用いて得られたレスポンスは以下のとおりです。

image.png

無料枠で API を使うこともできています。

実行結果2: gemma-3n-e4b-it

次に gemma-3n-e4b-it を使って同じ処理を試してみます。こちらも無料枠で API を使うことができました。

image.png

おわりに

とりあえず、API の無料枠で Gemini・Gemma の新モデル(以下 2つ)を試せました。

  • gemini-2.5-flash-preview-05-20
  • gemma-3n-e4b-it

上記の API を使ったお試しもさらにやってみつつ、別途、Gemma 3n については Hugging Face で公開されているモデルをダウンロードして扱ってみるというのも進めたいところです。

●Models - Hugging Face
 https://huggingface.co/models?sort=trending&search=google%2Fgemma-3n

image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?