香港から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',
)
)









