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

User location is not supported for the API use. エラーの対処【Gemini API】Caddyプロキシ

0
Last updated at Posted at 2026-09-14

香港からgeminiにアクセスできないためメモ
プロキシ代を下げるため、常時プロキシせず、疎通できないときだけプロキシ使う

base_urlの指定方法

node.js
const apiKey = 'YOUR_API_KEY'
const r = await fetch(`https://generativelanguage.googleapis.com/v1/files?key=${apiKey}`)
const files = await r.json()

// アクセス制限あるとき
if (r.status === 400 && files?.error?.message?.includes('User location is not supported')) {
    const ai = new GoogleGenAI({
        apiKey,
        httpOptions: {
            baseUrl: 'https://*****.us-central1.run.app'
        }
    })
    const response = await ai.models.generateContent({
        model: 'gemini-3.5-flash-lite',
        contents: 'hi'
    })
    console.log(response.text)
}
python
from google import genai

client = genai.Client(api_key='YOUR_API_KEY')

try:
    client.files.list()
except genai.errors.APIError as e:
    if e.code == 400 and "User location is not supported" in str(e.message):
        # アクセス制限あるとき
        client = genai.Client(
            api_key='YOUR_API_KEY',
            http_options=genai.types.HttpOptions(
                base_url='https://*****.us-central1.run.app',
            )
        )

1. コンテナをデプロイ

image.png

2. caddy:alpineを入れる

image.png

3. リージョンはセントラを入れる(ティア1は無料)

image.png

image.png

4. パブアクセスを許可

image.png

5. 破産しないように最大1のインスタンス数

image.png

6. コンテナコマンド caddy コンテナ引数を入れる reverse-proxy --from :8080 --to https://generativelanguage.googleapis.com --change-host-header

image.png

7. タイムアウトを入れる。gemini apiは時間かかるため長めに

image.png

8. 破産しないようにインスタンス最大数1

image.png

9. 作成🎉

image.png

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