Skip to content

feat: basic rate limits#358

Open
theuargb wants to merge 1 commit intocgoinglove:mainfrom
theuargb:feature-basic-rate-limits
Open

feat: basic rate limits#358
theuargb wants to merge 1 commit intocgoinglove:mainfrom
theuargb:feature-basic-rate-limits

Conversation

@theuargb
Copy link
Contributor

Implements #357

Main limitation: redis-only.

  • add Redis-backed AI rate limiting with per-role env knobs (user/editor/admin) plus fallback defaults
  • enforce limits on chat and temporary chat endpoints; surface localized, user-friendly rate-limit UI
image

@vercel
Copy link

vercel bot commented Dec 24, 2025

@theuargb is attempting to deploy a commit to the cgoinglove's projects Team on Vercel.

A member of the Team first needs to authorize it.

import globalLogger from "logger";
import { buildUserSystemPrompt } from "lib/ai/prompts";
import { getUserPreferences } from "lib/user/server";
import { getAiRateLimiter } from "lib/ai/rate-limit";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename this to getRateLimiter

if (rateLimiter) {
const rateLimitResult = await rateLimiter.check(
session.user.id,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of as anys, could you fix this. The code quality is not great because of them

@@ -0,0 +1,101 @@
import { describe, expect, it, vi } from "vitest";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { describe, expect, it, vi } from "vitest";
import { describe, expect, it} from "vitest";

@@ -0,0 +1,195 @@
import Redis from "ioredis";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a lib/redis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants