Skip to content

feat: local billing mode for models served on your machine - #2

Merged
agent-kit-startup merged 4 commits into
mainfrom
feat/local-model
Nov 30, 2026
Merged

agent-kit-startup merged 4 commits into
mainfrom
feat/local-model

Conversation

@agent-kit-startup

Copy link
Copy Markdown
Contributor

Closes #1

What changes

  • Gateway variables reach the fire. config.env is sourced, not exported, so ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN written there never reached agent-kit countdown. The loader now exports the endpoint and model-name variables the claude CLI reads (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_DEFAULT_{HAIKU,SONNET,OPUS}_MODEL, CLAUDE_CODE_SUBAGENT_MODEL). This applies to every billing mode.
  • NS_BILLING=local. Fails closed: refuses to start without ANTHROPIC_BASE_URL, or with a non-loopback endpoint unless NS_LOCAL_REMOTE_OK=1. Fires run without ANTHROPIC_API_KEY and without a per-tick cap; no --budget-remaining is passed and the three budgets are ignored.
  • Made-up cost is not counted. For a model it does not know, claude reports a price with costBasis: "unknown", and the kit writes it to the cost ledger. Local fires are recorded in local-fires.tsv and every spend sum (loop, --check, morning report) skips their ledger lines, so switching back to api-key later in the month is not charged for money never spent.
  • Docs. README "Local model" section (status, configuration, limits), docs/config.md "Endpoint" table, config.env.example, plan-template.md.

Answers to the issue's questions

  1. Environment: gateway variables did not reach the fire from config.env (fixed); subscription only strips ANTHROPIC_API_KEY. A dedicated local billing mode was needed because budgets cannot apply.
  2. Cost ledger: notional figure, not zero (0.0608 USD for an empty 8B tick, 5.10 USD for a real 27B tick). Local mode counts it as 0; the kit-side fix is tracked separately.
  3. Tick contract: llama3.1:8b (32k context, Ollama) answered in one turn with no tool call and changed nothing. Qwen3.8 27B (Q4, integrated GPU) completed a trivial to-do end to end: 27 turns, 26 tool calls, 58 minutes, commit merged to the pre-production branch, plan exhausted.
  4. Model per task: NS_MODEL_* and model= take the server's model names; the ANTHROPIC_DEFAULT_*_MODEL variables cover claude's own aliases.

Verification

  • bash tests/run.sh: all suites pass, including the new tests/test_local.sh (36 checks: export from config, fail-closed guards, loopback look-alikes, no key / no budget flag / no tick cap in local fires, ledger exclusion across a billing switch, morning report).
  • bash scripts/hygiene-scan.sh: clean.
  • Two real fires against local servers in a throwaway repo, started with env -i so the gateway variables came only from config.env; on the real ledger, --check under api-key showed the local fires excluded.

Not covered

No full night yet, only supervised single fires. A fire the kit reports as ok is not proof of work on a weak model (documented in the README).

config.env is sourced but not exported, so ANTHROPIC_BASE_URL and
ANTHROPIC_AUTH_TOKEN written there never reached a fire. The loader now
exports the endpoint and model-name variables the claude CLI reads.

NS_BILLING=local runs a night against a model served on this machine:
- refuses to start without ANTHROPIC_BASE_URL on a loopback host
  (NS_LOCAL_REMOTE_OK=1 vouches for a non-billing remote server)
- strips ANTHROPIC_API_KEY and AGENT_KIT_CLAUDE_MAX_BUDGET_USD
- passes no --budget-remaining and ignores the three budgets
- records its fires in local-fires.tsv so every spend sum skips the
  price claude makes up for an unknown model

README documents the mode as experimental, with the limits found so far.

Refs #1
@agent-kit-startup
agent-kit-startup merged commit c93b3e0 into main Nov 30, 2026
2 checks passed
@agent-kit-startup
agent-kit-startup deleted the feat/local-model branch November 30, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run a night on a local model (Anthropic-compatible endpoint): test and document

1 participant