015 · Models
Model providers, resilience, fallback and per-model settings (spec_015_models)
| Status | Implemented. Reverse-engineered from 53f8c53 (2026-09-24) and kept with the code since; its paths checked 2026-09-27 (//tools/specs). |
| Source | pkg/engine/runtime/model_factory.go, anthropic.go, openai_images.go, images.go, documents.go, fallback.go, httpclient.go, settings.go, usage.go, speech.go, painter.go, apipictures.go, apiprovider.go, apiresponse.go, apitoken.go, scriptrun.go; pkg/config/apiprovider.go; pkg/engine/breaker |
| Tests | pkg/engine/runtime/anthropic_test.go, fallback_test.go, httpclient_test.go, settings_test.go, pin_test.go, images_test.go, speech_test.go, painter_test.go, apipictures_test.go, apiprovider_test.go, apitoken_test.go, scriptrun_test.go; pkg/config/apiprovider_test.go; pkg/engine/breaker/breaker_test.go |
| Depends on | spec_002_config |
| Used by | spec_016_engine |
Every model is an ADK model.LLM. A factory builds one from a model reference for one of four providers, wraps it with per-model settings, images and (optionally) a fallback chain, and gives every SDK a shared HTTP client with retry and stall limits.
- MDL-01 A reference is
provider/modelor a baremodel.ParseModelRef(ref, default)splits on the first/only when the prefix is a known provider (gemini,anthropic,openai,ollama,bedrock,azure,vertex-anthropic,api, case-insensitive); otherwise the whole string is a model of the default provider. OpenRouter-style names therefore need the provider spelled out:openai/anthropic/claude-sonnet-5. - MDL-01a 2026-11-04 (scan N26-engine-runtime#17, #18: an unknown
llm.providerfrom a file orLLM_PROVIDERquietly ran on Gemini when a Gemini key was set, and the provider list was kept three times). The providersllm.providertakes are one list,config.Providers(the runtime’s prefixes addenterprise, which comes from the connection);ValidProvider,ProviderListand the unknown-provider error use it. An unknown provider fails the model’s build withunknown provider "antropic" (gemini, anthropic, openai, ollama, bedrock, azure, vertex-anthropic or api)whatever keys are set, and the settings check reports it at its line. - MDL-02
NewModel(cfg, override)usesoverrideelsecfg.ModelName(), builds the primary, and ifllm.fallback_modelsis non-empty wraps primary + each buildable fallback in a fallback model. Fallbacks that fail to build are logged and skipped.NewModelRefbuilds exactly one model (no chain) — used bydoctorand pins.
| Provider | Implementation | Credentials |
|---|---|---|
gemini |
ADK gemini.NewModel over genai |
Since 2026-10-09 (the owner’s request), one credential, the first there is: an API key (api_key, api_key_command, GEMINI_API_KEY/GOOGLE_API_KEY), alone, to the Gemini API; else Google Cloud’s credentials, to Vertex AI: Application Default Credentials (GOOGLE_APPLICATION_CREDENTIALS), else the Google account signed in with gcloud (auth = "oauth", gcloud’s application-default login), else a Google Cloud machine’s (the metadata server). auth doesn’t change the order: with a key, adc and oauth wait until it’s removed. On Vertex AI: project project_id, else GOOGLE_CLOUD_PROJECT, else the credentials’ own (a service account’s key file), required; location location, else GOOGLE_CLOUD_LOCATION, else global. The credentials sign that model’s requests only (a copy of the shared HTTP client), never another model’s, so a request never carries a key and a token. |
anthropic |
Native adapter over anthropic-sdk-go Beta Messages API |
auth = "oauth": the ant auth login (Anthropic Console) profile profile, else ant’s (ANTHROPIC_PROFILE, the active profile, default), with the SDK’s environment defaults off so no API key or token shadows it; a missing profile fails the model build. auth = "adc": Claude on Vertex AI (the SDK’s vertex.WithCredentials) with Application Default Credentials found as for Gemini (missing ones fail the build; the SDK’s WithGoogleAuth would panic), project and location as for Gemini ([llm.anthropic] project_id, location), the quota project sent, first-party credentials ignored, and server-side refusal fallback off (Vertex AI has none); the models need enabling in Vertex AI’s Model Garden. Otherwise api_key, else SDK resolution (ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, ant auth login profile, workload identity); optional base_url |
openai |
ADK OpenAI model (Responses API) wrapped for images and text tool calls | [llm.openai] key and base URL |
ollama |
Same as openai |
Uses [llm.openai]; base URL defaults to http://localhost:11434/v1 when unset or still the OpenAI default; key is always the placeholder ollama (never the OpenAI key) |
bedrock |
The anthropic adapter with the SDK’s bedrock option (SigV4, Bedrock’s URL for the region) |
[llm.bedrock] region (else AWS_REGION, the profile’s), profile, auth (since 2026-10-04: "oauth", an AWS IAM Identity Center sign-in for the profile; "" access keys; both through the chain), model (a Bedrock model or inference profile ID, required). AWS’s standard chain (environment, shared config and credentials, SSO, instance and task roles) checked when the model is built (30 s), or a Bedrock API key in AWS_BEARER_TOKEN_BEDROCK. No server-side refusal fallbacks |
azure |
A model whose name starts with claude: the anthropic adapter over the SDK’s foundry client (https://<resource>.services.ai.azure.com/anthropic/, or anthropic_base_url); any other: the openai adapter over Azure OpenAI’s v1 API (https://<resource>.openai.azure.com/openai/v1/, or base_url) |
[llm.azure] resource, model (the deployment, required), api_key (else AZURE_OPENAI_API_KEY, or ANTHROPIC_FOUNDRY_API_KEY for Claude; sent as api-key or x-api-key), or auth = "entra": Azure’s default credential chain (environment, workload and managed identity, the Azure CLI and Developer CLI logins), a token for cognitiveservices.azure.com or ai.azure.com per request, one checked when the model is built |
vertex-anthropic |
anthropic with auth = "adc" |
as anthropic’s adc ([llm.anthropic] project and location) |
api |
The openai adapter (Responses API, §3.4) with request and response middleware for gateways that speak it |
[llm.api] base_url, headers, and a token from token_script (shell, Python or TypeScript) put wherever {{TOKEN_SCRIPT}} appears; no API key, no OpenAI settings from the environment |
Since 2026-10-04 Blitz also signs in for the account methods above, as an addition to API keys: the desktop app’s Sign in and blitz auth login run the vendor’s own tool on the service’s machine (gcloud, ant, aws, az; spec_021_service SVC-56), then the service builds the failed models again.
- MDL-10 Empty provider: pick Gemini if a Gemini key exists, else Anthropic if its key exists (its configured model unless
default_modelis set), else OpenAI-compatible if key or base URL set, else local Ollama. Unknown provider: Gemini if a Gemini key exists, else error “unsupported or unconfigured LLM provider”. - MDL-10a 2026-11-04 (scan N26-engine-runtime#17). An unknown provider is an error whatever keys are set (MDL-01a), no longer Gemini when a Gemini key exists.
- MDL-12 2026-10-29. Ollama with no model (
[llm.ollama] modelempty) uses the first model Ollama lists, found on the first call (a stopped Ollama doesn’t stop Blitz starting) and kept (ollamaAuto,pkg/engine/runtime/ollama.go); none pulled, or Ollama not answering, fails the call with what to do (ollama pull …; open the Ollama app orollama serve). An OpenAI-compatible call that fails carries what the provider said (providerError: the SDK’sOpenAI API error: 404 Not Foundleaves the message out), the key and remembered secrets masked; Ollama’s 404 names the model it doesn’t have and suggests choosing one orollama pull. - MDL-12a 2026-10-29 (the owner’s request, after replaying a conversation on
qwen2.5-coder:7b). Ollama’s limits as an agent are said where it’s chosen: with Ollama selected, Settings › Providers showsdesktop.keys.ollama_limitsunder the form (as OpenAI showsopenai_key_only). It says local models are less reliable as agents (small ones describe the steps instead of running them, or write tool calls as text), and to choose one with strong tool calling (such asqwen3:8bor larger) for agent work, leaving small ones for chat and quick questions. The providers guide’s Ollama section says the same at more length.
- MDL-20 Default model
claude-opus-5; defaultmax_tokens16000 unless the request sets one. - MDL-21 The system instruction becomes one system text block with ephemeral cache control (prompt caching).
- MDL-21a Tool and rolling conversation cache breakpoints (spec_056 CA-28): besides the system block, the adapter places an ephemeral
cache_controlbreakpoint on the last tool declaration (p.Tools[len(p.Tools)-1]) and on the last cacheable content block of the conversation’s last stable turn (the second-to-last message,p.Messages[len(p.Messages)-2], whenlen(p.Messages) >= 2), so the tool prefix and earlier turns and tool results are read from the prompt cache as the conversation grows. - MDL-22 Function declarations become tools with JSON Schema input (raw JSON schema preferred; genai
Schemaconverted: lower-case types, enums, formats, items, properties, required, nullable →[type,"null"]). An absent schema is an empty object. - MDL-23 Contents map to messages; consecutive same-role contents merge (so parallel tool results share one user message). The conversation must start with a user message.
FunctionCall⇄tool_use;FunctionResponse→tool_result(JSON body;is_errorwhen the response has a non-emptyerror). An image directly after a tool result is placed inside that tool result (forview_image); other images are image blocks; a PDF is adocumentblock, inside the tool result afterview_document(spec_011_images IMG-53); other unsupported inline media become a text placeholder. - MDL-24 Thinking blocks round-trip unchanged: thinking text in
Thoughtwith its signature inThoughtSignature; redacted thinking is stored with aredacted:prefix. Unsigned thoughts and user-side thoughts are dropped. - MDL-25
temperatureis sent only to models that accept sampling (prefixesclaude-haiku-4-5,claude-sonnet-4-6,claude-opus-4-6,claude-sonnet-4-5,claude-opus-4-5,claude-opus-4-1,claude-sonnet-4-,claude-opus-4-0,claude-3); current models reject it with 400. - MDL-26 Server-side refusal fallback on
claude-opus-5*andclaude-fable-5*:fallbacks = "default"routes by category (betaserver-side-fallback-2026-07-01); a model ID pins one fallback (beta2026-06-01);offdisables. - MDL-26a On Vertex AI (
auth = "adc",vertex-anthropic), which has no server-side fallback, a refusal is retried client-side by the SDK’slib/betafallbackmiddleware on any model: a model ID is the fallback, anddefaultfalls back toclaude-opus-4-8(none when that is the model itself). The middleware wraps Vertex’s, so the retry’s model reaches the URL path. Each session keeps its ownBetaFallbackState(the ADK’s invocation names it), so a session that fell back stays on the fallback and others start on the primary (BL-ENG-22). - MDL-27 Streaming yields partial text deltas, then one aggregated final response (same shape as Gemini). Non-streaming yields one response. A non-streaming request the SDK won’t send unstreamed (
max_tokensa reply could take more than ten minutes to fill: an engine turn’s full output, or a thinking budget) is streamed anyway and yields only the final response, rather than failing with “streaming is required for operations that may take longer than 10 minutes” (2026-10-29: the coder subagent on[llm.api]). - MDL-28 Stop reasons:
max_tokens→ MaxTokens;refusal→ Safety withErrorCode=refusaland the note “The model declined to continue this request. ()” appended as text; else Stop. An empty final response gets one empty text part. ModelVersion= the model that served. - MDL-28a 2026-11-04 (scan N26-engine-runtime#23: a tool_use cut off at
max_tokenswent to the tool with{}, the SDK having emptied its unfinished input). A tool call the reply stopped in (the last block of amax_tokensreply, or input that doesn’t parse) isn’t run: the reply gets the note “(The call towas cut off before its arguments were complete, so it wasn’t run.)”, and the turn ends with ErrOutputLimitas before. - MDL-29 Usage: prompt = input + cache reads + cache writes; cached = cache reads; cache writes reported via
CustomMetadata["cache_creation_input_tokens"]. - MDL-30 Errors: 401/403 → “authentication failed … check llm.anthropic.api_key or ANTHROPIC_API_KEY”; 429 → “rate limited” (unless it’s a quota, MDL-30a); other status → “API error (N)”.
- MDL-30a Quota: a refusal with Google’s
RESOURCE_EXHAUSTED— a genaiAPIErrorwith that status (Gemini, on the API or Vertex AI), or a 429 whose body is a Google error (or a list of them, as Vertex AI sends) with that status (Claude on Vertex AI) — is a*runtime.QuotaError: “quota exceeded: <Google’s message> (raise the quota in the Google Cloud console, IAM & Admin › Quotas, or wait for it to reset)”, never “rate limited”. Every provider model’s errors pass through it (the settings wrapper), so turn errors,doctor --onlineand job runs say so;ModelErrorSummarykeeps a quota error whole, on one line, where it keeps only the first line of others. SDK retries still apply (a per-minute quota recovers).
- MDL-40 Never streams (text-encoded tool calls are only recognisable in complete responses).
- MDL-41 Text tool calls: a text part that is (optionally code-fenced) JSON
{"name", "arguments"|"args"|"parameters"}becomes aFunctionCallonly if the name is a tool offered in that request, so quoted JSON can’t trigger arbitrary tools.file_pathis aliased topath. - MDL-42 Images: the ADK OpenAI model rejects image parts, so each image is replaced by a unique marker text (prefixed U+2063) and a request middleware swaps markers for
input_imagedata URLs in the outgoing JSON. Markers travel in the request context; nothing is shared between requests.
- MDL-45 Every model is wrapped so stored-image references in a request are expanded to bytes just before sending; history and session files only ever hold references (spec_011_images).
Since 2026-10-21 (the owner’s request: a provider for a gateway that speaks OpenAI’s Responses API but signs requests with its own headers and a short-lived token).
- MDL-100 Settings:
[llm.api]base_url(required, absolutehttp/https; a model’s requests go to its API’s path under it, MDL-113),model,headers(a table of header name → value, at least one),token_scriptandtoken_script_language(shell, the default,pythonortypescript). A model is built through the adapter for the API it speaks behind the gateway (MDL-100b); for the Responses API that is theopenaiadapter (§3.2: images, text tool calls; streaming as MDL-100c says) with Blitz’s shared HTTP client (§4). Config that breaks these rules fails the build (the model is then unavailable, WS-05), saying which rule: a bad URL,{{TOKEN_SCRIPT}}in the URL’s scheme or host, no headers, a header name that isn’t an HTTP token,{{TOKEN_SCRIPT}}used with notoken_script, atoken_scriptthat nothing uses, an unknown language. - MDL-100b Until 0.9.10; MDL-112 and MDL-113 replace the name’s choice and the one path with settings. The model’s name decides the API its requests are written in, since a gateway passes each vendor’s request on as it is: a
claude…model speaks Anthropic’s Messages API through theanthropicadapter (§3.1: streaming, prompt caching, thinking, tool use; no server-side fallback,fallbacks = "off"), any other model OpenAI’s Responses API. Both are sent to<base_url>/responses(the anthropic adapter’s/v1/messagesand its?beta=trueare rewritten) and signed alike (MDL-101–105). The anthropic client takes nothing from the environment (ANTHROPIC_API_KEY,ANTHROPIC_BASE_URL), and its placeholder key’sX-Api-KeyandAuthorizationare removed unless configured. MDL-104’s body rules and MDL-104b and MDL-106 are the Responses API’s; a Messages request and answer are the anthropic adapter’s as they are. Verified 2026-10-21 against a gateway:claude-sonnet-5-5(Messages, tool use),gpt-6-luna(Responses, tool use); that gateway’sgemini-…models answered500to both formats, so Gemini’s own API isn’t offered. - MDL-100c Built (2026-11-01). The
apiprovider asks for the Responses API streamed (stream: true), so a long reply keeps data flowing and is never cut by a timeout between Blitz and the model, as Claude’s Messages are streamed (MDL-27). The openai adapter reads replies whole, so the stream is folded into the one response its last event carries (response.completed,response.incomplete, orresponse.failed, whose error fails the call; anerrorevent fails it too, and a stream that ends without one is “the model’s reply ended before it was complete”); comments and events Blitz doesn’t need are skipped (foldStreaminpkg/engine/runtime/apiresponse.go). A gateway that refusesstreamas OpenAI refuses a parameter (400withparam: "stream", as gateways and Blitz Enterprise services before GW-04 do) gets the request again unstreamed, and the model’s later requests are sent whole, so it’s asked once. A gateway that answers a streamed request with plain JSON is read as before. - MDL-101
{{TOKEN_SCRIPT}}(exactly that) in a header’s value or inbase_url’s path or query is replaced, on each request, by the token: every occurrence, in the URL escaped as a query value. It is never replaced in the request body, which holds the conversation. The script isn’t run when nothing uses the placeholder. - MDL-102 The token is the script’s output, trimmed; empty output, more than one line, a failure or 30 s without finishing is an error naming the script’s language and its standard error (trimmed to 256 characters, any token in it redacted).
shellruns/bin/sh -c <script>;pythonrunspython3 -c <script>;typescriptwrites the script to a temporary.tsfile and runsnode --experimental-strip-types --no-warnings <file>(Node 22.6 or later). A missing interpreter says which one to install. The script runs with the service’s environment, outside the agent’s sandbox, likeapi_key_command(MDL-55); a project’s settings can’t set it (CFG-05,llmis never taken from a project). - MDL-103 The token is kept per session (the ADK session the call belongs to; calls outside a session share one entry), in memory only, for at most 64 sessions (least recently used dropped). The script runs when a session first needs a token and again after the token is dropped (MDL-105); a new session runs it afresh. Concurrent calls in one session share one run. Since 0.9.10, one cache serves every model and the model list (MDL-114) with the same token script (its language and text), so listing the gateway’s models doesn’t run the script again for a call, nor a call for a listing. It isn’t run when the model is built, so a short-lived token isn’t spent before a session starts;
blitz doctor --onlineruns it in its model request (MDL-109). A script that fails ends the call before any request is sent, with[llm.api] token script: <error>, and nothing is kept. - MDL-104 Requests: the configured headers are set on each one (replacing the SDK’s).
Authorization,OpenAI-OrganizationandOpenAI-Projectare removed unless configured, so no OpenAI key or setting from the environment (OPENAI_API_KEY,OPENAI_ORG_ID,OPENAI_PROJECT_ID) reaches the gateway; the SDK is given a placeholder key for the same reason. APOSTto…/responsesalways has"store": falseand"stream": falsein its JSON body; the rest of the body is kept as the adapter wrote it, except for MDL-104b. - MDL-104b The request follows the model, not the adapter: a model known to reject sampling gets no
temperatureortop_p(current Claude models, assupportsSamplingdecides for the anthropic provider, and OpenAI’s reasoning models,gpt-5*,o1*,o3*,o4*). A gateway’s model names can be aliases, so a400that refuses a field (OpenAI’scodeunsupported_parameterorunsupported_valuewith itsparam, or a messageUnsupported parameter: '<field>'orUnsupported value: '<field>' …) is sent again without that field, and the model’s requests leave it out from then on (in memory, until the service restarts). Only fields a request can do without are dropped:temperature,top_p,reasoning,max_output_tokens,parallel_tool_calls; a refusal of any other field is the call’s error. - MDL-105 Errors: a
401or403drops the session’s token, runs the script once more and sends the request once more with the new token. A second401/403(or a script failure then) fails the call with[llm.api] the API rejected the token (HTTP <status>). Check the token script, sign in again if needed, then retry(no final full stop, as for every error), never read as a model response. A connection error or5xxdrops the session’s token, so the SDK’s retry (MDL-52) runs the script for a fresh one. Any other HTTP error reads[llm.api] HTTP <status> <text>: <reason>, the reason being the body’serror.message, else the start of the body (either redacted, MDL-108, and cut to 256 characters), since the SDK’s own text is only the status. An error response the SDK can’t read (the gateway’s own{"status":500,"error":"Internal Server Error",…}) is reported the same way, from the status and body the middleware keeps for the call’s last attempt. Every api provider error starts[llm.api], never the adapter’sopenai: call failed, whatever model the gateway serves; an Anthropic error’s own text, which quotes the request’s URL, isn’t used. - MDL-105a 2026-11-04 (scan N26-engine-runtime#15, #16: the errors’ hints named the wrong credentials where an adapter is reused, and the organization’s errors said
[llm.api]and “the token script”). A refused sign-in names what to check for how the model signs in:[llm.anthropic]’s key orapi_key_command,ant auth login(auth = "oauth"), Google Cloud’s credentials (Claude on Vertex AI), AWS credentials and[llm.bedrock], or[llm.azure]’s key or Entra sign-in. Every OpenAI-compatible model’s error adds what the server said, masked (providerError), Azure OpenAI’s and those built without a provider name too. Through an organization’s service (theenterpriseprovider) the errors are its: “your organization’s service refused your sign-in (HTTP 401): sign in again (Settings › Organization, or blitz enterprise login), then retry”, and other errors “your organization’s service: HTTP 404 Not Found: …”, without[llm.api]. Gemini’s errors other than quota still carry the SDK’s text only. - MDL-106 Responses: a successful (
2xx) JSON response from…/responseswhoseerror.messageisn’t empty is a failure, whatever itsstatus(the gateway can answer200with a logical error): it is read as"status": "failed"(the adapter’sErrResponseFailed, quoting the message). A message’s content part of typetextis read asoutput_text. Everything else is the adapter’s: output items in order (reasoninggives only hidden thoughts;function_callitems become calls, whose results go back asfunction_call_outputwith the samecall_id),usageas tokens, no text and no call an error (ErrNoTextOrToolContent). - MDL-107
providerOfnames theapimodel by its API (MDL-100b):anthropicfor a Claude model, so per-model settings are Anthropic’s (supportsSamplingand the rest, MDL-72), elseopenai, so they dropseedas for OpenAI. - MDL-108 Tokens never reach logs, the audit log, errors or
doctor’s output: each token is remembered by the redactor (redact.Remember, pkg/redact) when fetched, and errors quote the script’s standard error only after redaction. - MDL-108a 2026-11-21 (re-check of N26 engine-runtime#27). The organization’s token fetched again after a
401is remembered by the redactor too, not only the first. - MDL-108a 2026-11-04 (scan N26-engine-runtime#27). The organization’s access token (the
enterpriseprovider) is remembered by the redactor too, each time it is fetched. - MDL-109
blitz doctorreports theapiprovider under credentials: MDL-100’s checks, its endpoint and its headers by name (never a value), and whether the token comes from a script. The script isn’t run for that;--online’s model request runs it first, so its result says which failed: the script ([llm.api] token script: …), the token (MDL-105) or the model.blitz models apilists only[llm.api] model, as for Bedrock and Azure (MDL-56). - MDL-112 0.9.10 (issue #105: the gateway’s models each speak their own API, and Blitz can’t know every gateway’s). Each model’s API is the settings’:
[llm.api.apis]maps a model’s name to one ofresponses(OpenAI’s Responses API, theopenaiadapter),chat_completions(OpenAI’s Chat Completions, what OpenAI-compatible servers speak: the same adapter,openaimodel.APIChatCompletions),messages(Anthropic’s Messages, streamed: Claude’s, and Anthropic-compatible servers’),gemini(the Gemini API’sgenerateContent) orvertex(Vertex AI’s, for Google’s models);"*"is every model not named. A model in neither goes by its name (APIOf):claude…Messages,gemini…the Gemini API (before 0.9.10, the Responses API), any other the Responses API. Google’s two go through thegeminiadapter with a placeholder key (Vertex AI’s express mode: no project, location or Google credentials, none taken fromGOOGLE_CLOUD_PROJECTor the rest of the environment) and the provider’s middleware as its client’s transport, so they’re signed, retried, and their errors worded as the others’ (MDL-101–105);X-Goog-Api-KeyandAuthorizationare removed unless configured. Per-model settings follow the API (MDL-107: Google’s aregemini’s, with their thought signatures kept); no provider-side tools are offered through the gateway, so Gemini’sinclude_server_side_tool_invocationsis never sent. An API that isn’t one of these fails the build, naming the model and the five. - MDL-113 Each API’s model requests go to its path under
base_url:[llm.api.paths]by API, else/responses(Responses, and Messages, where gateways that route by the request’s model take Claude’s),/chat/completions,/models/{model}:{method}(Gemini) and/publishers/google/models/{model}:{method}(Vertex AI).{model}is the model’s name as it is (a/in it stays a path separator, as gateways that route on it expect; Google’s names have none) and{method}Google’sgenerateContentorstreamGenerateContent(a streamed call,?alt=ssekept); nothing else is filled in, and a path is a path alone: it starts with/and has no query, fragment, spaces or{{TOKEN_SCRIPT}}. Since 2026-11-14 (the owner’s request: the gateway shouldn’t enforce Google’s) the fill-ins are offered, never required: a Google path without{method}(or{model}) is the gateway’s to route, such as one fixed path for every Gemini call; the form shows each API’s fill-ins in a tooltip (an ⓘ beside its path) instead of requiring them.base_url’s query goes on every request (MDL-101). Requests that aren’t model calls go where the adapter sends them. The organization’s service (spec_053_enterprise EN-20) takes Claude’s at/messages. - MDL-114 The gateway’s models are what it lists: a
GETtomodels_pathunderbase_url(default/models), signed as the model requests are, whose JSON is read in the shapes servers give it:{"data": [...]}(OpenAI’s, Anthropic’s and compatible servers’),{"models": [...]}(Gemini’s,models/dropped, those that can’tgenerateContentleft out; Ollama’s), or a list; each entry anid,modelorname, or the name alone. The first page only.models_path = "none"says the gateway doesn’t list them: the menus havemodel,modelsand the models[llm.api.apis]names ("*"aside; MOD-42, which[llm.api] modelsis too). A list that fails (an HTTP error, worded as MDL-105’s; not JSON; empty) is the provider’s error beside those configured models, the default path’s included: a gateway with no list says so (HTTP 404) untilmodels_pathis set ornone(the owner’s call, 2026-11-10: errors are reported, never hidden).blitz models api, the model menus andblitz doctor(each model’s API and path, and where the list is) use it. - MDL-115 2026-11-12 (#111). The list can be on another server:
models_pathis a path underbase_urlor an absolutehttp/httpsURL ({{TOKEN_SCRIPT}}only in its path or query, asbase_url’s).[llm.api.models_headers]sign the list’s request in place ofheaders,{{TOKEN_SCRIPT}}in them as inheaders(the gateway’s token script and cache, MDL-103). A path underbase_urlor a URL on its server (scheme, host and port) is sentmodels_headers, else the gateway’sheaders, and a path getsbase_url’s query; a URL on another server is sentmodels_headersalone, never the gateway’s headers or query, so none of the gateway’s credentials reach it. Header names and values are checked asheaders’ are (MDL-100). Describe withholds their values as it doesheaders’ (CFG-44); the desktop form shows Model list headers under the list’s field while the gateway lists its models (DSK-61), andblitz doctornames them (“models listed at https://catalog.example.com/models with headers X-Catalog”, or “with no headers”). - MDL-110 The settings are written by
SetProviderwithApiProviderSettings(spec_002_config CFG-45b) and shown byDescribeConfigwith header values withheld (CFG-44), so the desktop form (spec_024_desktop DSK-61) never receives one. - MDL-111 2026-10-26 (the owner’s usability pass).
ConfigService.CheckApiKeytries a key that isn’t saved: the scope’s settings with the key in place of the provider’s own (its key command and sign-in set aside: Gemini’s and Anthropic’sauthcleared), listing the provider’s models with it (ListModels’ listing, so the same timeout and retries). It answers whether the key works, why not, and the models it reaches; nothing is written, and the key isn’t kept or cached. It takes gemini, anthropic and openai; other providers, or an empty key, are refused (InvalidArgument). The desktop form tries a key as it’s pasted (spec_024_desktop DSK-104).
- MDL-50 All SDKs share an HTTP client: dial timeout 30 s, TLS handshake 15 s, response-header timeout = stall limit, and a body wrapper that cancels the request if no bytes arrive for the stall limit (each read resets the timer), returning
ErrStalled“model API stopped responding: no data for”. - MDL-51 Stall limit =
llm.stall_timeout_seconds(default 600 s; ≤0 → 10 min). It also bounds non-streamed generations, so it must exceed the longest one. - MDL-51a 2026-11-04 (scan N26-engine-runtime#19: the default was written twice and the error named no setting). The default is
config.DefaultStallTimeoutSeconds(600), used by both; the error says “model API stopped responding: no data for 10m0s (llm.stall_timeout_seconds sets how long to wait)”. - MDL-51a The client health-checks its HTTP/2 connections: one that receives nothing for 30 s is pinged and closed when no answer comes within 15 s. Its requests fail with a connection error, which the SDKs retry on a new connection, so a connection dropped without a word (a VPN, NAT or network change) costs under a minute rather than the stall limit for each attempt. A slow model still answers pings and isn’t cut off.
- MDL-51b When a request’s connection fails (not cancelled) and retries are on (
llm.max_retries> 0), the transport tells the turn in passing (runtime.WithTurnStatus, atransientnotice): “model.reconnecting”, with the gist of the error (“unexpected EOF”, not the method and URL). Clients are shared by stall limit and whether retries are on. Background tasks don’t send it to the turn. - MDL-52 Retries =
llm.max_retries(default 3; negative → 0) on rate limits, overload, 5xx and dropped connections. Gemini:Attempts = retries+1, initial delay 1 s, max 30 s. Anthropic and OpenAI: SDK backoff (0.5 s doubling to 8 s with jitter, honouringRetry-After). - MDL-53 A stream that fails after output has been shown is not retried.
- MDL-54 Proxies (PAR-MOD-05): the shared client clones Go’s default transport via
pkg/netutil(netutil.CloneDefaultTransport), soHTTPS_PROXY,HTTP_PROXYandNO_PROXYapply, as they do to MCP and web search.[network] ca_file(a PEM bundle) is loaded throughpkg/netutil(netutil.SetExtraCAs, invoked byengine.SetupNetworkwhen a workspace opens; an unreadable file or one without certificates is a warning) without mutatinghttp.DefaultTransportin place across concurrent requests, so every client built withnetutil.CloneDefaultTransportornetutil.NewClienttrusts it,web_fetchincluded (vianetutil.TLSConfig).web_fetchalso goes through the proxy the environment names: the host is resolved and every address checked as public first (unlessweb.allow_private), and only the proxy’s own address, often private, is dialled without the check (spec_008_web WEB-04).[network]is never taken from a project. The browser’s traffic doesn’t go through an upstream proxy. - MDL-55 Keys from a command (PAR-MOD-04): with
api_keyempty,llm.<provider>.api_key_command(gemini, openai, anthropic) runs through/bin/shwhen a model is built (a failure, an empty output or more than one line fails the build) and again whenapi_key_ttl(a Go duration, default 5m) has passed; each request carries the current key (Gemini’sx-goog-api-key, OpenAI’sAuthorization: Bearer, Anthropic’sX-Api-Key), so a rotated key keeps working in a long session. The output is cached in memory only, per command and TTL, and shared by the models using it; the command has 30 s. A provider with a key command counts as set up (blitz models, project models). - MDL-56
blitz models [provider…](PAR-MOD-03) asks each configured provider (a key or key command,adc,oauth; Ollama when it’sllm.provider; Bedrock and Azure, which show only their configured model, their consoles listing the rest), or those named, for its models, in parallel with 20 s each, through the same clients: Gemini’s model list (those that generate content,models/stripped), Anthropic’s and OpenAI’s (OpenAI-compatible, Ollama’s too) model endpoints. Each is printedprovider/modelwith the price Blitz knows (input and output per million tokens,[pricing]included) or-. A provider that can’t answer is shown with why, and the command exits 1; none set up is a usage error.
- MDL-60 The chain reports the primary’s name. It tries models in order, skipping those whose circuit breaker is open (threshold: 1 failure — SDK retries already ran). If every breaker is open, it tries them all rather than fail unasked. Breakers are consulted just before each attempt (a half-open trial is reserved).
- MDL-61 It moves on only when a model fails before yielding anything. After output has been yielded, an error ends the call (a failure is recorded). Cancellation never moves on and records no verdict (
Abandon). A consumer stopping early counts as success. - MDL-61a 2026-11-05 (scan N26 engine-runtime#20: the spec didn’t say which errors move on; the owner decided every one does). The chain moves on, and opens the failed model’s breaker, for every error a model returns before yielding anything, client errors included: a 400, 401/403 (a broken key), 404 (an unknown model), a context too long, an organization’s budget refusal (
ErrOrgLimit), as well as 5xx, 429/529, connection failures and stalls. A cancelled call (context.Canceled, or its context done) is still no error to fall back on. So that a broken key or a bad model name isn’t hidden behind the fallback, the fallback’s response also carries the primary’s error (CustomMetadata["blitz_fallback_reason"]: this call’s, or, while its breaker is open, the one that opened it; one line, cut at 300 characters), and the notice names it: “model.fallback_error” ("failed ( ); answering with fallback for now."), “model.fallback” when no error is known. - MDL-61b 2026-11-05 (spec_056 CA-111). One error doesn’t move the chain on at once: a context too long (
api.ErrContextLength). The conversation is summarised to fit and the same model tried again first; only then does the chain move on. - MDL-62 A response from a fallback is marked
CustomMetadata["blitz_fallback_from"] = <primary>andModelVersion = <fallback>if empty, so cost is priced by the model that answered. - MDL-63 If all fail: “every model failed:
”. - MDL-64 The engine notifies the user once when a fallback starts answering (“model.fallback”) and once when the primary is back (“model.fallback_recovered”), not on every call. During a turn the notice is one of the turn’s events (
notice,runtime.WithTurnNotices), so the terminal and the desktop show it in the conversation; outside a turn it goes toWithNotice(the service’s log). - MDL-64a 2026-11-04 (scan N26-engine-runtime#8: the state was one per engine, so a background task on its fallback and the turn on its primary flipped the notices on every call, and “is answering again” named the active agent’s model). “Once per change” is per run: per session, and per background task apart from it. “model.fallback_recovered” names the primary that recovered. Forgetting a session drops its state.
- MDL-65 Breaker behaviour (
pkg/engine/breaker): after the threshold the breaker opens for 15 s, doubling up to 5 min; then one half-open trial call is allowed.
- MDL-70
[model_settings."<model>"]keys are normalised to the bare model name (provider prefix dropped); when bothgpt-5andopenai/gpt-5exist, the bare key wins deterministically. - MDL-71 Every built model (primary, each fallback, each pinned agent’s model) is wrapped to apply its own settings on each call from a lookup carried in the run context, so changes apply from the next call, even in turns already running. The request is copied, never mutated (it is shared across the chain). (Decision: settings apply per built model, not per agent; applying them per agent would give fallbacks the primary’s settings.)
- MDL-72 Unsupported settings are dropped from the request (debug-logged) and reported by
/model_settings: OpenAI/Ollama have noseed; Anthropic acceptsmax_tokens, andtemperatureonly on sampling-capable models;top_pandseedare not sent to Anthropic. Gemini accepts all. - MDL-73
reasoning_effort(minimal|low|medium|high|max;xhighis read asmax) andthinking_budget(tokens,0= off) become genaiThinkingConfig(level and budget;maxishighthere). The OpenAI adapter maps them toreasoning.effort(a budget only chooses none or some). Gemini 2.5 takes no level; Gemini 3 rejects a level with a budget, so the level wins. Anthropic: the exact effort reaches the adapter in the request context and goes tooutput_config.effort(minimal→low) on models that take it (Opus 4.5, Sonnet/Opus 4.6+, and models without sampling parameters); a budget becomesthinkingenabled (at least 1024,max_tokensraised above it, notemperature) or disabled at 0, on Claude 3.7 and later. Models that think adaptively (those without sampling parameters: Opus 4.7 and later, Sonnet 5, Fable) refusebudget_tokens: there a budget above 0 sendsthinkingadaptive and, unless an effort is set, the effort it stands for (up to 4096 tokenslow, 16384medium, 65536high, above thatmax);0sends disabled, except to models that always think (Opus 5.5, Fable), which refuse it: it isn’t sent, andSettingApplies(the value-awareSettingSupported) makes/model_settingsreport it unsupported (MDL-72). Thinking blocks round-trip with their signatures (MDL-24). - MDL-73a 2026-11-05 (spec_056 CA-10, CA-13). Each model has one record (
ModelInfo), which these rules read:- Names: Bedrock’s (
us.anthropic.claude-…-v1:0), Vertex AI’s (claude-…@version) and Gemini’s (models/…) are read as the model they name. Claude on Bedrock now takes its effort, thinking and sampling settings as Claude does elsewhere. - Learned refusals: a setting a model refuses with a 400 (OpenAI’s “Unsupported parameter”, Gemini’s “Unknown name”, Anthropic’s “Extra inputs are not permitted”) is learned and left out from then on, the call sent again once without it. So are tools, images, a stream, system instructions and reasoning settings.
- Kept and cleared: what’s learned is kept in
~/.blitz/models.learned.tomlfor 30 days.blitz models forget <model>clears it.
- Names: Bedrock’s (
- MDL-74 The session effort (
/effort,--effort,SetSetting effort) overrides every model’sreasoning_effortfor the requests only:ModelSettingsand saved settings are unchanged.auto(or empty) clears it. It is not persisted.
- MDL-85 What each model takes as attachments, and how (inline, uploaded, as text), is
runtime.AcceptedMedia(spec_011_images IMG-62): Gemini images (HEIC too), PDFs, text, audio and video (Files API above 14 MB, on the Gemini API); Claude images, PDFs and text; others images, text and PDFs as their text. The expansion wrapper routes each stored file by it (IMG-64), and an Anthropic request takes text files as text blocks.
- MDL-90
[audio] model(provider/model) is the speech modelgenerate_audioreads aloud with (spec_006_filetools FS-74); empty, the default, means none.runtime.NewSpeakerbuilds it when the workspace opens and again when its settings are reloaded (a key or the model set in the desktop): a Gemini speech model through genai’s client as[llm.gemini]signs in (an API key, a key command or Application Default Credentials on Vertex AI), or an OpenAI one (/audio/speech, with[llm.openai]’s key and base URL). Another provider is refused (“can’t generate speech”), and a model that can’t be built is a warning when the workspace opens, never a failure, and is reported by the workspace’s settings (speech_error). - MDL-91 Gemini: each chunk of text (at most 4,000 characters, cut at paragraphs, then lines, then sentences, then words, so a conversation’s lines stay whole) is one
generateContentcall with response modalityAUDIOand a prebuilt voice ([audio] voice, the call’s, elseKore), or for two speakers a multi-speaker voice configuration (each{name, voice}, defaultsKoreandPuck) and the prompt “TTS the following conversation between A and B:”. The 16-bit PCM of every chunk (its rate from the media type, 24 kHz by default) is joined and given a WAV header; the result has its length in seconds. - MDL-92 OpenAI: MP3, the voice the call’s or
[audio] voice, elsecoral. Two speakers are spoken turn by turn (a run of one speaker’s lines, a line naming no speaker staying with the last), each in its voice (defaultscoralandash), and the MP3s joined; one voice is spoken in chunks of 4,000 characters. - MDL-93 A speech call’s usage (Gemini’s tokens, summed over its chunks; reported even when a chunk fails) goes in the session’s usage, priced by
[pricing](defaults forgemini-2.5-flash-preview-ttsandgemini-2.5-pro-preview-tts) but never as the conversation’s last prompt; a call without usage (OpenAI’s) makes the session’s cost unknown rather than wrong. - MDL-95 2026-11-06.
[images] model(provider/model) is the image modelgenerate_imagedraws with (spec_006_filetools FS-80); empty, the default, means none.runtime.NewPainterbuilds it asNewSpeakerbuilds the speech model (when the workspace opens and when its settings are reloaded), a Gemini image model through genai’s client as[llm.gemini]signs in; another provider is refused (“can’t draw pictures”), and a model that can’t be built is a warning, reported by the workspace’s settings (image_error). A call is onegenerateContentwith the prompt and the pictures to start from, response modalitiesTEXTandIMAGE, and anImageConfigwhen a shape or size is asked for. The first picture in the answer is kept (thoughts skipped, its text returned with it); an answer without one is an error giving the model’s text, its finish reason or the prompt’s block reason. - MDL-95a 2026-11-06 (the owner chose the organization’s
gemini-3.1-flash-imageas a conversation’s model and got “openai: response included no output items”). The organization’s image models.[images] model = "enterprise/<id>"(or the bare id when[llm] providerisenterprise) draws through the organization’s service:newOrgPaintersigns with the person’s session as the organization’s models do (enterpriseProvider, EN-20) and posts a Responses request to/api/v1/responseswith animage_generationtool (aspect_ratio,image_size: the enterprise gateway’s GW-04b) and the pictures to start from asinput_imagedata URLs; the firstimage_generation_call’sresultis the picture (its type sniffed), the messages’ text comes with it, andusageis billed as MDL-96 says. A model the organization doesn’t offer by that id is refused, never its default; a Messages model (Claude) can’t draw. Afailedanswer gives the service’s message (GW-04c’sempty_outputincluded), an HTTP error the service’s words. In a conversation, a picture in an organization model’s answer (or any[llm.api]gateway’s) reaches it as a picture: the api provider swaps eachimage_generation_callitem, whole or streamed, for a marker message the ADK adapter reads, keeping the picture in the call’s context, and puts the picture back in its place (apipictures.go); it is then kept like any picture a model made (spec_056 CA-70). - MDL-96 An image call’s usage goes in the session’s usage as a speech call’s does (MDL-93), as an
imagecall in its ledger (RecordMedia), priced by[pricing]: defaults forgemini-3.1-flash-image($0.50 in, $60 out a million tokens, about $0.067 a 1K picture),gemini-3.1-flash-lite-image($0.25, $30) andgemini-3-pro-image($2, $120). - MDL-97 2026-11-06.
gemini-4-argon’s default price is its published one, no longer a placeholder at Gemini 3.8 Flash’s: $2 in, $10 out and $0.10 cached a million tokens through 2026-11-30, then $4, $20 and $0.20 (aPriceChangesentry). - MDL-97a 2026-11-26 (the owner’s figures). The rest of Gemini 4 is priced too, a million tokens, output including thinking tokens:
gemini-4-carbonas Argon ($2 in, $10 out, $0.10 cached through 2026-11-30, then $4, $20 and $0.20: its ownPriceChangesentry);gemini-4-neon$3, $15 and $0.15;gemini-4-hydrogen$1.50, $7.50 and $0.075. A dated version (gemini-4-carbon-001) has its model’s price (PriceFor’s longest prefix); a Gemini 4 model not listed has none. spec_002’s pricing line, which still gave Argon its placeholder price, says the same now.
- MDL-80
MockLLMreturns scripted contents in order (then “Done.”), records requests, and can attach usage,ServedByand metadata. It backs tests; a model that can’t be built isNewUnavailableModelinstead, which fails every call (WS-05).
- Reasoning settings per model (effort, thinking budgets) are not implemented.