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 API が502 エラーを返すようになった話

0
Posted at

概要

Edge Function から Gemini API を呼び出す処理で、ある日突然 502 エラーが返ってくるようになりました。原因はコードでも API キーでもなく、使っていたモデルの提供終了でした。同じ事象で困っている人向けに、原因と対応方法をまとめておきます。

発生していた事象

API が正常に応答を返さなかった場合、次のようなレスポンスが返ってきていました。

{
  "error": "AI analysis failed."
}

HTTP ステータスは 502。

原因

使っていたモデルはこちらです。

gemini-2.0-flash

調べてみると、このモデルは 2026年6月1日に提供終了していました。コードや API キーは合っているのに動かない…と思ったら、そもそもモデルのエンドポイント自体がもう存在していなかった、というオチでした。

解決方法

利用可能なモデルに変更しました。

最初はこちらに変更しました。

const geminiModel = 'gemini-3.6-flash'

ただ、これだと応答速度が気になったので、最終的には軽量モデルに落ち着きました。

const geminiModel =
  Deno.env.get('GEMINI_MODEL') || 'gemini-3.5-flash-lite'

環境変数で上書きできるようにしておいたので、今後モデルがまた変更・廃止になっても、コードを直さずに対応できるはずです。

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?