Repository navigation
feat(py): serve Model Garden's OpenAI-compatible models via OpenAICompatible(backend=GoogleCloud()) - #197
Closed
huangjeff5 wants to merge 2 commits into
Closed
feat(py): serve Model Garden's OpenAI-compatible models via OpenAICompatible(backend=GoogleCloud())#197huangjeff5 wants to merge 2 commits into
huangjeff5 wants to merge 2 commits into
Conversation
This was referenced Nov 30, 2026
…patible(backend=GoogleCloud())
huangjeff5
force-pushed
the
feat/py-openai-compatible
branch
from
November 30, 2026 21:40
7853f01 to
6c14b5a
Compare
huangjeff5
force-pushed
the
feat/py-openai-compatible-google-cloud
branch
from
November 30, 2026 21:40
88dd349 to
9a7d5b3
Compare
This was referenced Nov 30, 2026
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenAICompatible(backend=GoogleCloud(...))serves Model Garden's OpenAI-compatible models (Llama, Mistral and others) from Google Cloud, billed to your project and authenticated with application default credentials. The backend builds the endpoint and handles the token, so there's nobase_url, no key and no token code.garden.model(id)gives the ref for any of these models.Stacked on #196 (and #151). Review and merge those first.
This is the replacement #198 needs for Llama and the other open models when
genkit-vertexaiis removed. Refs default tomodelgarden/<publisher>/<model>, as they were inModelGarden, so moving over is a constructor change only — and you can pass a customname=when you want another namespace (for example, to run multiple regions or projects side by side).Changes
backend=onOpenAICompatible, and a new exportedGoogleCloud(project=None, location=None). The endpoint ishttps://{location}-aiplatform.googleapis.com/v1beta1/projects/{project}/locations/{location}/endpoints/openapi, the same oneModelGardenuses.globalgets the unregioned host.base_url=overrides it, for example for Private Service Connect, and auth stays Google's.project=, thenGCLOUD_PROJECT, thenGOOGLE_CLOUD_PROJECT, then the credentials' project.location=, thenGOOGLE_CLOUD_LOCATION, thenus-central1(ModelGarden's default; most open models are regional).namerule.nameis still required, as in JS and Go.GoogleCloud:nameis optional and defaults to'modelgarden'; any other valid single-segment name (non-empty, no'/') is accepted so multiple regions or projects can coexist in one app.FAILED_PRECONDITIONwith thegcloudcommand that fixes it.FAILED_PRECONDITIONnaming three ways to set one.TransportErrorand retryableRefreshErrormap toUNAVAILABLE(both on initial load and hourly refresh) soRetrymiddleware can retry them.FAILED_PRECONDITION, before ADC is touched, because every call bills the project.api_key=together withGoogleCloudraisesValueErrorat setup, andclient_options={'api_key': ...}raisesTypeErrorat setup (GoogleCloudServerreservesapi_key)./models, so no request goes out. Any id resolves when called.google-cloudextra →google-auth[requests]>=2.14.1, the same bound asgenkit-vertexai. Without it, the constructor raisesImportErrorwith theuv addcommand.OpenAICompatible's main use case, with first-time setup, defaults, customname=, and the Claude pointer (Anthropic(backend=GoogleCloud())).Decisions
.model(), config) is theOpenAICompatiblepath from feat(py): add OpenAICompatible for any OpenAI-compatible server, matching JS and Go #196. This mirrorsAnthropic(backend=GoogleCloud()).GoogleCloudlocal to each plugin, not exported fromgenkitcore: Onlygenkit-openaiandgenkit-anthropicneed this shape, so duplicating the small config + ADC module is cheaper than expandinggenkitcore's public API surface.modelgardendefault name, customname=allowed: Llama users' refs don't change when leavinggenkit-vertexai, while passingname=lets apps register multiple Google Cloud regions, projects, or PSC endpoints side by side.us-central1by default, notglobal: The open models are mostly regional, andModelGardendefaulted tous-central1. This differs fromgenkit-anthropic'sGoogleCloud, which defaults toglobalbecause every Claude model has global quota.genkit-vertexai's Llama 3.1 and 3.2 entries) is stale. Any id resolves, and a curated list can come later without an API change.asyncio.Lockwould bind to one event loop, and the plugin's clients are per-loop.Verification
packages/genkit-openai: 1,068 passed, includingopenai_compatible_google_cloud_test.pycovering custom names, multi-region/project coexistence, invalid names, endpoint URLs, ADC loading/caching/retry, token refresh/errors, and missing extra error.ruff format --check --preview .,ruff check --preview .,ty check .,pyrefly checkon changed files,scripts/check_consistency.py, anduv lock --checkall pass.Breaking changes
None.
backendis optional, andOpenAICompatiblewithout it behaves as in #196.