Skip to content

Conversation

@jezekra1
Copy link
Collaborator

@jezekra1 jezekra1 commented Dec 9, 2025

Summary

  • add "role-based" rate limits:
rateLimit:
  enabled: false
  globalLimits:
    - "20/second"
    - "100/minute"
  strategy: "sliding-window-counter"
  roleBasedLimits:
    user:
      openai_chat_completion_tokens: []
      # - "100000/minute"
      openai_chat_completion_requests: []
      # - "100/minute"
      openai_embedding_inputs: []
      # - "1000/minute"
    developer:
      openai_chat_completion_tokens: []
      openai_chat_completion_requests: []
      openai_embedding_inputs: []
    admin:
      openai_chat_completion_tokens: []
      openai_chat_completion_requests: []
      openai_embedding_inputs: []
  • refactor openai proxy

Linked Issues

Ref: #1450

Documentation

  • No Docs Needed:

@jezekra1 jezekra1 requested a review from JanPokorny December 9, 2025 16:25
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Dec 9, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jezekra1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a robust role-based rate limiting system for the OpenAI proxy, allowing administrators to define distinct usage quotas for different user roles across various OpenAI API functionalities. It also includes a substantial refactoring of the OpenAI proxy's internal architecture, transitioning to a more flexible and maintainable adapter pattern. These changes ensure better resource management, prevent abuse, and improve the overall stability and extensibility of the proxy service.

Highlights

  • Role-Based Rate Limits: Introduced a new system for applying rate limits based on user roles (user, developer, admin) for specific OpenAI API calls, such as chat completion tokens, chat completion requests, and embedding inputs.
  • OpenAI Proxy Refactoring: The OpenAI proxy logic has been significantly refactored into a more modular architecture using protocol-based adapters, making it easier to integrate and manage different OpenAI-compatible model providers.
  • Rate Limit Configuration: The rate limit configuration now supports defining global limits and granular role-based limits, with examples provided for common OpenAI usage metrics.
  • Error Handling and Cost Estimation: Enhanced error handling for rate limit exceeded scenarios, including specific HTTP headers, and implemented a mechanism to estimate LLM token costs for accurate rate limiting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust role-based rate limiting mechanism for the OpenAI proxy endpoints, significantly enhancing the server's control over resource consumption. The changes involve a substantial refactoring of the model provider interaction logic, moving it behind new interfaces (IOpenAIProxy, IOpenAIChatCompletionProxyAdapter, IOpenAIEmbeddingProxyAdapter) and adapter implementations for various model providers (OpenAI, WatsonX, RITS, Anthropic, Github, Voyage). This refactoring greatly improves modularity, testability, and extensibility.

Key improvements include:

  • Modular Design: The introduction of proxy interfaces and adapters cleanly separates the concerns of model interaction from the API layer.
  • Role-Based Rate Limiting: Users are now subject to rate limits based on their assigned roles, with separate limits for chat completion tokens, chat completion requests, and embedding inputs.
  • Token Cost Estimation: A heuristic-based token cost estimation is implemented for LLM and embedding requests, allowing for more granular rate limiting.
  • Improved Error Handling: Rate limit exceeded errors are now properly caught and returned with appropriate HTTP status codes and X-RateLimit-* headers.
  • Configuration Updates: The Configuration and Helm charts have been updated to support the new rate limiting parameters.
  • Comprehensive Testing: New integration tests have been added to validate the rate limiting functionality.

Overall, this is a well-executed feature that improves the stability and manageability of the server, particularly for AI model interactions.

@jezekra1 jezekra1 force-pushed the add-role-based-rate-limits branch 7 times, most recently from fabd04a to d826010 Compare December 10, 2025 12:56
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 10, 2025
@jezekra1 jezekra1 force-pushed the add-role-based-rate-limits branch from d826010 to da7c128 Compare December 10, 2025 13:15
@jezekra1 jezekra1 merged commit d1c1420 into main Dec 10, 2025
11 checks passed
@jezekra1 jezekra1 deleted the add-role-based-rate-limits branch December 10, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants