MCPcopy Create free account
hub / github.com/dwgx/WindsurfAPI / acquireAccountByKey

Function acquireAccountByKey

src/auth.js:902–925  ·  view source on GitHub ↗
(apiKey, modelKey = null)

Source from the content-addressed store, hash-verified

900 * back to a fresh cascade on a different account instead of queuing.
901 */
902export function acquireAccountByKey(apiKey, modelKey = null) {
903 const now = Date.now();
904 const a = accounts.find(x => x.apiKey === apiKey);
905 if (!a) return null;
906 if (a.status !== 'active') return null;
907 if (isAccountInMaintenance(a)) return null;
908 if (isRateLimitedForModel(a, modelKey, now)) return null;
909 const limit = rpmLimitFor(a);
910 if (limit <= 0) return null;
911 const used = pruneRpmHistory(a, now);
912 if (used >= limit) return null;
913 if (modelKey && !isModelAllowedForAccount(a, modelKey)) return null;
914 const reservationTimestamp = nextReservationToken(now);
915 a._rpmHistory.push(reservationTimestamp);
916 a.lastUsed = now;
917 a._inflight = (a._inflight || 0) + 1;
918 a._inflightAt = now;
919 return {
920 id: a.id, email: a.email, apiKey: a.apiKey,
921 apiServerUrl: a.apiServerUrl || '',
922 proxy: getEffectiveProxy(a.id) || null,
923 reservationTimestamp,
924 };
925}
926
927/**
928 * Explain why a pinned account cannot be used right now. Used by strict

Callers 2

handlerFunction · 0.90

Calls 8

getEffectiveProxyFunction · 0.90
isAccountInMaintenanceFunction · 0.85
isRateLimitedForModelFunction · 0.85
rpmLimitForFunction · 0.85
pruneRpmHistoryFunction · 0.85
isModelAllowedForAccountFunction · 0.85
nextReservationTokenFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected