Repository navigation
feat(py): serve Model Garden's OpenAI-compatible models via OpenAICompatible(backend=GoogleCloud()) - #259
Merged
huangjeff5 merged 1 commit intoDec 1, 2026
Conversation
This was referenced Nov 30, 2026
huangjeff5
force-pushed
the
feat/py-openai-google-cloud
branch
from
December 1, 2026 20:23
4bf2942 to
fb5bcd4
Compare
huangjeff5
force-pushed
the
feat/py-openai-google-cloud
branch
from
December 1, 2026 21:20
fb5bcd4 to
7e00071
Compare
…patible(backend=GoogleCloud())
huangjeff5
force-pushed
the
feat/py-openai-google-cloud
branch
from
December 1, 2026 21:37
7e00071 to
327e7de
Compare
huangjeff5
enabled stacked auto-merge (squash)
December 1, 2026 21:52
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) on Google Cloud using your project's billing and application default credentials. The backend constructs the Vertex OpenAI endpoint and refreshes Google tokens automatically.This provides the replacement #260 needs for open Model Garden models before
genkit-vertexaiis deprecated. Refs default tomodelgarden/<publisher>/<model>(matchingModelGarden), so migrating only changes the plugin constructor. Passing a customname=lets you run multiple regions or projects side by side.Changes
backend=parameter andGoogleCloudconfig:GoogleCloud(project=None, location=None)buildshttps://{location}-aiplatform.googleapis.com/v1beta1/projects/{project}/locations/{location}/endpoints/openapi(unregioned host forglobal).project=,GCLOUD_PROJECT,GOOGLE_CLOUD_PROJECT, then the ADC project. Location resolution:location=,GOOGLE_CLOUD_LOCATION, then'us-central1'.base_url=overrides the generated endpoint (e.g. for Private Service Connect) while keeping Google auth; whenbase_urlis set,projectis not required, and blankbase_urlvalues raiseValueError.name='modelgarden'withGoogleCloud:nameremains required when no backend is given. WithGoogleCloud, it defaults to'modelgarden'and accepts any valid single-segment name for multi-region/project setups.load_adcloads and refreshes credentials in a worker thread on first call;AdcTokenserializes token refreshes under athreading.Lockand guards against empty/Nonetokens.FAILED_PRECONDITIONwith thegcloud auth application-default logincommand; failed loads aren't cached.FAILED_PRECONDITIONpointing toGoogleCloud(project=...),GOOGLE_CLOUD_PROJECT, andgcloud config set project.TransportErrorand retryableRefreshErrormap toUNAVAILABLE(both on initial load and hourly refresh) forRetrymiddleware.api_key=(ValueError),client_options={'api_key': ...}(TypeError), pinnedAuthorizationindefault_headers(ValueError), and foreignGoogleCloudinstances (module-qualifiedTypeError) at setup. Clears ambientOPENAI_ORG_IDandOPENAI_PROJECT_ID. Per-requestcontext.secretsfails withFAILED_PRECONDITIONbefore touching ADC./modelslisting: Model Garden's OpenAI endpoint has no/modelsroute, solist_actionsreturns an empty list without making a request; any model ID resolves on demand.google-cloudextra: Addsgoogle-auth[requests]>=2.14.1. Ifgoogle-authorgoogle.auth.transport.requestsis missing, construction raisesImportErrorwith theuv addcommand.base_url=override, customname=, and a pointer toAnthropic(backend=GoogleCloud())for Claude.Decisions
OpenAICompatible: Model Garden's open models are an OpenAI-compatible server with Google Cloud auth and URL formatting. AttachingGoogleCloudas a backend reuses the entire chat, embedding, config, and.model()path from feat(py): add OpenAICompatible for any OpenAI-compatible server, matching JS and Go #258 and mirrorsAnthropic(backend=GoogleCloud()).GoogleCloudclass: Onlygenkit-openaiandgenkit-anthropicneed this config. Keeping the small dataclass + ADC helper local avoids expandinggenkitcore's public API surface.'modelgarden'with optionalname=: ExistingModelGardenLlama/Mistral refs keep working unchanged, while customname=supports multiple regions, projects, or PSC endpoints in one app.'us-central1': Most open Model Garden models are regional andModelGardenalready defaulted tous-central1(unlikegenkit-anthropic'sGoogleCloud, which defaults to'global'because Claude has global quota).genkit-vertexai's old Llama 3.1/3.2 list is stale. Resolving any ID on demand works immediately, and a curated list can be added later without breaking changes.threading.LockinAdcToken: Token refresh runs in worker threads and clients are per-event-loop, sothreading.Lockserializes concurrent refreshes without binding to a singleasyncioloop.Verification
packages/genkit-openai,packages/genkit-anthropic,packages/genkit-vertexai, andtests/version_bounds_guard_test.py— 1,648 passed, 5 skipped (live tests).ruff,ty,pyrefly(0 errors),scripts/check_consistency.py,uv lock --check, andaddlicense -checkall pass (pyrightruns in CI).Breaking changes
None.
backendis optional, andOpenAICompatiblewithout it behaves as in #258.