Runtimes from Telegram
Runtimes, their logins and a read-only routing view from the Telegram owner command /runtimes; routing changes by free text.
Paths in crates/axe-core/src/, crates/axe-telegram/src/, crates/axe-node/src/, crates/axe-server/src/ or crates/axe/src/ (a file is in one) unless noted.
Runtimes: /runtimes. A runtime is one tool (harness) set up on the
node with its own logins: one for Claude and Codex, one per provider for a
tool that takes the provider table. Telegram calls it by its display name (claude-1 is Claude 1,
routing::display). On a node with [runtimes] dir, /runtimes lists every
logged-in runtime on one line: its state (working, needs login, nearly out,
out until a time, out of credit, failing), its one meter and its live runs,
with an ! line on top for the first runtime that needs you
(runtime_views::runtimes_text). The meter comes from the login
(Runtime::meter, harness::Meter): a subscription login (Claude web
sign-in or setup token) shows its share of the week (20% of week); an API
key or a provider key is billed per use and shows the last 7 days' spend
from axe's own cost records ($1.84 this week, usage::runtime_spend);
Codex shows none. One button per runtime (marked
! when it needs you), Add runtime and Routing →; with no runtime yet,
"No runtime yet. Set up Claude, Codex, OpenCode or Pi to start your bots." and
one button per tool, three a row (Log in Claude, Log in Codex, Set up OpenCode, Set up Pi), both from the harness rows
(runtime_views::tools, telegram::runtimes_screen). Every button edits
the same message in place (Gateway::runtimes_press); runtime screens
never change what a bot or task runs on.
- A runtime shows its state, its week or spend and live runs (and, on
a runtime that holds several provider keys, one line per provider), with
Log in when it needs one, Check when it is out of credit, Remove…
and Back (
telegram::runtime_screen). - Add runtime asks "Which one?" (the tool), then the login method
(
telegram::add_screen,telegram::login_screen). Add (login first) writes<dir>/<name>/runtime.tomlunder the next free name (claude-2) with its ownlogin_dir(<dir>/<name>/home, linking the owner's instructions, settings and skills from the CLI's default directory, never its credentials). It is not listed and takes no runs until its login check passes (Runtime::pending; a second Add of that harness reuses it); then it shares the harness's work with the others. A chat bot with no runtime gets it as its primary; if axe had paused it because its runs failed for want of a runtime, it resumes and its queued messages run once the login passes (bot::edit). An Add that does not end in a login leaves nothing behind: Cancel drops it at once, and it is removed when its first login fails its check, or when none passed withinruntime::ADD_LOGIN_WAIT(added_atin itsstate.json), with a card saying so. - Remove… asks to confirm, saying how many runs are going and how many
bots use the runtime as their primary (
runtime_views::remove_text). The node refuses while the runtime has live runs and deletes<dir>/<name>(its stored credentials, and its login directory when that is inside); a login directory elsewhere, such as the CLI's default, is left in place. A session that ran on it starts fresh elsewhere (Registry::remove).
The node applies Add and Remove between picks, and they persist: the registry directory is the state, so hand-written runtimes keep working beside them.
Routing, view only. Routing → shows, in one read-only message, what
each bot runs on (primary → backup, the model and effort of its bot= rule,
and live: on its backup or waiting), what tasks run on per project (the
default rule and each label= rule, as their ordered use lists; other
rules are counted), and what would wait if a working runtime ran out
(routing::Routing, runtime_views::routing_text). Its only button is ←
Runtimes. To change routing, tell the bot in free text ("give tn-cos Codex
1 as backup"): it runs axe bot set or axe rule add / axe rule rm and
replies with the result (the bot protocol's "Routing (free text)",
crates/axe-core/src/bot_protocol.md). Older /runtimes messages' Primary
and Backup buttons only answer that they are retired.
Cards. The ops bot ([telegram] ops_bot, default the first bot) sends
you one card when a runtime needs a login or is out of quota (the result
of a login you started goes to that chat instead; see below), saying what
moved and what waits meanwhile, with Log in, Routing → (when something
waits) and Runtimes (Gateway::runtime_alert, runtime_views::alert_text).
A weekly quota at or above 80% (routing::NEARLY_OUT) sends one nearly out
card per runtime per quota window: the node raises it once per window
(runtime::nearly_out_window, Registry::set_quota) and the server skips it
while that window's card is open. When the runtime works again its card is
edited to "Claude 1 works again." and loses its buttons; a nearly-out card
is edited the same way when its window resets, and a removed runtime's
card says it was removed (telegram::runtime_cards,
telegram::close_runtime_card). Nearly out is the week's only: a runtime
billed per use gets none.
Out of credit. A provider that refuses for lack of prepaid credit (HTTP
402) puts the runtime out of credit: limited with no end time, so its work
moves or waits as for any runtime that is out, and it never lapses on its
own (Registry::mark_run). One card goes out on the first 402: "Claude 2 is
out of credit. Top up, then tap Check." with Check and Runtimes. Check
runs the runtime's login check now (Axe::runtime_check, the node's
Registry::check_now); a passing check ends it and edits the card to
"Claude 2 works again.", a failing one replies that it is still out. On a
runtime that holds several provider keys only that provider's login is out
("OpenCode 1: DeepSeek is out of credit."), and the runtime keeps working
on the others.
Logins from Telegram. Log in offers the runtime's login methods
(runtime::login_methods); re-login of a working runtime stays in the CLI
(axe runtimes login):
- Claude Code. Sign in on web: the node runs
claude auth loginwith its stdin kept open, relays the claude.ai link, and the code the page shows comes back in a sealed form and goes to that stdin (Runtime::device_login,sealed::Desk::relay_code); a passing login removes a stored token or API key, which would hide it. A login still running two minutes after its code (the CLI asks again for a code it cannot use, such as one missing its#...part) is stopped and fails, with a card, and a new sign-in can start (runtime::DEVICE_CODE_WAIT); one that never gets a code is stopped after an hour (runtime::DEVICE_LOGIN_MAX). While a sign-in waits, another of the same runtime is refused. Or Paste token (aclaude setup-tokentoken) or Paste API key arrives in a sealed form (see Sealed forms and messages). It is kept as<name>/login/CLAUDE_CODE_OAUTH_TOKENorANTHROPIC_API_KEY(0600) and set in the runtime's environment, where it takes precedence over the login directory. Or Other provider… (shown while a provider-table row has an Anthropic-Messages endpoint,runtime_views::other_provider): one button per such row (DeepSeek, OpenRouter) and Other… (any Anthropic-compatible base URL), then OpenCode's key screen and sealed form for that provider's key (telegram::provider_screen,telegram::key_screen); Back returns to the login methods. The key replaces the runtime's login like any other, Claude Code reaches the provider with it as a bearer token (see Runtimes, Providers), and the card says "Claude 2 is ready with DeepSeek (deepseek-flash)." (see Models, below). A rule names the provider to use it (claude-code:deepseek/deepseek-flash); bare Claude rules keep to Anthropic logins. - Codex. Paste API key: the key arrives in a sealed form and goes to
codex login --with-api-keyon stdin. Or Device code:codex login --device-authruns on the node, and its link and code are relayed to the owner. - OpenCode (a runtime that holds one key per provider). Set up
OpenCode (or OpenCode under Add runtime) adds
OpenCode 1and asks which provider first, one button per provider-table row it takes, three a row (DeepSeek, OpenRouter, OpenAI, Anthropic, Google Gemini), then Other… on its own row (telegram::provider_screen); no provider comes first. The provider's screen says where to get a key, and Paste API key sends a sealed form with one field, that provider's key (runtime_loginwith--provider). Other… takes any OpenAI-compatible server: Paste URL + key sends one sealed form with its base URL (https://, orhttp://tolocalhoston the node;provider::check_base_url) and its key. The node stores it, rewrites the runtime'sopencode.jsonand checks the key at once with the provider's free key check. The card says "OpenCode 1 is ready with DeepSeek (deepseek-flash)." or "OpenCode 1: the DeepSeek key didn't work. The check said: … Nothing was added.": a key that fails its first check is dropped (Registry::check_login), and a runtime with no other key is removed, as for any Add. A working OpenCode runtime's screen has Add provider while a provider it does not hold is left: the same provider and key screens, and a failed key's card offers Try again for that provider. Cancel drops a runtime that never logged in. - Pi works the same way as OpenCode (Set up Pi,
Pi 1, the same provider and key screens); the node rewrites the runtime's Pisettings.jsoninstead.
Models. A runtime stores no model of its own: routing rules choose
models. A provider login runs its row's default model (provider.rs
default_model) when a rule names none, and the ready card says which,
then "For another model, tell me which (e.g. "run research tasks on
OpenCode 1 with model X")." The owner asks the bot, which adds a rule
(axe rule add --use opencode:openrouter/openai/gpt-6.2-sol). Other… has
no default model, so its card says "It has no default model: tell me which
model to run on it". Ready cards have no model buttons; a model button on
a card from an older version only answers that it is retired.
A login made this way is checked at once (runtime::Registry::check_now)
and the outcome comes as a card: ready for all bots and tasks (and whether
anything uses the runtime yet), or what the check said
(runtime_views::alert_text). That card, and the one saying an added
runtime got no login in time, comes in the chat you started the login from,
from that bot, not from the ops bot (Gateway::login_started, kept in
memory: after a server restart it falls back to the ops bot). A
runtime that needs a login is also rechecked every few minutes
(runtime::PROBE_EVERY).