Skip to content

fix(provider): honor base_url for google-genai and vertexai providers - #1269

Merged
RealKai42 merged 2 commits into
mainfrom
fix/google-genai-base-url
Jul 1, 2026
Merged

fix(provider): honor base_url for google-genai and vertexai providers#1269
RealKai42 merged 2 commits into
mainfrom
fix/google-genai-base-url

Conversation

@RealKai42

@RealKai42 RealKai42 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

The google-genai and vertexai provider types silently ignored a configured base_url — requests always hit generativelanguage.googleapis.com. For example, a "Gemini-compatible proxy URL + key" setup was unusable.

The endpoint was dropped at two layers:

  • In kosong, GoogleGenAIOptions had no baseUrl field, and _buildClient never passed httpOptions.baseUrl to the @google/genai SDK.
  • In agent-core, toKosongProviderConfig never read provider.baseUrl in the google-genai branch; the vertexai branch only mined it for location, never as an endpoint.

By contrast, the openai / anthropic / kimi / openai_responses branches all read base_url correctly.

Changes

  • kosong (providers/google-genai.ts): add baseUrl to GoogleGenAIOptions, store it on the instance, and inject it into the client's httpOptions.baseUrl, merged with the existing headers into a single httpOptions (the SDK merges headers and overrides the base host, so both coexist).
  • agent-core (session/provider-manager.ts): forward provider.baseUrl in the google-genai and vertexai branches, with GOOGLE_GEMINI_BASE_URL / GOOGLE_VERTEX_BASE_URL env fallback. vertexai keeps deriving location from an aiplatform host (backward compatible).
  • docs: document base_url for both providers in the EN/ZH providers.md, noting that only the host root should be given — the SDK appends the API version segment itself (Gemini /v1beta, Vertex /v1beta1), so a trailing version would duplicate the path (/v1beta/v1beta/...).

Testing

Added 8 unit tests:

  • kosong layer: asserts baseUrl reaches the SDK client's httpOptions, coexists with defaultHeaders, and applies in vertexai mode.
  • agent-core layer: asserts base_url is forwarded into the kosong config, the env fallback works, and vertexai still derives location from an aiplatform host.

Also ran smoke verification (intercepting the real global fetch, driving a full generate()): confirmed the configured base_url reaches the actual outbound request URL and hits the custom host, with no regression to the default endpoint when unset.

  • Target tests: 122 passed
  • kosong + agent-core typecheck pass; 0 lint errors on changed files

The google-genai and vertexai provider types silently ignored a configured
base_url and always hit generativelanguage.googleapis.com (e.g. a Gemini-
compatible proxy URL + key could not be used). Plumb the endpoint through to
the @google/genai SDK via httpOptions.baseUrl:

- kosong: add baseUrl to GoogleGenAIOptions and inject it into the client's
  httpOptions alongside the existing headers (the SDK merges headers and
  overrides the base host).
- agent-core: forward provider.baseUrl in the google-genai and vertexai
  branches, with GOOGLE_GEMINI_BASE_URL / GOOGLE_VERTEX_BASE_URL env
  fallback. vertexai keeps deriving location from an aiplatform host.
- docs: document base_url for both providers, noting the host root only
  must be given because the SDK appends the API version itself.

Covered by unit tests asserting the URL reaches the kosong config and the
SDK client's httpOptions.
@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9682bc0

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@9682bc0
npx https://pkg.pr.new/@moonshot-ai/kimi-code@9682bc0

commit: 9682bc0

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 433a782dc5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core/src/session/provider-manager.ts Outdated
The vertexai branch forwarded the endpoint from config `base_url` OR the
GOOGLE_VERTEX_BASE_URL env fallback, but service-account detection
(`hasVertexAIServiceEnv` / `vertexAILocation`) still derived the region from
`provider.baseUrl` only. Supplying the regional endpoint via the env fallback
(with a project but no explicit GOOGLE_CLOUD_LOCATION) therefore left location
undefined and silently downgraded Vertex ADC to API-key Gemini routing.

Resolve the effective base URL once and use it for both forwarding and location
derivation, so the env fallback behaves exactly like `base_url`. Add a
changeset for the kosong + agent-core patch release.
@RealKai42

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 9682bc03b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@RealKai42
RealKai42 merged commit bf35f63 into main Jul 1, 2026
9 checks passed
@RealKai42
RealKai42 deleted the fix/google-genai-base-url branch July 1, 2026 11:33
@github-actions github-actions Bot mentioned this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant