Native Modelsdoc/{zh,en}/design/plugins/native-models.md

Native Model APIs: the Anthropic and Gemini Plugins

Status: 2026-12-04, media harness review finding M-18 (the review is in PR #195). Built: the model plugins anthropic (Anthropic's Messages API) and gemini (Google's Gemini API), th

Status: 2026-12-04, media harness review finding M-18 (the review is in PR #195). Built: the model plugins anthropic (Anthropic's Messages API) and gemini (Google's Gemini API), the shared packages pkg/modelhttp and pkg/modelfiles, and the CI workflow of section 7. Verified offline only, against local fake servers (plugins/anthropic/*_test.go, plugins/gemini/*_test.go, pkg/modelfiles/files_test.go); no call to either vendor has been made, as no key was available. The provider families, errors and usage are in LLM providers; how files reach a model, in native media at the model boundary.

1. Scope

The openai plugin speaks the Chat Completions dialect only, so Claude and Gemini could be used only through compatible endpoints, which give neither a PDF as a document block, nor audio and video natively, nor a vendor's file API. M-18 asks for native adapters that declare their limits through the model contracts, with no Host branch for either vendor. Both plugins are builtin, default: available (off until an admin adds an instance), role model, egress: in_process.

2. Shared Packages

PackageResponsibilityUsers
pkg/modelhttpSSE events (Events), status classification (Classify) and wait hints (WaitError), the in-place retry before text (Retrier), one streamed request (Streamer), client options, portable tool names, Recallopenai, anthropic, gemini
pkg/modelfilesThe uploads of one instance: orchestrator Files, provider port Vendor (Upload, Delete, Find), records in the instance's data directoryanthropic, gemini

plugin.Usage gains cache_write_tokens, which Cost.Of prices at cost.cache_write; plugin.CacheConfig is the cache option all three plugins read; plugin.Reasoning.Effort picks the effort to send; plugin.Message.Text joins a message's text. The Host changed in one generic place: a step refused as llm.payload_too_large while it carried native files is sent once more with them parsed, as llm.input_rejected is (C5).

Recall keeps what a vendor wants back with an answer's tool calls and the runtime does not keep (it keeps reasoning as text and renames the calls): Anthropic's signed thinking blocks, Gemini's thought signature. It is keyed by the calls' names and arguments, holds 256 answers, and lives in memory: after a restart an Anthropic answer goes without its thinking blocks, and a Gemini call goes with skip_thought_signature_validator, the value Google documents for a call whose signature is not known.

3. The anthropic Plugin

Configuration (config_schema; the key is the config key api_key, declared as openai declares it, sensitive with x-init, but required: a literal, ${ENV_VAR}, or ${secret:api_key} after orquelo secret set <instance> api_key; serve --preflight looks the secret up read-only, and an instance without a key is refused there and at load, naming the instance and api_key, never showing a value):

FieldDefaultMeaning
base_urlhttps://api.anthropic.comRequests go to /v1/messages and /v1/files
modelrequiredThe model requested
api_version2023-06-01The anthropic-version header
inputstext, imageOf text, image, pdf; another kind is refused by the schema
max_tokensmax_output, else 8192The API requires an output cap
cache{mode: explicit, cold_after: 5m}none marks nothing; cold_after of 1 h or more asks for the one-hour cache
reasoningunsettoggleable or always sends thinking: {type: adaptive, display: summarized}; efforts go as output_config.effort
inline_max_bytes20 MiBImage and PDF bytes one request carries in base64
file_max_bytes32 MiBA larger PDF is given as its reading (MediaLimits.FileMaxBytes)
files_ttl, upload_timeout6h, 2mThe Files API's records (section 5)
max_retries, idle_timeout, headers, temperature, tool_choice, cost, context_window, max_output, tools, prompt_overlay, image_max_side, image_max_bytesas openai

Request: leading system messages are system blocks; a later system message goes as user text. Tool calls are tool_use blocks under the runtime's ids, results tool_result blocks whose content holds the result's text, images and PDFs; consecutive messages of one role are joined, tool results first. Images go as image blocks, PDFs as document blocks, in base64 while the inline budget lasts and then as {type: file, file_id} from the Files API (the Files API is generally available; a gateway that still needs anthropic-beta: files-api-2025-04-14 sets it in headers). tool_choice none, auto, required go as none, auto, any; the default declared list is auto and none, as the newest models refuse any.

Cache: at most three cache_control marks: the last system block (or the last tool, without a system prompt), the last message of the request's baseline, summary and history zones (ChatRequest.Zones), and the last block of the request, so each call reads the prefix the one before it wrote. Usage: input_tokens is the API's input plus cache_creation_input_tokens plus cache_read_input_tokens; cache_read_tokens and cache_write_tokens are the two.

Stops: end_turn, stop_sequence are end_turn, tool_use is tool_calls; max_tokens and model_context_window_exceeded are max_output_tokens and drop the calls; refusal is content_filter; others are other, or end_turn when the answer has text or calls.

Not built: PDF page counts are not checked before sending (the API's 100- or 600-page limit is enforced by its refusal, which C5 turns into the parsed reading); structured output (output_config.format) is not sent, JSON is asked in the prompt; server tools, citations, Bedrock and Vertex endpoints.

4. The gemini Plugin

Configuration as anthropic, with these differences: base_url defaults to https://generativelanguage.googleapis.com, api_version to v1beta; inputs are of text, image, pdf, audio, video; inline_max_bytes defaults to 14 MiB (the API's 20 MB request in base64), file_max_bytes to 50 MiB, upload_timeout to 5m; cache (implicit or none) is reported only; reasoning sends thinkingConfig with includeThoughts and the effort as thinkingLevel. The key goes as x-goog-api-key, never to the upload URL.

Request: streamGenerateContent?alt=sse; system messages are the systemInstruction; the runtime's tool calls are functionCall parts (with their ids), results functionResponse parts named after their call, {output: text}, the result's files after them. Files go as inlineData within the budget, then as fileData with the File API's URI. JSON answers go as responseMimeType and responseJsonSchema. Declared limits: images PNG, JPEG, WebP, HEIC; audio WAV, MP3, AIFF, AAC, Ogg, FLAC (other audio is converted by the Host's ffmpeg, as for openai).

Usage: input is promptTokenCount plus toolUsePromptTokenCount, cache reads cachedContentTokenCount, output candidatesTokenCount plus thoughtsTokenCount, reasoning the latter. Stops: STOP is end_turn (or tool_calls), MAX_TOKENS max_output_tokens, the safety reasons and a blocked prompt content_filter, MALFORMED_FUNCTION_CALL the retryable llm.bad_tool_call.

Not built: cached content objects (explicit caching), Vertex AI endpoints, video clipping and frame rates (videoMetadata), multimodal function responses.

5. Uploaded Files

modelfiles.Files owns the records of one instance (files.json in its data directory, written whole and renamed into place); the plugin's Vendor does the I/O. A file is keyed by the digest of its media type and bytes, so one content is uploaded once per instance, also by concurrent calls. Without a data directory there are no records and every file goes inline.

StateDeadlineWay out
uploading (recorded before the upload is sent)upload_timeoutReady on success; removed when the vendor refused it (a 4xx other than 408 and 429, ErrNotSent); otherwise it may be held: past its deadline the sweep looks it up by its unique name (orq-<digest>-<nonce>), deletes it if found, and removes the record either way
readyfiles_ttl after the last use; for Gemini at most 47 h after the upload, as the API keeps a file 48 hEach use moves the deadline; past it the sweep deletes the file (a 404 counts as deleted) and removes the record
any, its vendor calls failingeach sweepTried again on the next sweep; after 24 failed sweeps the record is removed and modelfiles.abandoned is logged at error level with the vendor's file id, for the operator to delete at the vendor

The sweep runs when the instance starts and every 10 minutes until it closes; a reload closes it and the next instance reads the records. Gemini uploads are resumable (start, then upload, finalize), and a PROCESSING file is polled until ACTIVE within upload_timeout; a FAILED one is deleted and the step is refused as llm.input_rejected. Logs: modelfiles.uploaded, upload_refused, upload_failed, deleted, never_uploaded, sweep_failed, abandoned.

6. Errors and Traces

Vendor answerCodeIn place
429, rate_limit_error, RESOURCE_EXHAUSTEDllm.rate_limitedRetried, with retry-after up to 60 s; a longer wait ends the call with retry_after_ms
529, overloaded_error (also in the stream)llm.overloadedRetried, with the wait hint
401, 403, authentication_error, Gemini API_KEY_INVALID (a 400)llm.authenticationNo
400 naming an image, PDF, file, audio or video; an upload refusedllm.input_rejectedNo; the Host retries the step with its files parsed (C5)
413, request_too_largellm.payload_too_largeNo; C5 as above when the step carried native files
400 saying the prompt is too long, or "maximum number of tokens"llm.context_overflowNo; the runtime compacts
5xx, api_error, INTERNAL, UNAVAILABLE, a stream error eventllm.server_errorRetried before any text

A success: the step sends a 30 MiB PDF to Claude; the first 20 MiB budget is spent, so the PDF is uploaded (modelfiles.uploaded, file_011…), the request carries {type: file}, the stream settles with cache_write_tokens. A failure and its recovery: Gemini answers 400 "Unsupported MIME type" for an inline video; the call fails with llm.input_rejected, the Host (media.rejected) sends the step once more with the video as its transcript, and the run's later steps send it parsed. A lost upload: the Host stops while a Gemini file is PROCESSING; the record stays uploading; at the next start the sweep finds the file by its name, deletes it, and logs modelfiles.deleted.

7. Continuous Integration

.github/workflows/ci.yml runs on every push and pull request on ubuntu-latest, macos-latest and windows-latest, with Go from go.mod and the actions pinned to commits: gofmt -l (Linux), go build ./..., go vet ./..., go test -race (Linux and macOS; plain go test on Windows, where the race detector needs cgo; on Linux the model worker's test again without it, as its memory bound leaves no room for the detector's shadow memory), and make size (Linux). Tests that need ffmpeg, ONNX models, a browser or a vendor key skip themselves; the media packages run natively on each system. Checkouts keep LF line ends on Windows. Its first run is the one its pull request starts; no result is claimed here.

8. Acceptance

  • ◆Offline, per plugin: streamed text and usage with cache reads and writes; a tool call round trip with its signature kept; image, PDF, audio and video encoding; the file API's upload, reuse, processing wait, failure, deadline and deletion; each error class; missing key, unknown input kind and the default base URL. All pass.
  • ◆Built binary with a scratch home: orquelo plugins lists both; serve --preflight passes with each as the agent's model and never prints the key; a missing key and an unknown input kind are refused; orquelo exec against an unreachable base_url fails with exit 1.
  • ◆Not yet: a live call to either vendor, and native runs on Linux and Windows beyond what CI shows.