Skip to content

Commit 82af5f8

Browse files
authored
Merge pull request #198 from tombii/fix/requests-row-model-fallback-429
fix: insert requests row on model-fallback 429 paths
2 parents 95091b5 + a74ead0 commit 82af5f8

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

packages/proxy/src/handlers/proxy-operations.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,27 @@ export async function proxyWithAccount(
745745
`[ccflare] account=${account.name} cooldown_applied reason=${reason} until=${new Date(cooldownUntil).toISOString()}`,
746746
);
747747
account.rate_limited_until = cooldownUntil;
748+
const responseTime = Date.now() - requestMeta.timestamp;
749+
ctx.asyncWriter.enqueue(() =>
750+
ctx.dbOps.saveRequest(
751+
crypto.randomUUID(),
752+
req.method,
753+
url.pathname,
754+
account.id,
755+
429,
756+
false,
757+
reason,
758+
responseTime,
759+
failoverAttempts,
760+
undefined,
761+
requestMeta.agentUsed ?? undefined,
762+
apiKeyId ?? undefined,
763+
apiKeyName ?? undefined,
764+
requestMeta.project ?? null,
765+
undefined,
766+
requestMeta.comboName ?? null,
767+
),
768+
);
748769
ctx.asyncWriter.enqueue(() =>
749770
ctx.dbOps.markAccountRateLimited(
750771
account.id,
@@ -861,6 +882,27 @@ export async function proxyWithAccount(
861882
`[ccflare] account=${account.name} cooldown_applied reason=${reason} until=${new Date(cooldownUntil).toISOString()}`,
862883
);
863884
account.rate_limited_until = cooldownUntil;
885+
const responseTime = Date.now() - requestMeta.timestamp;
886+
ctx.asyncWriter.enqueue(() =>
887+
ctx.dbOps.saveRequest(
888+
crypto.randomUUID(),
889+
req.method,
890+
url.pathname,
891+
account.id,
892+
429,
893+
false,
894+
reason,
895+
responseTime,
896+
failoverAttempts,
897+
undefined,
898+
requestMeta.agentUsed ?? undefined,
899+
apiKeyId ?? undefined,
900+
apiKeyName ?? undefined,
901+
requestMeta.project ?? null,
902+
undefined,
903+
requestMeta.comboName ?? null,
904+
),
905+
);
864906
ctx.asyncWriter.enqueue(() =>
865907
ctx.dbOps.markAccountRateLimited(
866908
account.id,

0 commit comments

Comments
 (0)