@cortexkit/pi-anthropic-auth 1.2.5 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,7 +40,7 @@ Pi state is stored separately from OpenCode at:
40
40
 
41
41
  Override the path with `PI_ANTHROPIC_AUTH_FILE`. The package also respects `PI_AGENT_DIR` when deriving the default sidecar path.
42
42
 
43
- The sidecar uses the same JSON shape as the OpenCode package, including `claudeCache`, `cacheKeep`, `claudeFast`, `dump`, `relay`, and fallback `accounts` blocks.
43
+ The sidecar uses the same JSON shape as the OpenCode package, including `routing`, `claudeCache`, `cacheKeep`, `claudeFast`, `dump`, `relay`, and fallback `accounts` blocks.
44
44
 
45
45
  ## Commands
46
46
 
@@ -64,10 +64,14 @@ The sidecar uses the same JSON shape as the OpenCode package, including `claudeC
64
64
  /claude-fast on
65
65
  /claude-fast off
66
66
 
67
+ /claude-routing
68
+ /claude-routing main-first
69
+ /claude-routing fallback-first
70
+
67
71
  /claude-quota
68
72
  ```
69
73
 
70
- `/claude-quota` reports sidecar fallback account quota state from `~/.pi/agent/anthropic-auth.json`. `/claude-cachekeep HH-HH` keeps recently used hybrid-mode session caches warm during the configured local time window by sending `max_tokens: 0` pre-warm requests about five minutes before the 1-hour TTL expires. `/claude-fast on` adds Anthropic `speed: "fast"` plus the `fast-mode-2026-02-01` beta header for supported Opus models (`claude-opus-4-6` and `claude-opus-4-7`).
74
+ `/claude-quota` reports sidecar fallback account quota state from `~/.pi/agent/anthropic-auth.json`. `/claude-routing fallback-first` prefers usable fallback accounts before the main account; `/claude-routing main-first` restores the default. `/claude-cachekeep HH-HH` keeps recently used hybrid-mode session caches warm during the configured local time window by sending `max_tokens: 0` pre-warm requests about five minutes before the 1-hour TTL expires. `/claude-fast on` adds Anthropic `speed: "fast"` plus the `fast-mode-2026-02-01` beta header for supported Opus models (`claude-opus-4-6`, `claude-opus-4-7`, and `claude-opus-4-8`).
71
75
 
72
76
  ## Relay
73
77
 
package/dist/commands.js CHANGED
@@ -1,4 +1,4 @@
1
- import { buildClaudeQuotaSummary, buildFallbackQuotaSummaries, CLAUDE_CACHE_KEEP_COMMAND_NAME, executeCache1hCommand, executeCacheKeepCommand, executeDumpCommand, executeFastModeCommand, getCache1hPersistentMode, getCacheKeepWindow, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isCacheKeepPersistentlyEnabled, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, loadAccounts, parseCache1hCommandAction, parseCacheKeepCommandAction, parseDumpCommandAction, parseFastModeCommandAction, setCache1hPersistentEnabled, setCache1hPersistentMode, setCacheKeepPersistentEnabled, setCacheKeepPersistentWindow, setDumpPersistentEnabled, setFastModePersistentEnabled, } from '@cortexkit/anthropic-auth-core';
1
+ import { buildClaudeQuotaSummary, buildFallbackQuotaSummaries, CLAUDE_CACHE_KEEP_COMMAND_NAME, CLAUDE_ROUTING_COMMAND_NAME, executeCache1hCommand, executeCacheKeepCommand, executeDumpCommand, executeFastModeCommand, executeRoutingCommand, getCache1hPersistentMode, getCacheKeepWindow, getRoutingMode, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isCacheKeepPersistentlyEnabled, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, loadAccounts, parseCache1hCommandAction, parseCacheKeepCommandAction, parseDumpCommandAction, parseFastModeCommandAction, parseRoutingCommandAction, setCache1hPersistentEnabled, setCache1hPersistentMode, setCacheKeepPersistentEnabled, setCacheKeepPersistentWindow, setDumpPersistentEnabled, setFastModePersistentEnabled, setRoutingMode, } from '@cortexkit/anthropic-auth-core';
2
2
  import { getPiAccountStoragePath } from "./paths.js";
3
3
  function notify(ctx, message, kind = 'info') {
4
4
  ctx.ui.notify(message, kind);
@@ -99,6 +99,21 @@ export function registerCommands(pi) {
99
99
  }), action.type === 'usage' ? 'warning' : 'info');
100
100
  },
101
101
  });
102
+ pi.registerCommand(CLAUDE_ROUTING_COMMAND_NAME, {
103
+ description: 'Show or change Claude account routing mode',
104
+ handler: async (args, ctx) => {
105
+ const path = getPiAccountStoragePath();
106
+ let storage = await loadAccounts(path);
107
+ const action = parseRoutingCommandAction(args ?? '');
108
+ if (action.type === 'mode') {
109
+ storage = await setRoutingMode(action.mode, path);
110
+ }
111
+ notify(ctx, executeRoutingCommand({
112
+ argumentsText: args ?? '',
113
+ mode: getRoutingMode(storage),
114
+ }), action.type === 'usage' ? 'warning' : 'info');
115
+ },
116
+ });
102
117
  pi.registerCommand('claude-quota', {
103
118
  description: 'Show Claude quota state for fallback accounts',
104
119
  handler: async (_args, ctx) => {
package/dist/index.js CHANGED
@@ -34,6 +34,15 @@ export default function cortexKitPiAnthropicAuth(pi) {
34
34
  baseUrl: 'https://api.anthropic.com',
35
35
  api: 'cortexkit-anthropic-messages',
36
36
  models: [
37
+ {
38
+ id: 'claude-opus-4-8',
39
+ name: 'Claude Opus 4.8',
40
+ reasoning: true,
41
+ input: ['text', 'image'],
42
+ cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
43
+ contextWindow: 1_000_000,
44
+ maxTokens: 128_000,
45
+ },
37
46
  {
38
47
  id: 'claude-opus-4-5',
39
48
  name: 'Claude Opus 4.5',
package/dist/stream.js CHANGED
@@ -1,4 +1,4 @@
1
- import { applyClaudeCodeHeaders, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, FAST_MODE_BETA, FallbackAccountManager, getCache1hPersistentMode, getRelayConfig, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isFastModePersistentlyEnabled, loadAccounts, mergeAnthropicBetas, resolveClaudeCodeIdentity, sendViaRelay, shouldFallbackStatus, } from '@cortexkit/anthropic-auth-core';
1
+ import { applyClaudeCodeHeaders, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, FAST_MODE_BETA, FallbackAccountManager, getCache1hPersistentMode, getRelayConfig, getRoutingMode, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isFastModePersistentlyEnabled, loadAccounts, mergeAnthropicBetas, resolveClaudeCodeIdentity, sendViaRelay, shouldFallbackStatus, } from '@cortexkit/anthropic-auth-core';
2
2
  import { calculateCost, createAssistantMessageEventStream, } from '@earendil-works/pi-ai';
3
3
  import { buildAnthropicRequest, fromClaudeCodeToolName } from "./convert.js";
4
4
  import { getPiAccountStoragePath } from "./paths.js";
@@ -168,6 +168,32 @@ async function executeWithFallback(options) {
168
168
  configPath: options.storagePath,
169
169
  });
170
170
  const storage = await loadAccounts(options.storagePath);
171
+ async function tryFallbackAccounts() {
172
+ for (const account of await manager.getUsableFallbackAccounts(storage)) {
173
+ if (!account.access)
174
+ continue;
175
+ const response = await sendAnthropicRequest({
176
+ ...options,
177
+ accessToken: account.access,
178
+ });
179
+ const preflight = await firstStreamingError(response);
180
+ if (preflight instanceof Response && preflight.ok) {
181
+ await manager.markUsed(account);
182
+ return preflight;
183
+ }
184
+ if (preflight instanceof Response &&
185
+ !shouldFallbackStatus(preflight.status, storage)) {
186
+ return preflight;
187
+ }
188
+ }
189
+ return null;
190
+ }
191
+ const fallbackFirst = getRoutingMode(storage) === 'fallback-first';
192
+ if (fallbackFirst) {
193
+ const fallback = await tryFallbackAccounts();
194
+ if (fallback)
195
+ return fallback;
196
+ }
171
197
  const primary = await sendAnthropicRequest({
172
198
  ...options,
173
199
  accessToken: options.primaryAccessToken,
@@ -177,22 +203,10 @@ async function executeWithFallback(options) {
177
203
  if (!shouldFallbackStatus(primaryPreflight.status, storage))
178
204
  return primaryPreflight;
179
205
  }
180
- for (const account of await manager.getUsableFallbackAccounts()) {
181
- if (!account.access)
182
- continue;
183
- const response = await sendAnthropicRequest({
184
- ...options,
185
- accessToken: account.access,
186
- });
187
- const preflight = await firstStreamingError(response);
188
- if (preflight instanceof Response && preflight.ok) {
189
- await manager.markUsed(account);
190
- return preflight;
191
- }
192
- if (preflight instanceof Response &&
193
- !shouldFallbackStatus(preflight.status, storage)) {
194
- return preflight;
195
- }
206
+ if (!fallbackFirst) {
207
+ const fallback = await tryFallbackAccounts();
208
+ if (fallback)
209
+ return fallback;
196
210
  }
197
211
  return primaryPreflight instanceof Response ? primaryPreflight : primary;
198
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-anthropic-auth",
3
- "version": "1.2.5",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,7 +35,7 @@
35
35
  "prepublishOnly": "bun run build"
36
36
  },
37
37
  "dependencies": {
38
- "@cortexkit/anthropic-auth-core": "1.2.5"
38
+ "@cortexkit/anthropic-auth-core": "1.4.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@earendil-works/pi-ai": "*",