Documentation
¶
Overview ¶
Package gemini talks to Google's Gemini API on a key the user supplies through the environment.
Caprock never stores that key. It is read from GEMINI_API_KEY at the moment of the call, never written to config.json, never accepted by PUT /v1/settings and never returned by GET /v1/settings — see ADR-023. The objection this answers is recorded in .ai/17-teams.md: a bug in a tool that holds no credential cannot leak one.
This is the second outbound call in the product, after the release check, and the first that carries user content. Nothing here runs on a timer or in the background: a request leaves only when a person asked a question in that turn.
Index ¶
Constants ¶
const Agent = "gemini"
Agent is the value the sessions table carries for Gemini work, alongside "claude" and "opencode".
const DefaultModel = "gemini-3.5-flash-lite"
DefaultModel is what a request without a model uses: the cheapest current Flash tier, because the common use is a question about the user's own sessions rather than deep reasoning, and it is their money.
const Endpoint = "https://generativelanguage.googleapis.com/v1beta"
Endpoint is the only host this package ever contacts.
const EnvKey = "GEMINI_API_KEY"
EnvKey is the variable the key is read from. The name matches what Google's own tooling uses, so a machine already set up for Gemini needs no new setup.
const MaxBody = 8 << 20
MaxBody bounds what is read back. A runaway response must not become a runaway allocation in a daemon that is meant to sit quietly.
Variables ¶
var ErrNoKey = errors.New("no " + EnvKey + " in the environment")
ErrNoKey means the environment holds no key, which is also how the feature stays off: with nothing set there is no default-on path to disable.
Functions ¶
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
// Base overrides the endpoint in tests. Empty means Endpoint.
Base string
// Now is injectable so timings are deterministic under test.
Now func() time.Time
}
Client calls the API. The zero value is usable.
type Reply ¶
type Reply struct {
Text string `json:"text"`
Model string `json:"model"`
Usage Usage `json:"usage"`
Elapsed time.Duration `json:"-"`
}
Reply is one answer plus what it cost.
type Usage ¶
type Usage struct {
PromptTokens int64 `json:"prompt_tokens"`
OutputTokens int64 `json:"output_tokens"`
CachedTokens int64 `json:"cached_tokens"`
ThoughtsTokens int64 `json:"thoughts_tokens"`
TotalTokens int64 `json:"total_tokens"`
}
Usage is what the response says it cost, in tokens. These are the figures Caprock prices; there is no per-key billing API to reconcile them against (Google reports per project), so the total is what Caprock sent rather than what Google billed, and the UI says so.