Connect through native OpenRouter
Use the native OpenRouter adapter with an opaque credential and switch provider model slugs in the accompanying notebooks.
// Configure once in Terminal: aner secrets set openrouter
// Choose an available OpenRouter model slug; account access may vary.
// Checking sends no requests. Running sends one request and can incur charges.
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.model())
print(answer.finish_reason())
print(answer.input_tokens())
print(answer.output_tokens())
print(answer.total_tokens())
// Token counts are provider-reported; -1 means unavailable and zero is meaningful.
// Use llm_token_usage.aner for cache/reasoning details and labeled missing-usage handling.
Run step by step in VS Code.
The OpenRouter notebook separates credential setup, shared request settings, and two model requests into cells. It opens in Production mode with empty outputs and Shared variables enabled.
- Install a compatible updated native Aner executable and matching notebook integration using the editor guide.
- Configure
aner secrets set openrouterthrough hidden terminal input. The credential guide explains stored references and the explicitsecrets.dotenvalternative for one selected private environment file. Keep key values outside notebook cells and source. - Download the
.anernbnotebook and open it in your VS Code project. If it appears as JSON, choose Reopen Editor With… → Aner Notebook. Select theAner — notebookkernel and keep Shared variables active. - Review the shared credential reference, two provider model identifiers, prompt, ordered history, output budget and sampling settings. Client construction sends no request. Run cells in order when ready; the two explicit request cells each send one provider request and may incur provider charges. Read generated text, the returned model, finish reason and labeled input, output, total, cache and reasoning usage below each completed cell. Unavailable counts remain explicit; cache and reasoning details are already included in their parent counts.
After editing declarations or earlier settings, use Aner: Restart Notebook Session, then rerun the cells in order. Each repeated request creates another provider call. Saved outputs are historical; reopening the file starts without live variables. The notebook guide explains session state and runtime controls.
Run step by step in Jupyter.
Download the .ipynb notebook and open it in a notebook application with the Aner kernel configured. Select Aner and run its cells from top to bottom. The Jupyter guide explains kernel requirements, shared session state and output policies.
The OpenRouter notebook starts in Production mode with empty outputs. Configure its shared credential reference and model identifiers before running the two explicit request cells. Each request and rerun may incur provider charges. Restart the kernel after editing declarations, then run the cells in order.
Make it your experiment.
With a compatible development runtime installed, save this program as examples/llm_openrouter.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/llm_openrouter.aner
aner run examples/llm_openrouter.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use the current native Aner development runtime with the OpenRouter adapter and secrets.dotenv support. Notebook execution also requires a matching Aner VS Code extension or Jupyter kernel integration. Checking sends no inference request and resolves no credential. Running the source sends one request; Run All in either notebook sends two requests and can incur provider charges. Configure an available OpenRouter model slug and a private opaque credential reference before running.
aner secrets set openrouter
aner secrets status openrouterThe source program sends one generation request. The notebooks compare two model identifiers with two explicit requests using the same credential, prompt, history, and generation settings. Client construction and syntax checking send no request. Running a request cell again sends another request and may incur provider charges.
Read the native OpenRouter contract