Compare commits

..
Author SHA1 Message Date
william f4f785e0bb Re-add the claude-subscription LiteLLM route — confirmed working for the real CLI
Earlier this session I removed this route after a curl-based test got
rejected by Anthropic and concluded OAuth subscription forwarding doesn't
work through a proxy at all. That conclusion was wrong: the real `claude`
CLI binary, with ANTHROPIC_BASE_URL pointed at litellm, successfully
completed a request billed against the subscription. The earlier curl test
just didn't replicate whatever header/fingerprint Anthropic requires from
genuine Claude Code CLI traffic — LiteLLM relays that fine when the real
CLI is the caller, but a hand-built request from any other client (Hermes
included) still gets rejected the same way curl did.
2026-08-23 16:08:26 +00:00
4 changed files with 17 additions and 34 deletions
-4
View File
@@ -30,10 +30,6 @@ MATRIX_CONTROL_ROOM_ID=
# Required: without it the bot can't tell its own messages apart from real ones and would
# reply to itself in a loop, so it refuses to start.
MATRIX_BOT_USER_ID=
# Comma-separated Matrix IDs of OTHER agents sharing the control room (currently just
# @hermes:...) — without this, claude-bot treats every message another bot posts as
# fresh chat input and replies to it, which that bot may then react to in turn.
OTHER_AGENT_USER_IDS=@hermes:matrix.apps.williamturner.eu
# Comma-separated "owner/repo" list the chat router is allowed to open code-change PRs
# against. A plain chat message mentioning a repo NOT in this list is treated as chat,
# never as a code task — the router only matches confidently against known repos.
-11
View File
@@ -11,15 +11,6 @@ const GITEA_URL = process.env.GITEA_URL;
// to the endpoint itself. This is also the only reliable way to filter the bot's own
// messages now that there's no command prefix to naturally exclude them by.
const BOT_USER_ID = process.env.MATRIX_BOT_USER_ID;
// Other agents sharing this room (currently just Hermes) — their own messages must be
// ignored the same way claude-bot ignores its own, or claude-bot's classifier treats
// every message another bot posts as fresh chat input and replies to it, which that
// bot may then react to in turn. Found the hard way: a single @hermes mention cascaded
// into claude-bot replying to Hermes's own thread messages ("Hermes says: ...").
const OTHER_AGENT_USER_IDS = (process.env.OTHER_AGENT_USER_IDS || "")
.split(",")
.map((id) => id.trim())
.filter(Boolean);
const KNOWN_REPOS = (process.env.KNOWN_REPOS || "")
.split(",")
.map((r) => r.trim())
@@ -56,7 +47,6 @@ export async function startMatrixBot() {
client.on("room.message", async (roomId, event) => {
if (roomId !== CONTROL_ROOM_ID) return;
if (event.sender === BOT_USER_ID) return;
if (OTHER_AGENT_USER_IDS.includes(event.sender)) return;
const body = event.content?.body;
if (!body) return;
// Messages explicitly addressed to another agent in this room (currently just
@@ -77,7 +67,6 @@ export async function startMatrixBot() {
}
const reply = await chatReply(body);
console.log("chat reply sent, length:", reply.length);
await client.sendText(roomId, truncate(reply));
} catch (err) {
console.error("message handling failed", err);
+4 -12
View File
@@ -77,15 +77,7 @@ services:
# rooms (DMs to it would respond unprompted, per Hermes's own default behavior).
MATRIX_ALLOWED_USERS: ${MATRIX_HUMAN_USER_ID}
MATRIX_REQUIRE_MENTION: "true"
# Routed through the local litellm gateway, not OpenRouter directly — same pattern
# as claude-agent's chat path, one place to hold the OpenRouter credential and swap
# models. Hermes's "main"/custom-endpoint provider is any OpenAI-compatible API
# reachable via OPENAI_BASE_URL + OPENAI_API_KEY. Note: this does NOT give Hermes
# access to the Claude Pro/Max subscription — that's blocked by Anthropic itself for
# any caller other than the real Claude Code CLI, proven earlier in this session
# (reproduced with plain curl straight to api.anthropic.com, LiteLLM or not).
OPENAI_BASE_URL: http://litellm:4000/v1
OPENAI_API_KEY: ${LITELLM_MASTER_KEY}
OPENROUTER_API_KEY: ${OPENROUTER_API_KEY}
# Left disabled: Hermes itself warns that a network-reachable API server combined
# with the default unsandboxed ('local') terminal backend gives any caller full
# terminal/file access within the container. Matrix is the actual interface in use;
@@ -121,10 +113,10 @@ services:
MATRIX_BOT_TOKEN: ${MATRIX_BOT_TOKEN}
MATRIX_CONTROL_ROOM_ID: ${MATRIX_CONTROL_ROOM_ID}
MATRIX_BOT_USER_ID: ${MATRIX_BOT_USER_ID}
OTHER_AGENT_USER_IDS: ${OTHER_AGENT_USER_IDS}
KNOWN_REPOS: ${KNOWN_REPOS}
# Chat replies go through the local litellm service (OpenRouter's models, incl. its
# auto-router), not OpenRouter directly.
# All model calls now go through the local litellm service, not OpenRouter directly —
# one gateway for OpenRouter's models (incl. its auto-router) and, for the
# claude-subscription route, Anthropic itself via the forwarded OAuth token above.
LITELLM_BASE_URL: http://litellm:4000
LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
volumes:
+13 -7
View File
@@ -11,13 +11,19 @@ model_list:
model: openrouter/openai/gpt-4o-mini
api_key: os.environ/OPENROUTER_API_KEY
# NOT included: a "claude-subscription" route forwarding the Claude Pro/Max OAuth token
# (from `claude setup-token`) through to Anthropic's raw API. Tested and confirmed
# non-functional — Anthropic returns a generic rate_limit_error for ANY direct API call
# using this token type outside the real Claude Code CLI client (reproduced with plain
# curl straight to api.anthropic.com, bypassing LiteLLM entirely, same result). The
# subscription token only works through the actual Claude Code CLI, which is what
# claude-agent already uses directly for code tasks — it was never routed through here.
# Routes to Anthropic using the CALLER's forwarded Authorization header (the Claude
# Pro/Max subscription OAuth token) instead of a LiteLLM-held API key — billed against
# the subscription, not per-token. CONFIRMED WORKING, but only for the real `claude`
# CLI binary as caller (tested: `claude -p` with ANTHROPIC_BASE_URL pointed here
# returned a real completion). An earlier test with plain curl replicating the same
# request shape failed — Anthropic apparently requires header/fingerprint details only
# the real CLI sends, which LiteLLM faithfully relays but a hand-built request won't
# have. Do NOT expect this to work for other callers (Hermes, generic HTTP clients) —
# they aren't the real CLI and can't reproduce that fingerprint.
- model_name: anthropic-claude
litellm_params:
model: anthropic/claude-sonnet-5
general_settings:
forward_client_headers_to_llm_api: true
master_key: os.environ/LITELLM_MASTER_KEY