From inside Docker : "User location is not supported for the API use.", works from outside

Other reference to this issue in forum mentions the issue got resolved “magically”. Please advise what we might be doing wrong.

== test.sh ==
#!/bin/bash
curl “https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=$GEMINI_API_KEY
-H ‘Content-Type: application/json’
-X POST
-d ‘{
“contents”: [
{
“parts”: [
{
“text”: “Explain how AI works in a few words”
}
]
}
]
}’

docker exec -it packages_api_1 sh
/app # sh +x test.sh
{
“error”: {
“code”: 400,
“message”: “User location is not supported for the API use.”,
“status”: “FAILED_PRECONDITION”
}
}

== Same script executed from outside of docker works ==
sh +x test.sh
{
“candidates”: [
{
“content”: {
“parts”: [
{
“text”: “AI learns patterns from data to make predictions or decisions.\n”
}
],
“role”: “model”
},
“finishReason”: “STOP”,
“avgLogprobs”: -0.08905194203058879
}
],
“usageMetadata”: {
“promptTokenCount”: 8,
“candidatesTokenCount”: 12,
“totalTokenCount”: 20,
“promptTokensDetails”: [
{
“modality”: “TEXT”,
“tokenCount”: 8
}
],
“candidatesTokensDetails”: [
{
“modality”: “TEXT”,
“tokenCount”: 12
}
]
},
“modelVersion”: “gemini-2.0-flash”
}

Server physical location France, if it helps. (Present in this list : ai.google.dev/gemini-api/docs/available-regions)

After some troubleshooting, figured out request headers is perhaps the problem. setting
‘User-Agent’: ‘Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36’

in the shell script works, but js sdk still does not work with customHeaders set as requestOptions.

Tried @google/genai also. same issue.

The IP address exposed is same outside/within docker. some bug around request headers/ user agent looks like