Hello,
I am calling the gemini-2.5-flash model via the Node.js SDK from an external server (Vultr).
I am using a Service Account and have set the GOOGLE_APPLICATION_CREDENTIALS environment variable. The authentication seems
to be working.
However, when I call the generateContentStream method with JSON mode enabled (responseMimeType: ‘application/json’ and a
responseSchema), the API returns a full HTML page starting with “…” instead of the expected JSON object.
This causes a “SyntaxError: Unexpected token ‘<’” in my application.
The same code works perfectly on my local Windows machine using Application Default Credentials from a gcloud login.
Why would the Vertex AI API return an HTML page instead of a JSON error or the expected JSON payload, specifically when
called from a Vultr server environment?
That behavior usually means you’re not receiving a model response at all, but an HTTP error page that your code is trying to parse as JSON.
When Vertex AI returns HTML (starting with <), it’s almost always because of one of these:
Wrong Vertex AI location
Make sure you’re using a region (for example us-central1, europe-west4), not a zone like us-central1-a. A wrong location often results in an HTML error page instead of JSON.
Auth succeeds, but permissions don’t
Service account authentication can work while the request is still blocked. Ensure the service account has at least roles/aiplatform.user (or equivalent Vertex AI permissions). Misrouted or unauthorized requests can return HTML.
External server/network interception
Some hosting environments (Vultr included) may return an HTML response due to:
Proxy / firewall / outbound restriction
Redirect (302) or block page
This explains why it works locally but not from the server.
To confirm, log from the Vultr server:
HTTP status code
Content-Type response header
First ~200 characters of the raw response body
If you see text/html, this is a routing/auth/network issue, not JSON mode failing. Vertex AI will only return JSON for successful model responses; errors are never converted into structured output.