generateContent / streaming for chat, and countTokens aligned with the same system-instruction handling as complete.
Why
Gemini fits when you want Google’s models in a multi-provider setup. List model ids such asgemini-2.0-flash in config and route with params.model like any other provider.
Setup
- Confirm
apps/backend/package.jsonincludes"tooling-ai-google": "workspace:*". - Run
make deps-installif needed. - Add
googleundertools.aiinapps/backend/src/configuration/development.ts:
- No
compose.ymlchanges are required — the Generative AI API is HTTP from the backend container. - Add to
.env.development(name your variable consistently in config; example):
- Verify:
Local observability
Gemini calls are visible through Refract instrumentation (ai logs and metrics). Google Cloud billing and quotas are managed in Google AI Studio / GCP consoles outside this repo.
Adding a new model id
- Append the model id to
tools.ai.google.models. - Set
defaultModelwhen this id should be the fallback for omittedparams.model(and Google is the primary loaded provider). - Run
make test module=tooling-ai-google.
Gotchas
- System-role prompts are passed as
systemInstructionon the generative model; conversation contents exclude system messages — keep prompts structured accordingly. countTokensusestoGeminiConversationContentsso counts matchcomplete, not a duplicate system-as-user mapping.- Final stream chunk includes usage metadata; earlier chunks may show zero tokens until aggregation completes.
