This document defines the browser-safe Gemini proxy contract for ERP hosts.
ERP browser clients must be able to use Gemini without receiving, storing, or sending provider API keys.
In server-auth mode, the browser sends requests only to host-owned proxy URLs. The ERP server owns provider authentication and injects the Gemini key server-side.
Use authMode: "server" for browser-safe Gemini provider calls:
await agrun.run({
provider: "gemini",
model: "gemini-2.5-flash",
authMode: "server",
endpoint: "/api/ai/gemini/generateContent.cfm",
streamEndpoint: "/api/ai/gemini/streamGenerateContent.cfm",
prompt: "Summarize this ERP case."
});Server-auth behavior:
apiKeyis optional and should not be passed from ERP browser clients.endpointis required for non-streaming Gemini requests.streamEndpointis required for streaming Gemini requests.cachedContentModedefaults to"disabled"whenauthModeis"server".- Browser requests do not send
x-goog-api-keyorauthorizationprovider headers.
The proxy endpoint should accept a Gemini generateContent compatible JSON body and return a Gemini-compatible JSON response.
The streaming proxy endpoint should accept the same request body and return a Gemini-compatible SSE stream.
Gemini grounding search has its own provider request path. ERP hosts that need grounding must proxy it separately:
await agrun.run({
provider: "gemini",
model: "gemini-2.5-flash",
authMode: "server",
endpoint: "/api/ai/gemini/generateContent.cfm",
streamEndpoint: "/api/ai/gemini/streamGenerateContent.cfm",
searchProvider: "gemini_grounding",
webSearchAuthMode: "server",
webSearchEndpoint: "/api/ai/gemini/grounding.cfm",
webSearchModel: "gemini-2.5-flash",
prompt: "Answer with grounded web context."
});Grounding server-auth behavior:
webSearchAuthMode: "server"tells agrun.js to call the ERP grounding proxy.webSearchEndpointis required for Gemini grounding in server-auth mode.- The browser does not require or send a Gemini API key for grounding.
- The ERP grounding proxy should call Gemini with the Google Search tool enabled and return a normalized search result payload.
Direct browser grounding with apiKey remains available for non-ERP demos, but ERP clients should not use that mode.
When an approval pause happens in server-auth mode, the resume token preserves routing fields:
authModeendpointstreamEndpointcachedContentModesearchProviderwebSearchAuthModewebSearchEndpointwebSearchModel
The resume token does not serialize apiKey for server-auth mode.
For ERP integration acceptance, verify the browser Network and storage surfaces:
- Requests go only to same-origin or approved ERP proxy URLs.
- No provider key appears in JavaScript config.
- No provider key appears in request headers or request bodies.
- No provider key appears in
localStorage, IndexedDB, resume tokens, or debug snapshots. - Direct-key mode is used only for local demos or non-ERP examples.