Note: Steps so far were run locally and final issue was created with assistance of Opus 4.6
Problem
When using Google Vertex AI models through a corporate API gateway (Azure API Management),
the gateway proxies requests using Google's native API format
(/v1beta1/publishers/google/models/{model}:generateContent) with API key auth
(x-goog-api-key header).
Currently, chat_google_vertex() does not accept a base_url argument, so there's
no way to point it at a custom endpoint. The gateway is NOT OpenAI-compatible, so
chat_openai_compatible() doesn't work either.
Workaround
Using httr2 directly works:
url <- "https://my-gateway.example.com/vertex-ai-express/v1beta1/publishers/google/models/gemini-2.5-flash-lite:generateContent"
resp <- request(url) |>
req_headers(`x-goog-api-key` = api_key, `Content-Type` = "application/json") |>
req_body_json(list(
contents = list(list(role = "user", parts = list(list(text = "Hello!"))))
)) |>
req_perform()
The Python google.genai SDK supports this via HttpOptions(base_url=...):
from google.genai import Client
from google.genai.types import HttpOptions
client = Client(vertexai=True, api_key=api_key, http_options=HttpOptions(base_url=ENDPOINT))
Proposed Solution
Add a base_url parameter to chat_google_vertex() that overrides the default Google endpoint URL, similar to how the Python SDK's HttpOptions(base_url=...) works.
This would also need to support API key authentication (via x-goog-api-key header) as an alternative to OAuth/service account credentials.
Environment
- ellmer version: 0.4.1
- R version: [your R version]
- Gateway path format: /v1beta1/publishers/google/models/{model}:{method}
- Auth: x-goog-api-key header with API key
Note: Steps so far were run locally and final issue was created with assistance of Opus 4.6
Problem
When using Google Vertex AI models through a corporate API gateway (Azure API Management),
the gateway proxies requests using Google's native API format
(
/v1beta1/publishers/google/models/{model}:generateContent) with API key auth(
x-goog-api-keyheader).Currently,
chat_google_vertex()does not accept abase_urlargument, so there'sno way to point it at a custom endpoint. The gateway is NOT OpenAI-compatible, so
chat_openai_compatible()doesn't work either.Workaround
Using
httr2directly works:The Python
google.genaiSDK supports this viaHttpOptions(base_url=...):Proposed Solution
Add a
base_urlparameter tochat_google_vertex()that overrides the default Google endpoint URL, similar to how the Python SDK'sHttpOptions(base_url=...)works.This would also need to support API key authentication (via
x-goog-api-key header) as an alternative to OAuth/service account credentials.Environment