Language model connections
Call Anthropic, Google Gemini, OpenRouter, Ollama, OpenAI and vLLM through native adapters with explicit credentials, bounded transport and typed token accounting.
Implementedaner.llm provides service clients for local and cloud inference plus an optional in process local model connection. This page describes the service clients; the native local model guide covers llm.load. Aner constructs and validates requests, resolves an explicit credential reference, verifies transport, and returns a typed response. The selected service performs model inference. Connecting an external language model does not train an Aner neural network or allocate Aner tensors on that service.
For optional direct local GGUF loading, model leases and deployment adapters, see Native local models. Existing service clients retain their contracts.
For implemented native model construction, training, fine tuning and scientific generation, see the from scratch guide, native tokenization and native generative models.
Module guide
Start by constructing a client and checking its configuration, then send one explicit request only after the selected service and model are ready. This module has provider adapters inside one aner.llm import; Ollama, OpenAI, OpenRouter, Anthropic, Google Gemini and vLLM are not separate Aner submodule namespaces.
| Task | Reference | Complete program |
|---|---|---|
| Inspect fictional settings without a request | Configuration only example | Client configuration |
| Generate one answer locally | Local model setup | Local generation; requires your running Ollama model |
| Control history, output and sampling | Explicit request and API reference | Ordered chat |
| Authenticate a cloud request | Cloud credentials and aner.secrets | Cloud generation; requires a configured key and may incur charges |
| Use Anthropic Claude directly | Anthropic | Anthropic generation; requires a configured key and may incur charges |
| Use Google Gemini directly | Google Gemini | Gemini generation; requires a configured key and may incur charges |
| Record input, output and detailed usage | Token accounting | Token usage; one explicit OpenRouter request |
| Access a model through OpenRouter | OpenRouter | OpenRouter generation; requires a configured key and may incur charges |
| Switch OpenRouter models with one private credential | OpenRouter notebook | Aner notebook, Jupyter notebook; two explicit requests |
| Switch Anthropic, Gemini and OpenRouter with per call usage | Provider switching notebook | Aner notebook, Jupyter notebook, plain program; three explicit requests |
| Use another compatible service | Hosted/local service | vLLM; requires your configured server/model |
| Organize or serve the configured client | Research class, inference API | Research assistant, API route |
Check configuration without a service
The complete configuration program uses a fictional reserved hostname and an opaque credential label:
import aner.llm
import aner.secrets
let model = llm.client(provider: "vllm", model: "example-model",
endpoint: "https://llm.example.invalid/v1",
key: secrets.stored("example-llm-key"), timeout_ms: 30000)
let message = llm.message(role: "user", content: "Explain validation data.")
print(model.provider())
print(model.model())
print(message)Run aner check examples/llm_configuration.aner, then aner examples/llm_configuration.aner. No service, stored credential or network access is needed. It prints vllm, example-model and an opaque message handle. Construction validates the settings but does not prove that a real endpoint is reachable or that a model exists. Replace the fictional settings and provision your credential before adding generate or chat.
Capability boundary
| Provider | Native adapter | Default endpoint | Authentication |
|---|---|---|---|
| Ollama | Chat endpoint | http://127.0.0.1:11434 | Optional explicit credential reference |
| OpenAI | Responses endpoint, with store: false | https://api.openai.com/v1 | Required explicit credential reference |
| OpenRouter | Chat completion endpoint | https://openrouter.ai/api/v1 | Required explicit credential reference |
| Anthropic | Messages endpoint | https://api.anthropic.com/v1 | Required explicit credential reference |
| Gemini | Stable v1 Interactions endpoint, with store: false | https://generativelanguage.googleapis.com/v1 | Required explicit credential reference |
| vLLM | Compatible chat completion endpoint | http://127.0.0.1:8000/v1 | Optional explicit credential reference |
The current module implements synchronous text generation and ordered messages. Streaming, model discovery, embedding requests, tool execution, structured response schemas, automatic conversation memory, and additional provider specific controls are future work. A local service and its model must already be running; Aner does not install models or start another service. The service controls its tokenizer, context window, inference hardware, model weights, and scheduling.
OpenAI Responses and Gemini Interactions requests disable response storage through store: false; this setting is not a promise of zero data retention. Provider policies and account settings still govern submitted content. OpenRouter routing and upstream provider retention are governed by OpenRouter and the selected providers, rather than Aner's OpenAI storage setting. Select a provider and endpoint appropriate for the dataset before sending prompts.
Start with a local model
Choose the exact model identifier installed in your Ollama service. This example uses llama3.2:3b; replace it if your service hosts another model.
import aner.llm
let model = llm.client(provider: "ollama", model: "llama3.2:3b")
let answer = model.generate("Explain a linked list in three sentences.")
print(answer.text())Client construction sends no request. generate sends one user message and waits for a bounded response. The default maximum output budget is 512 tokens; temperature is omitted so the service chooses its default. A response can end at that budget before the answer is complete. Inspect finish_reason() when completeness matters.
Run the local example from a terminal whose working directory contains the downloaded program:
aner check llm_local.aner
aner llm_local.anerChecking validates Aner syntax and types without contacting a provider. Running sends the prompt to the configured endpoint. A named model that is absent from the service produces an error rather than selecting another model.
Define an explicit request
Keep messages, generation budget, and sampling settings visible in source when an experiment needs control:
import aner.llm
let model = llm.client(provider: "ollama", model: "llama3.2:3b",
endpoint: "http://127.0.0.1:11434", timeout_ms: 120000)
let messages = List(
llm.message(role: "system", content: "Explain concepts precisely and concisely."),
llm.message(role: "user", content: "Compare a linked list and a fixed array."))
let answer = model.chat(messages, max_tokens: 256, temperature: 0.2)
print(answer.text())
print(answer.model())
print(answer.finish_reason())
print(answer.input_tokens())
print(answer.output_tokens())A message list is nonempty, ordered, and contains only LLMMessage values. Roles are exactly "system", "user", or "assistant". The runtime admits at most 256 messages. Anthropic and Gemini accept system messages only at the start; Aner combines their content into the provider’s separate system instruction, and the remaining history must start with a user message. Each request supplies its complete intended history; an earlier call does not silently add messages to the next call.
max_tokens is an integer from 1 through 1,000,000, subject to stricter model or service limits. An explicit temperature must be finite and between 0.0 and 2.0, with an Anthropic limit of 1.0. Gemini stable v1 Interactions does not support the temperature parameter; Aner rejects an explicit value before resolving credentials or sending a request. Provider models can impose additional restrictions; newer Anthropic models deprecate explicit sampling controls. Omit temperature for Anthropic and Gemini examples to preserve the service default. Maximum output tokens are a budget, not a guarantee of that output size or a reservation of model context.
Reported token counts use the service tokenizer; see Token accounting for normalized totals and detail fields. Responses have no shared conversation state and do not expose the raw provider JSON.
The explicit chat example retains these controls and usage accessors in a complete program.
Token accounting
Yes: every successful LLMResponse can expose input_tokens() and output_tokens(), including OpenRouter responses. Aner now also exposes total, cache and reasoning details when the service reports them. Read and retain usage for each request rather than inferring it from answer length or the requested output budget.
| Accessor | Meaning |
|---|---|
answer.input_tokens() | Normalized input count, including reported cache read and cache write input. |
answer.output_tokens() | Normalized output count, including reported reasoning/thinking output. |
answer.total_tokens() | The provider reported total when available; otherwise a checked sum of known input and output counts. |
answer.cached_input_tokens() | Cache read input tokens, already included in input_tokens(). |
answer.cache_write_input_tokens() | Cache write input tokens, already included in input_tokens(). |
answer.reasoning_tokens() | Reasoning/thinking tokens, already included in output_tokens(). |
Every count is an Int64. -1 means unavailable; 0 means a reported zero. Missing or null usage is never replaced with a character estimate or zero. Never add cache or reasoning details to the parent counts again. A provider reported total remains authoritative even if it differs from the visible detail fields. Counts can differ between models because services use their own tokenizers and accounting rules.
import aner.llm
import aner.secrets
let model = llm.client(provider: "openrouter", model: "openai/gpt-4.1-mini",
key: secrets.stored("openrouter"))
let answer = model.generate("Explain the purpose of validation data.", max_tokens: 256)
print("Input tokens: " + String(answer.input_tokens()))
print("Output tokens: " + String(answer.output_tokens()))
if answer.total_tokens() >= 0 {
print("Total tokens: " + String(answer.total_tokens()))
} else {
print("Total tokens: unavailable")
}The complete token usage example labels every field and handles unavailable counts. The OpenRouter notebook does the same. For experiment accounting, record the configured provider, requested and returned model identifiers, finish reason and usage alongside your own request identifier. Each response describes that request’s full submitted history and output; it is not a conversation wide accumulator. Preserve unknown values if aggregating usage across requests rather than treating them as zero.
OpenRouter input/output map to reported prompt_tokens/completion_tokens; cached, cache write and reasoning details are already subsets of those counts. Anthropic reports uncached input separately from cache reads/writes. Aner returns normalized input only when uncached input and both cache categories are reported; a missing/null category makes input_tokens() unavailable, while an explicit zero is included. Gemini Interactions reports ordinary output separately from thoughts. Aner returns normalized output only when both ordinary output and thought counts are reported; missing/null thoughts make output_tokens() unavailable. A provider reported total remains available independently of missing input/output details; a derived total requires both normalized counts to be known. These detail accessors report usage; they do not enable prompt caching, reasoning, or additional provider features.
Token usage is not a currency amount or a billing verification. Cached input, cache creation, reasoning, model routing and current provider prices can affect charges. Keep pricing outside the inference adapter and reconcile monetary costs against the provider’s usage/billing records. A timeout or rejected response may occur after provider work has started; no successful response handle is available to account for that work. Aner does not retry automatically or run a second billing lookup.
Cloud credentials
Configure a credential once through hidden terminal input:
aner secrets set openaiThen refer to its label from source:
import aner.llm
import aner.secrets
let model = llm.client(provider: "openai", model: "gpt-4.1-mini",
key: secrets.stored("openai"))
let answer = model.generate("Explain why sample weighted gradients matter.",
max_tokens: 256)
print(answer.text())The default store uses the native operating system credential service on macOS and Windows. On Linux, explicitly choose the managed file fallback or an environment variable injected by your deployment system; see Credentials. Source files and notebooks keep a reference, never the key value. Request execution resolves the reference; a missing credential fails before authenticated transport. OpenAI requests can incur provider charges when the program runs.
The cloud example demonstrates this configuration. The model identifier is explicit because available models and their settings can depend on account access. Aner does not replace an unavailable model with another model.
Anthropic
Anthropic Claude uses a native Messages adapter in Aner’s C++ runtime with verified HTTPS and no external SDK dependency. Configure a private credential through hidden terminal input:
aner secrets set anthropicimport aner.llm
import aner.secrets
let model = llm.client(provider: "anthropic", model: "claude-sonnet-5-5",
key: secrets.stored("anthropic"))
let answer = model.generate("Explain the purpose of validation data.", max_tokens: 1024)
print(answer.text())
print(answer.finish_reason())
print(answer.input_tokens())
print(answer.output_tokens())
print(answer.total_tokens())The default base endpoint is https://api.anthropic.com/v1; Aner sends /messages with version 2023-06-01 and bearer authentication. An explicit model identifier is required; choose one available to your Anthropic account. claude-sonnet-5-5 is illustrative, and model availability can change. Omit temperature to preserve model defaults; the native adapter admits explicit values only through 1.0, and a model may impose stricter rules.
For chat, put all system messages before the first user message; the adapter sends them as the separate top level system instruction. Supply the entire intended user/assistant history explicitly. The text interface does not request tools, cache control blocks or extended thinking. Usage reports cache/thinking details when the service includes them. A token budget finish can return incomplete text; inspect finish_reason().
The complete Anthropic example sends one request when run. Alternatively use secrets.env("ANTHROPIC_API_KEY") or secrets.dotenv(path: ".env.local", name: "ANTHROPIC_API_KEY"). Client construction and aner check neither resolve the credential nor send inference requests.
Google Gemini
Google Gemini uses a native stable v1 Interactions adapter in Aner’s C++ runtime. It is a text only implementation of the shared generate/chat interface. Configure a private credential through hidden terminal input:
aner secrets set geminiimport aner.llm
import aner.secrets
let model = llm.client(provider: "gemini", model: "gemini-3.7-flash",
key: secrets.stored("gemini"))
let answer = model.generate("Explain the purpose of validation data.", max_tokens: 1024)
print(answer.text())
print(answer.finish_reason())
print(answer.input_tokens())
print(answer.output_tokens())
print(answer.total_tokens())The default base endpoint is https://generativelanguage.googleapis.com/v1; Aner sends /interactions with the credential in x-goog-api-key and store: false. Choose a model available to your Google account; gemini-3.7-flash is illustrative. Gemini stable v1 Interactions does not accept an explicit temperature, so omit that argument. An attempt to supply it fails locally before credential resolution or transport.
For chat, leading system messages become the separate system instruction. Aner maps explicit ordered user/assistant messages to the Interactions input format and resubmits that supplied history on each call. It does not use a saved interaction identifier or automatic server conversation state. store: false disables interaction storage for this request; provider policies and account settings still govern retention. The text adapter does not expose multimodal input, tools, reasoning controls or response schemas. Reasoning text is not returned through text(), while reported reasoning token usage is included in output accounting.
The complete Gemini example sends one request when run. Alternatively use secrets.env("GEMINI_API_KEY") or secrets.dotenv(path: ".env.local", name: "GEMINI_API_KEY"). The same explicit file choice supports .env, .env.production, .env.development and .env.local without discovery or precedence rules.
Anthropic, Gemini and expanded usage accessors require a compatible updated native development runtime and matching editor/notebook integration; see installation and availability.
OpenRouter
OpenRouter is implemented in Aner’s native C++ runtime. Aner builds the JSON request and sends it through libcurl with verified HTTPS, using the same llm.client, generate and chat API. Provider requests use the native runtime directly, with no external SDK dependency. OpenRouter and its selected upstream service perform model inference.
OpenRouter and secrets.dotenv require a compatible native development runtime and matching notebook integration; see installation and availability.
Configure an OpenRouter key with hidden terminal input:
aner secrets set openrouterUse the existing client and response API with an explicit model slug:
import aner.llm
import aner.secrets
let model = llm.client(provider: "openrouter", model: "openai/gpt-4.1-mini",
key: secrets.stored("openrouter"))
let answer = model.generate("Explain the purpose of validation data.", max_tokens: 256)
print(answer.text())
print(answer.finish_reason())The default base endpoint is https://openrouter.ai/api/v1; Aner sends synchronous text requests to /chat/completions. Use a model slug with its organization prefix from OpenRouter's current catalog; openai/gpt-4.1-mini is an example, subject to availability and account access. chat, sampling settings and response accessors work as above. Construction and aner check examples/llm_openrouter.aner send no requests and resolve no credentials. Running the example sends a request and can incur charges.
Deployments may explicitly replace the key reference with secrets.env("OPENROUTER_API_KEY"), or choose a private dotenv file with secrets.dotenv(path: ".env.local", name: "OPENROUTER_API_KEY"). Aner does not discover that environment variable or load .env files automatically. Aner performs no automatic retries; OpenRouter controls upstream routing and provider fallbacks. OpenRouter specific routing parameters, app attribution headers, streaming, tools and multimodal inputs are outside this interface.
Switch OpenRouter models in a notebook
Download the Aner notebook or Jupyter notebook. Both contain the same cells, use the Aner kernel in persistent-session/production mode, and have no saved output or credentials. They send two explicit requests using one credential reference, shared message history, a 256 token output budget, and the same temperature: first openai/gpt-4.1-mini, then google/gemma-3-27b-it. The example slugs appear in OpenRouter's OpenAI model page and Google model page; availability and account access can change.
The setup defaults to secrets.stored("openrouter"). To use a private dotenv file, set key_source = "dotenv" and select env_file explicitly: .env, .env.production, .env.development, .env.local, or an absolute path. The notebook passes that path to secrets.dotenv; there is no file search, precedence, merging or process environment mutation. Relative paths are captured against the kernel's working directory when the reference is constructed. Keep the selected file outside version control and use a private regular file with mode 600 on macOS/Linux; see Credentials for the complete file contract.
Change selected_model and rerun either request cell to try another available model without changing the OpenRouter provider or key reference. Each request resolves the credential again and prints the requested and returned model identifiers, finish reason and reported usage. Construction sends no request; generating can incur charges. Choose credentials and models before Run All, and restart the session before rerunning edited setup declarations. Clearing a session does not delete stored credentials.
Switch between providers in a notebook
Download the Aner notebook or Jupyter notebook to switch between native Anthropic, Google Gemini and OpenRouter clients. Both formats contain the same cells, run in persistent-session/production mode, and contain no saved output or credential values. They require a compatible updated native development runtime and matching editor/notebook kernel; see installation and availability. A plain Aner companion performs the same three requests.
The notebook defaults to three separate SecretRef values: secrets.stored("anthropic"), secrets.stored("gemini") and secrets.stored("openrouter"). Set each credential through hidden terminal input, then choose models available to the corresponding accounts. The sample identifiers claude-sonnet-5-5, gemini-3.7-flash and openai/gpt-4.1-mini are illustrative. To use injected variables instead, set key_source = "env". For a private project file, set key_source = "dotenv" and select exactly one env_file: .env, .env.production, .env.development, .env.local, or an absolute path. The three explicit names are ANTHROPIC_API_KEY, GEMINI_API_KEY and OPENROUTER_API_KEY. No source value is a key String, and no provider searches for files or falls back to another credential source. Keep the file private and outside version control; see Credentials for permissions and path behavior.
Three separate request cells change the provider, model and credential reference together while keeping the same message history and 1024 token output budget. They omit temperature to preserve each service's supported defaults. Each cell prints the provider, requested and returned model identifiers, finish reason, input tokens, output tokens and total tokens. The shared reporting helper displays -1 as unavailable and preserves a reported zero. Totals come from total_tokens(); cache and reasoning details are already included in their normalized parent counts and must not be added again. Counts describe each call, not an accumulated conversation, and provider billing records remain authoritative for charges; see Token accounting.
Run All sends three requests and may incur charges. Setup and client construction send none. After setup, each request cell can be rerun independently; every rerun sends another request and resolves its selected credential again. Restart the session before rerunning edited setup declarations. Production mode disables development recording while inference and provider billing continue. Explicitly printed prompts or answers are ordinary notebook data; review and clear output before sharing.
Another local or hosted service
A vLLM service exposes its configured model identifier through its compatible endpoint. Set that exact identifier:
import aner.llm
let model = llm.client(provider: "vllm", model: "research-model",
endpoint: "http://127.0.0.1:8000/v1", timeout_ms: 120000)
let answer = model.generate("Summarize the purpose of validation data.",
max_tokens: 256, temperature: 0.2)
print(answer.text())For an authenticated hosted service, supply an explicit HTTPS base endpoint and credential reference. Plain HTTP is accepted only for loopback addresses. A private network address by itself does not provide encryption. To use a remote loopback service through an SSH tunnel, create the tunnel outside the program and pass its local endpoint; Aner does not open SSH sessions or scan for services.
A hosted provider must implement the selected adapter contract; using a compatible URL does not establish compatibility with every extension or model. See the vLLM example.
Organize a research workflow with a class
Classes can retain a configured client and define the instructions used by an experiment. The same native request API remains explicit:
import aner.llm
class ResearchAssistant {
let model: LLMClient
let instructions: String
fn explain(question: String) {
let messages = List(
llm.message("system", instructions),
llm.message("user", question))
return model.chat(messages, max_tokens: 256, temperature: 0.2)
}
}
let assistant = ResearchAssistant(
model: llm.client("ollama", "llama3.2:3b"),
instructions: "Explain assumptions, limitations, and the reasoning clearly.")
let answer = assistant.explain("Why must preprocessing fit training data only?")
print(answer.text())A class adds application organization without changing provider semantics, transport requirements, or message order. It can return LLMResponse so the caller decides whether to retain generated text or usage metadata. See the class example.
API reference
| Call | Result | Contract |
|---|---|---|
llm.client(provider: String, model: String) | LLMClient | Provider default endpoint and 120000 ms timeout; credential free construction is admitted for Ollama/vLLM. OpenAI, OpenRouter, Anthropic and Gemini require a key overload. |
llm.client(provider: String, model: String, endpoint: String) | LLMClient | Explicit base endpoint without a credential reference; Ollama/vLLM only. |
llm.client(provider: String, model: String, key: SecretRef) | LLMClient | Default endpoint with an explicit credential reference. |
llm.client(provider: String, model: String, endpoint: String, key: SecretRef) | LLMClient | Explicit endpoint and credential reference. |
llm.client(provider: String, model: String, timeout_ms: Int64) | LLMClient | Default endpoint and explicit timeout without a credential reference; Ollama/vLLM only. |
llm.client(provider: String, model: String, key: SecretRef, timeout_ms: Int64) | LLMClient | Default endpoint, explicit credential reference and timeout. |
llm.client(provider: String, model: String, endpoint: String, timeout_ms: Int64) | LLMClient | Explicit endpoint and timeout without a credential reference; Ollama/vLLM only. |
llm.client(provider: String, model: String, endpoint: String, key: SecretRef, timeout_ms: Int64) | LLMClient | Explicit endpoint, credential reference, and timeout. |
llm.message(role: String, content: String) | LLMMessage | Construct a typed ordered message without a request. |
model.generate(prompt: String) | LLMResponse | One user message, default output budget, provider temperature default. |
model.generate(prompt: String, max_tokens: Int64) | LLMResponse | One user message and explicit output budget. |
model.generate(prompt: String, max_tokens: Int64, temperature: Float64) | LLMResponse | One user message with explicit budget and temperature. |
model.chat(messages: List) | LLMResponse | Ordered typed messages and default generation settings. |
model.chat(messages: List, max_tokens: Int64) | LLMResponse | Ordered typed messages and explicit output budget. |
model.chat(messages: List, max_tokens: Int64, temperature: Float64) | LLMResponse | Ordered typed messages, explicit budget and temperature. |
model.provider() -> String | String | Read the exact configured provider without a request; module form llm.provider(client: LLMClient). |
model.model() -> String | String | Read the requested model identifier without a request; module form llm.model(value: LLMClient). |
answer.text() -> String | String | Read returned text explicitly; module form llm.text(response: LLMResponse). This extracted String has ordinary printing/capture visibility. |
answer.model() -> String | String | Read the provider reported model identifier; module form llm.model(value: LLMResponse). |
answer.finish_reason() -> String | String | Read why generation ended; module form llm.finish_reason(response: LLMResponse). A token limit can produce incomplete output. |
answer.input_tokens() -> Int64 | Int64 | Normalized input usage including reported cache read/write, or -1 when unavailable; module form llm.input_tokens(response: LLMResponse). |
answer.output_tokens() -> Int64 | Int64 | Normalized output usage including reported reasoning, or -1 when unavailable; module form llm.output_tokens(response: LLMResponse). |
answer.total_tokens() -> Int64 | Int64 | Provider total or checked input/output sum; -1 when unavailable; module form llm.total_tokens(response: LLMResponse). |
answer.cached_input_tokens() -> Int64 | Int64 | Cache read subset of input, or -1 when unavailable; module form llm.cached_input_tokens(response: LLMResponse). |
answer.cache_write_input_tokens() -> Int64 | Int64 | Cache write subset of input, or -1 when unavailable; module form llm.cache_write_input_tokens(response: LLMResponse). |
answer.reasoning_tokens() -> Int64 | Int64 | Reasoning subset of output, or -1 when unavailable; module form llm.reasoning_tokens(response: LLMResponse). |
Instance methods also have module forms, such as llm.generate(model, prompt) and llm.text(answer). Named arguments must use the labels in the signature. Credential references are documented independently in Credentials.
Parameter validation
| Parameter | Native accepted values |
|---|---|
provider | Exactly "ollama", "openai", "openrouter", "anthropic", "gemini" or "vllm"; adapters do not auto detect another service. All four cloud adapters require an explicit SecretRef. |
model | Nonempty valid UTF8 identifier of at most 256 bytes without control characters. Existence/account access is checked by the selected service when a request runs. |
endpoint | HTTP(S) base URL, at most 2048 bytes, without credentials, query or fragment. Plain HTTP requires exact loopback 127.0.0.1, [::1] or localhost; the localhost spelling is fixed to loopback. |
timeout_ms | Integer from 1 through 600000; default 120000. Bounds one synchronous request attempt. |
role, content | Role is system, user or assistant. Content must be valid UTF8; total message content and serialized request remain within the 1 MiB bounds. The service can impose stricter prompt/context requirements. |
messages | Ordered nonempty List of at most 256 LLMMessage values; no implicit conversation history. Anthropic/Gemini admit system messages only at the start, followed by a user message. |
max_tokens, temperature | Output budget from 1 through 1000000, default 512. Explicit temperature is finite and from 0.0 through 2.0, through 1.0 for Anthropic, and unsupported for Gemini stable v1. Provider/model restrictions still apply. |
Transport and error contract
The request body is bounded to 1 MiB and the response body to 8 MiB. The total timeout is from 1 through 600000 ms, including connection establishment, local model startup, and waiting for the response. TLS certificate and hostname verification remain enabled. Credentials cannot be embedded in endpoint URLs. The runtime does not follow redirects, use ambient HTTP proxy variables, or retry requests automatically; each inference call has one request attempt.
Invalid client configuration, incompatible messages, missing models, transport failures, invalid provider responses, and unsupported result content use source located R3101 diagnostics. Credential resolution uses R3102. Native diagnostic messages omit authorization headers, credential values, prompts, generated text, and raw provider error bodies. Ordinary source excerpts may still show text authored in the program; explicit String output and captures retain their normal visibility. Failed or unsupported responses do not masquerade as successful generated text. A timeout may occur after the provider has begun processing; retrying explicitly can create additional provider work.
The adapter requests plain text. Refusal, tool calls, and unsupported response content produce a sanitized error rather than executing anything. OpenRouter accepts stop and length completion reasons; length may return incomplete text. OpenRouter errors, including error objects inside HTTP 200 responses, content_filter, and tool results fail with sanitized diagnostics rather than exposing partial output. OpenAI incomplete responses expose the reported finish reason and any returned text; inspect the reason before treating output as complete. HTTP loopback exceptions support local inference and locally established tunnels; remote services require authenticated, verified HTTPS where applicable.
Development, production, and notebooks
LLMClient, LLMMessage, LLMResponse, and SecretRef are opaque values. Ordinary handle printing and development inspection do not reveal message text, generated content, endpoint credentials, or secret material. This protects handles; it does not make every String confidential. Prompt Strings already bound in source, answer.text(), and text explicitly printed or captured are ordinary program data and may appear in output or development reports. Keep sensitive content out of captures and saved notebook output.
Development and production execute the same requests. Production disables development recording; it does not change provider, model, token budget, temperature, precision, or provider billing. A notebook cell performs the request synchronously and displays its output after completion. Persistent sessions can retain the configured client, but a rerun sends another request. Notebook reset clears session values and does not delete credentials from their store.
Download the Aner notebook or the Jupyter notebook. Both start with local inference and contain no stored credentials or execution output. Configure your local service before executing request cells.
For cloud model switching with one credential, use the dedicated OpenRouter Aner notebook or OpenRouter Jupyter notebook. They include explicit stored/dotenv source selection and two bounded requests to models from different providers.
VS Code provides provider neutral signatures, parameter documentation, response methods, and credential references. Snippets include llmlocal, llmchat, llmcloud, llmopenrouter, llmanthropic, llmgemini, llmvllm, llmclass, secretref, and secretdotenv. Use an interpreter and extension that both support the selected provider; updating the extension alone does not update the engine.
Time and space complexity
Let c be client configuration bytes, m message count, q serialized request bytes, r response bytes, and t generated text bytes. These quantities describe Aner client work. They do not describe inference performed by the selected service.
| Operation | Aner client time | Aner client space |
|---|---|---|
| Client construction | O(c) | O(c) retained configuration |
| Message construction | O(t) | O(t) retained message content |
| Request assembly and response parsing | O(m + q + r) | O(q + r), plus supplied messages and retained response |
| Read token counts | O(1) | O(1) auxiliary |
| Read generated text | O(t) | O(t) returned String |
Elapsed generation time includes connection establishment, network latency, service queueing, model loading, prompt processing, and output generation. Model architecture, tokenizer, context length, hardware, and provider scheduling determine that work. Aner does not assign a universal Big O bound or completion estimate to remote inference. The output budget and timeout bound the admitted client request; they are not throughput guarantees. Provider model memory and KV cache are outside Aner client memory accounting.
Sources and related references
The native provider contracts follow the Ollama chat API, OpenAI Responses API, OpenRouter quickstart, OpenRouter API reference and error contract, Anthropic Messages API, Gemini stable v1 Interactions API, and vLLM compatible server interface. Service versions may expose additional operations that are outside this Aner module.
See Credentials, Development and production, and Interactive Aner notebooks for credential lifecycle and observation boundaries.
Native local model connection
The matching optional native inference development runtime also supports llm.load for local GGUF models, typed generation, explicit model lifetime and exact base deployment adapters. See native local inference and the local model example. This capability does not change existing Ollama or cloud requests or the separately published package inventory. Training, optimizer checkpoints and artifact export belong to the pretrained training workflow in aner.gen.
See the complete callable index for the native module and method name catalogue.
Continue with CPU and GPU model memory placement for this specialist contract.
Continue with Direct weight space programming for this specialist contract.
Continue with Native local inference optimizer for this specialist contract.
Continue with Remote language model devices for this specialist contract.