Repository navigation
feat(py): keyless GoogleAI init, context.secrets on embedders, and ErrorReason.INVALID_CREDENTIALS - #49
Merged
Conversation
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 9, 2026 19:08
ef30008 to
673a6a0
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 9, 2026 19:54
673a6a0 to
5db462d
Compare
huangjeff5
changed the base branch from
main
to
fix/py-1.0-pr3-generation-loop
November 9, 2026 19:54
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 9, 2026 20:02
5db462d to
fa0c24a
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 9, 2026 20:21
fa0c24a to
a81192d
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 9, 2026 21:22
a81192d to
616e6b0
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
2 times, most recently
from
November 9, 2026 21:51
4ec7d77 to
3b16545
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 9, 2026 22:03
3b16545 to
11af4df
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 9, 2026 23:18
11af4df to
774cfea
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 10, 2026 07:44
774cfea to
f6891e1
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 10, 2026 18:37
f6891e1 to
609a844
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 11, 2026 06:22
a677005 to
feed839
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 11, 2026 17:31
cefd754 to
da79841
Compare
… embedders PR4-05 (D6): - GoogleAI reads GEMINI_API_KEY -> GOOGLE_API_KEY -> GOOGLE_GENAI_API_KEY and no longer raises in __init__ when no key is set. - Each Gemini, Veo, and embedder call resolves the key as context.secrets.api_key, then the plugin key/credentials, else GenkitError(FAILED_PRECONDITION) with the setup help. The plugin client is only built when the plugin has auth, so a keyless plugin never hits genai.Client(api_key=None). The resolved key is always passed to genai.Client explicitly. - init()/list_actions() skip model listing when there is no key and no credentials. - context_api_key returns None when secrets has no api_key (falls back to the plugin key, like genkit-openai/anthropic). - One missing-key error for the package: Interactions models (api_key_for_context) share the same status and text. PR4-06 (google + core): - Genkit.embed()/embed_many() take context=, passed to the embedder as ctx.context (omitted, the enclosing action's context applies). - GoogleAI/VertexAI embedders build a tenant client from context.secrets.api_key, even when the plugin has its own key.
PR4-06: the embedder resolves its client the same way as models (context.secrets key, then the plugin key, else FAILED_PRECONDITION), so ai.embed(context=...) bills the tenant instead of the plugin key.
…plugin key Dropping the 'secrets has no api_key' guard let '' and whitespace fall through string_secret as None, so a tenant with a missing header ran on the operator's key. Raise INVALID_ARGUMENT like genkit-openai and genkit-anthropic; None and app-only secrets still fall back.
GoogleAI docstring said a keyless call raises; generate returns the failure on response.error by default. Ollama README said embed() takes no context. Drop internal PR tags from the BYOK test.
…e 0.12 migration guide The guide covers 0.12 -> 0.13. The 1.0 notes go to the release notes.
huangjeff5
changed the base branch from
fix/py-1.0-pr3d-prompt-loader-sse
to
main
November 11, 2026 18:37
huangjeff5
force-pushed
the
fix/py-1.0-pr4-googleai-byok
branch
from
November 11, 2026 18:38
da79841 to
1485113
Compare
apascal07
reviewed
Nov 11, 2026
apascal07
approved these changes
Nov 11, 2026
…e request_client_kwargs
…illing plugin key
…ai-byok # Conflicts: # packages/genkit-google-genai/tests/models/googlegenai_gemini_test.py
This was referenced Nov 12, 2026
Merged
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.
A BYOK gateway (one server, each restaurant brings its own Gemini key) couldn't start:
GoogleAI()raisedValueErrorat construction when no env key was set. It now starts keyless and bills each call to the tenant'scontext.secrets.api_key.ai.embed()also takescontext=, so embeddings bill the tenant too. A missing key is no longer silent, and a rejected key carriesErrorReason.INVALID_CREDENTIALSso app code can match on it.Main Changes
GoogleAI()raisedValueErrorwhenGEMINI_API_KEYwas unset. Now the plugin loads, skips model listing, and builds the client per call. A call with no plugin key, nocredentials, and no tenant key fails withFAILED_PRECONDITION.generatereturns it onresponse.error;embedandgenerate_operationraiseGenkitError.GoogleAI()logs one warning at construction with the setup steps. Before, the README quickstart with no key printed an empty line and exited 0 with nothing on stderr. The request-time message is now one line; it used to start with\nand span several lines, which looked broken instr()and tracebacks.ErrorReason.INVALID_CREDENTIALS:provider_error(...)takesreason=, stored indetails['reason'], so it survives boxing (response.error.reason) and shows on raised errors (GenkitError.reason). Gemini sets it for a 400 withErrorInfo.reason = API_KEY_INVALIDor any 401; Vertex for a non-transientRefreshError. Status staysUNAUTHENTICATED. Deep Research, Antigravity, and Lyria returnedINVALID_ARGUMENTfor a bad key; they now matchgenerate.GEMINI_API_KEY, thenGOOGLE_API_KEY, thenGOOGLE_GENAI_API_KEY. Previously onlyGEMINI_API_KEYwas read, so a key exported underGOOGLE_API_KEY(the name thegoogle-genaiSDK uses) failed startup.None/blankapi_keyfails closed: Previously anycontext.secretswithoutapi_keyraisedINVALID_ARGUMENT, so an app couldn't keep, say, a CRM token there. Omittingapi_keynow falls back to the plugin key, while an explicitNoneor blankapi_key(such asrequest.headers.get('x-gemini-key')when the header is missing) raisesINVALID_ARGUMENTinstead of billing the server key, acrossgenkit-google-genai,genkit-openai, andgenkit-anthropic.embedandembed_manyacceptcontext=: When omitted, the embedder sees the enclosing flow's context, same asgenerate. GoogleAI, VertexAI (express mode), and OpenAI embedders readcontext.secrets.api_key.Decisions
reasonis the cross-plugin contract in Python. App code matches onErrorReason, not provider status codes or message text. Gemini and Vertex go first; the other model plugins follow in Map provider credential failures to ErrorReason.INVALID_CREDENTIALS in all model plugins #101.INVALID_CREDENTIALS, no missing-credentials reason. A missing key staysFAILED_PRECONDITIONwith no reason. The warning and the message already say what to do.logging, notgenkit.get_logger. structlog prints to stdout and would mix into program output, andGoogleAI()runs beforeGenkit(), outside any trace. Stdlib logging falls back to stderr and follows the app'sloggingconfig if it has one.Breaking changes
None.
Cross-SDK
googleAI()with no key throws when it defines models and embedders, unless you passgoogleAI({ apiKey: false }). PythonGoogleAI()starts with no opt-in, warns, and fails on the first call withFAILED_PRECONDITION. Python resolves the key on every call (context.secrets.api_key, then the plugin key), so a keyless plugin is the normal BYOK gateway setup.apiKey: falsereturnsINVALID_ARGUMENT. Python returnsFAILED_PRECONDITION, the status JS uses for a missing key withoutapiKey: false.ErrorReasonis Python-only. JS and Go branch on status;UNAUTHENTICATEDis the same across SDKs.context, not options. JS passesoptions: { apiKey }. Python usescontext={'secrets': {'api_key': ...}}, which core telemetry already redacts, so the key never lands in span attributes.getApiKeyFromEnvVar.