feat: add sticky round-robin routing strategy

Implements a "sticky" round-robin strategy that uses the same provider
account for a configurable number of consecutive calls (default 3)
before switching to the next one. This optimizes for prompt caching
by reducing organization/account rotation. Adds a configuration input
to the Profile settings page.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Catalin Stanciu
2026-01-09 17:45:32 +07:00
committed by decolua
co-authored by Claude Sonnet 4.5
parent f2abcc6585
commit 4f292aae63
3 changed files with 84 additions and 14 deletions
+41 -1
View File
@@ -76,6 +76,24 @@ export default function ProfilePage() {
}
};
const updateStickyLimit = async (limit) => {
const numLimit = parseInt(limit);
if (isNaN(numLimit) || numLimit < 1) return;
try {
const res = await fetch("/api/settings", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ stickyRoundRobinLimit: numLimit }),
});
if (res.ok) {
setSettings(prev => ({ ...prev, stickyRoundRobinLimit: numLimit }));
}
} catch (err) {
console.error("Failed to update sticky limit:", err);
}
};
return (
<div className="max-w-2xl mx-auto">
<div className="flex flex-col gap-6">
@@ -165,9 +183,31 @@ export default function ProfilePage() {
disabled={loading}
/>
</div>
{/* Sticky Round Robin Limit */}
{settings.fallbackStrategy === "round-robin" && (
<div className="flex items-center justify-between pt-2 border-t border-border/50">
<div>
<p className="font-medium">Sticky Limit</p>
<p className="text-sm text-text-muted">
Calls per account before switching
</p>
</div>
<Input
type="number"
min="1"
max="10"
value={settings.stickyRoundRobinLimit || 3}
onChange={(e) => updateStickyLimit(e.target.value)}
disabled={loading}
className="w-20 text-center"
/>
</div>
)}
<p className="text-xs text-text-muted italic pt-2 border-t border-border/50">
{settings.fallbackStrategy === "round-robin"
? "Currently distributing requests across all available accounts."
? `Currently distributing requests across all available accounts with ${settings.stickyRoundRobinLimit || 3} calls per account.`
: "Currently using accounts in priority order (Fill First)."}
</p>
</div>