class

MJ::Arcana::GoogleDirectTransport

Inherits MJ::Arcana::Transport < Reference < Object

Google's Gemini image API, direct — a third independent capacity pool.

Same models Runware fronts as google:4@3 and google:nano-banana@2-lite, admitted against our own Google quota instead of queueing behind every other Runware customer. Unlike the OpenAI pool this one is also markedly FASTER: lite measured ~2.8s direct against 6.1s through Runware, which makes it the best candidate for anything a player might notice.

Everything below was probed against the live API, and three things differ from every other provider here:

  1. It takes an aspect RATIO, not pixel dimensions. The 14 legal ratios and the size each produces are in Cameras::GOOGLE_DIMS / RATIO_FOR, measured one call at a time. Eight of them match the Nano sizes probed through Runware exactly, which is good evidence the size set belongs to the model rather than the aggregator — and two (928x1152, 1152x928) are sizes Runware does not expose at all.
  2. It rejects unknown fields. Runware silently swallows a parameter it does not implement, so a 200 there proves nothing; OpenAI accepts the field name but the model may still refuse it. Google answers Unknown name "bogusField". A 200 from this provider actually means the parameters engaged, which makes it the only one of the three whose success is self-verifying.
  3. It reports tokens, so cost is computed rather than quoted. usageMetadata gives image output tokens — a flat 1120 for every 1K image regardless of aspect, so a 2928x352 panorama costs exactly what a square does.

Constants

ENDPOINT = "https://generativelanguage.googleapis.com"
RATIO_FOR = { {1024, 1024} => "1:1", {512, 2064} => "1:4", {352, 2928} => "1:8", {848, 1264} => "2:3", {1264, 848} => "3:2", {896, 1200} => "3:4", {2064, 512} => "4:1", {1200, 896} => "4:3", {928, 1152} => "4:5", {1152, 928} => "5:4", {2928, 352} => "8:1", {768, 1376} => "9:16", {1376, 768} => "16:9", {1584, 672} => "21:9"}

Reverse of the measured size table: which ratio string produces this exact size. The service snaps a caller's request to one of these sizes through the camera's dims, so the lookup is always an exact hit.

USD_PER_MTOK = {"gemini-3.1-flash-image" => 60.0, "gemini-3.1-flash-lite-image" => 30.0, "gemini-3-pro-image" => 60.0}

Published USD per 1M image output tokens, by model. Measured token counts times these give the per-call figure. NOT billed-back numbers — Google reports tokens and no price — so results carry usd_estimated: true.

The batch endpoint (batchGenerateContent, which every image model supports) is half these rates. Nothing uses it yet; it is the right home for a stock library, where no caller is waiting.

Constructors

new(api_key : String, retries : Int32 = 2, read_timeout : Float64 = 180.0)
Source

Instance methods

edit(references : Array(Bytes), prompt : String, width : Int32, height : Int32, model : String, extra : Hash(String, JSON::Any) | Nil, format : String) : GenerationResult
Source
name

A short stable name a Camera refers to, e.g. "runware".

Source