@cortexkit/pi-anthropic-auth 2.4.5 → 2.4.6

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.
Files changed (2) hide show
  1. package/dist/stream.js +17 -14
  2. package/package.json +2 -2
package/dist/stream.js CHANGED
@@ -1,4 +1,4 @@
1
- import { applyClaudeCodeHeaders, applyCustomHeaders, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, CacheKeepSessionRegistry, createProviderErrorResponseScope, createSseFramer, createStickyNoRouteResponse, decideStickyQuotaFailure, decodeSseFrame, dumpDirectRequest, FAST_MODE_BETA, getCache1hPersistentMode, getClaudeCodeIdentityForVerifiedAccount, getDefaultCacheKeepRegistryDirectory, getFallbackReauthLabels, getQuotaCheckIntervalMs, getRequestGzipLatch, getRequestGzipLatchPath, getRoutingMode, getScopedQuotaWindowForModel, getThinkingPrefixMismatchBehavior, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, isKillswitchEnabled, isNativeTransientAccountError, isOAuthAccount, isPermanentRefreshError, isValidApiBaseURL, killswitchPassesPolicy, logger, mergeAnthropicBetas, NativeAccountRefusal, NativeVaultNoAccountError, nativeAccountCanServe, parseSseFrame, QuotaManager, quotaBackoffActive, quotaSnapshotHasStandardWindows, quotaSnapshotModelScopeIsExhausted, quotaSnapshotPassesModelScope, quotaSnapshotPassesPolicy, STICKY_ROUTING_MAIN_ACCOUNT_ID, StickySessionRouter, sendViaRelay, sendWithRequestGzip, setDumpEnabled, shouldFallbackStatus, stickyQuotaSnapshotIsFresh, stickyRetryAfterWithJitter, stickyRouteFamilyForModel, } from '@cortexkit/anthropic-auth-core';
1
+ import { applyClaudeCodeHeaders, applyCustomHeaders, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, CacheKeepSessionRegistry, createProviderErrorResponseScope, createSseFramer, createStickyNoRouteResponse, decideStickyQuotaFailure, decodeSseFrame, dumpDirectRequest, FAST_MODE_BETA, getCache1hPersistentMode, getClaudeCodeIdentityForVerifiedAccount, getDefaultCacheKeepRegistryDirectory, getFallbackReauthLabels, getQuotaCheckIntervalMs, getRequestGzipLatch, getRequestGzipLatchPath, getRoutingMode, getScopedQuotaWindowForModel, getThinkingPrefixMismatchBehavior, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, isKillswitchEnabled, isNativeTransientAccountError, isOAuthAccount, isPermanentRefreshError, isValidApiBaseURL, killswitchPassesPolicy, logger, mergeAnthropicBetas, NativeAccountRefusal, NativeVaultNoAccountError, nativeAccountCanServe, parseSseFrame, QuotaManager, quotaBackoffActive, quotaExhaustionFromHeaders, quotaSnapshotHasStandardWindows, quotaSnapshotModelScopeIsExhausted, quotaSnapshotPassesModelScope, quotaSnapshotPassesPolicy, STICKY_ROUTING_MAIN_ACCOUNT_ID, StickySessionRouter, sendViaRelay, sendWithRequestGzip, setDumpEnabled, shouldFallbackStatus, stickyQuotaSnapshotIsFresh, stickyRetryAfterWithJitter, stickyRouteFamilyForModel, } 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 { getPiNativeRuntime, piAttemptAccessToken, } from './native.js';
@@ -1051,23 +1051,26 @@ async function executeWithFallback(options) {
1051
1051
  let migrate = (preflight instanceof Response && preflight.status === 403) ||
1052
1052
  permanentAuthFailure;
1053
1053
  if (primaryResponseAllowsApiFallback(preflight)) {
1054
- let quota;
1055
- try {
1056
- quota =
1057
- route.id === STICKY_ROUTING_MAIN_ACCOUNT_ID
1058
- ? await quotaManager.refreshMain(mainAccountId, '')
1059
- : await quotaManager.refreshFallback(route.id, '', route.account);
1060
- }
1061
- catch {
1062
- // Retain affinity when the quota probe itself is unavailable.
1063
- quota = undefined;
1054
+ const responseHeaders = preflight instanceof Response ? preflight.headers : response.headers;
1055
+ let quota = quotaExhaustionFromHeaders(responseHeaders, options.model.id);
1056
+ // Do not extend the usage endpoint's own rate limit when the refusal
1057
+ // already confirms exhaustion.
1058
+ if (Object.keys(quota).length === 0) {
1059
+ try {
1060
+ quota =
1061
+ route.id === STICKY_ROUTING_MAIN_ACCOUNT_ID
1062
+ ? await quotaManager.refreshMain(mainAccountId, '')
1063
+ : await quotaManager.refreshFallback(route.id, '', route.account);
1064
+ }
1065
+ catch {
1066
+ // Retain affinity when the quota probe itself is unavailable.
1067
+ quota = undefined;
1068
+ }
1064
1069
  }
1065
1070
  const decision = decideStickyQuotaFailure({
1066
1071
  quota,
1067
1072
  modelId: options.model.id,
1068
- responseHeaders: preflight instanceof Response
1069
- ? preflight.headers
1070
- : response.headers,
1073
+ responseHeaders,
1071
1074
  });
1072
1075
  if (decision.action === 'hold') {
1073
1076
  const headers = new Headers(preflight instanceof Response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-anthropic-auth",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,7 +36,7 @@
36
36
  "prepublishOnly": "bun run build"
37
37
  },
38
38
  "dependencies": {
39
- "@cortexkit/anthropic-auth-core": "2.4.5"
39
+ "@cortexkit/anthropic-auth-core": "2.4.6"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@earendil-works/pi-ai": ">=0.86.1 <2",