0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Gemini 1.5 ProのAPI呼び出しで「429 Too Many Requests」エラーが出る?

Last updated at Posted at 2025-05-12

状況

Gemini 1.5 Pro のAPIを呼び出すと「429 Too Many Requests」となってしまう。(下記、エラー全文)

GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent: [429 Too Many Requests] You exceeded your current quota, please check your plan and billing details. For more information on this error, head to: https://ai.google.dev/gemini-api/docs/rate-limits. [{"@type":"type.googleapis.com/google.rpc.QuotaFailure","violations":[{"quotaMetric":"generativelanguage.googleapis.com/generate_content_free_tier_input_token_count","quotaId":"GenerateContentInputTokensPerModelPerMinute-FreeTier","quotaDimensions":{"location":"global","model":"gemini-1.5-pro"}},{"quotaMetric":"generativelanguage.googleapis.com/generate_content_free_tier_requests","quotaId":"GenerateRequestsPerDayPerProjectPerModel-FreeTier","quotaDimensions":{"location":"global","model":"gemini-1.5-pro"}},{"quotaMetric":"generativelanguage.googleapis.com/generate_content_free_tier_requests","quotaId":"GenerateRequestsPerMinutePerProjectPerModel-FreeTier","quotaDimensions":{"location":"global","model":"gemini-1.5-pro"}}]},{"@type":"type.googleapis.com/google.rpc.Help","links":[{"description":"Learn more about Gemini API quotas","url":"https://ai.google.dev/gemini-api/docs/rate-limits"}]},{"@type":"type.googleapis.com/google.rpc.RetryInfo","retryDelay":"18s"}]

そんなに頻繁に呼び出した訳でもなかったのに何故…?

いつから発生しているか

2025.05.07 21時頃(JST)から発生。

周辺情報

  • 使用モデル:Gemini 1.5 Pro
  • バージョン:v1, v1beta
  • 料金プラン:無料枠
  • API呼び出し方法:ts-nodeでnpmライブラリ @google/generative-ai 内のメソッドを実行
サンプルコード
import { GoogleGenerativeAI } from "@google/generative-ai";
import "dotenv/config";
// Gemini準備
const gemini = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);//Gemini APIキー
const model = gemini.getGenerativeModel(
{
  model: "gemini-1.5-pro",
}
);
// 回答作成
const prompt = "早く寝るコツを教えて。";
const result = await model.generateContent(prompt);
let resContent = result.response.text();

調査したこと、試したこと等

  • エラーメッセージ通り「レート上限に達しているのでは」と考えたが、公式ドキュメントを見ると2025.5.12時点では1.5 Proの無料枠は期間毎の上限が無い模様
    image.png

  • 新規アカウントでapiキーを作っても同様な現象が発生することが判明。1リクエスト目から当エラーが発生している…
    Screenshot from 2025-05-12 02-09-31(edit).png

  • 1回毎の上限に達しているかも考えたが、入力のプロンプトは「早く寝るコツを教えて。」という極めて短い文章(8トークン)で、上限の2,097,152トークンに到達しているはずがない。
    回答も1600トークン程度であり、上限の8,192トークンに到達していると思えない。
    公式ドキュメント
    image.png

結局どうしたか

modelをGemini 2.5 Pro プレビューに変更。
(公式ドキュメントにも1.5 Pro → 2.5 Proプレビューに変更するよう指示あり)

無事、生成できるようになった。
image.png

おわりに

根本的な原因は突き止められなかったが、1.5 Proの最終更新日が昨年9月であることから、もう使うべきではなかったのかもしれない。
バージョン変更を、もっとアンテナ貼って頻繁に行うべきだった。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?