Skip to content

Auto-activate Gatewayz top models on startup; add gatewayz API endpoints#4

Open
vdimarco wants to merge 2 commits into
mainfrom
gatewayz-code/update-openweb-ui-gatewayz-active-pfqupq
Open

Auto-activate Gatewayz top models on startup; add gatewayz API endpoints#4
vdimarco wants to merge 2 commits into
mainfrom
gatewayz-code/update-openweb-ui-gatewayz-active-pfqupq

Conversation

@vdimarco

@vdimarco vdimarco commented Feb 2, 2026

Copy link
Copy Markdown

Summary

  • Auto-activate top Gatewayz models on startup when Gatewayz is enabled.
  • Introduce Gatewayz ranking API integration: fetch rankings and derive top models by provider.
  • Expose gatewayz ranking endpoints in the backend and frontend for consumption.
  • Add tests for the top-model extraction logic.
  • Default Gatewayz enablement with Dockerfile configuration; OpenAI and Ollama disabled by default.

Changes

Backend

  • Add Gatewayz activation flow:
    • New function activate_top_gatewayz_models(app) in backend/open_webui/main.py to fetch rankings and set top models as active for the first Gatewayz API URL. Handles missing config and errors gracefully.
    • Startup hook to run auto-activation when ENABLE_GATEWAYZ_API is true.
  • Gatewayz API integration (backend/open_webui/routers/gatewayz.py):
    • Introduce TOP_MODEL_PROVIDERS = ["openai", "anthropic", "google", "xai"] and TOP_MODELS_PER_PROVIDER = 3.
    • fetch_rankings_from_gatewayz(api_url, api_key): fetches rankings from /ranking/apps with optional Bearer token.
    • extract_top_models_by_provider(rankings, providers, top_n): returns top N models per provider, supporting various ranking shapes and inferring provider when needed.
    • Endpoints:
      • GET /rankings: returns rankings data, top_models, providers, top_n_per_provider.
      • GET /rankings/top-models: returns only the top_models list.
  • Config wiring:
    • The gatewayz API config paths are used to populate active models on startup.

Frontend / API (TypeScript)

  • src/lib/apis/gatewayz/index.ts:
    • Added GatewayzRankingsResponse type and getGatewayzRankings(token) to fetch /rankings.
    • Added getGatewayzTopModels(token) to fetch /rankings/top-models.
    • API calls include token-based authorization when provided.

Tests

  • Added tests for extract_top_models_by_provider in backend/open_webui/test/apps/webui/routers/test_gatewayz.py:
    • Empty, None, dict-wrapped data, list formats, model_id/name fields, provider inference, owned_by field, duplicate handling, and multi-provider aggregation.
  • Added TestTopModelProviders to verify defaults for TOP_MODEL_PROVIDERS and TOP_MODELS_PER_PROVIDER.

Deployment / Config

  • Dockerfile: Gatewayz APIs enabled by default by setting:
    • ENABLE_OLLAMA_API=false, ENABLE_OPENAI_API=false, ENABLE_GATEWAYZ_API=true
  • backend/open_webui/config.py:
    • ENABLE_OLLAMA_API and ENABLE_OPENAI_API default parsing changed to treat missing env as False (lower()==

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://terragon-www-production.up.railway.app/task/b5e46d51-e57f-4605-8f30-45c66b248600

Greptile Overview

Greptile Summary

This PR implements auto-activation of top-ranked Gatewayz models on application startup and exposes ranking API endpoints for frontend consumption.

Key Changes

  • Auto-activation on startup: When ENABLE_GATEWAYZ_API is true, the app automatically fetches rankings from Gatewayz API and activates the top 3 models from each of 4 providers (OpenAI, Anthropic, Google, xAI)
  • Ranking API integration: New /rankings and /rankings/top-models endpoints expose model rankings to authenticated users
  • Default configuration shift: Gatewayz is now enabled by default in Dockerfile, while Ollama and OpenAI APIs are disabled by default
  • Comprehensive test coverage: Added 14 unit tests covering edge cases in model extraction logic

Architecture

The implementation adds a startup hook that queries the Gatewayz /ranking/apps endpoint, extracts top models using flexible parsing (handles multiple data formats, provider field variations, and model ID inference), and persists the configuration to GATEWAYZ_API_CONFIGS. The frontend gains TypeScript API functions to fetch these rankings.

Issues Found

  • IndexError risk: GATEWAYZ_API_KEYS[0] access in backend/open_webui/main.py:576-580 doesn't check list length, only truthiness, which can fail if the list is empty

Confidence Score: 4/5

  • This PR is safe to merge with one IndexError bug fix needed
  • The implementation is well-structured with comprehensive error handling, extensive test coverage, and graceful degradation. One critical bug exists (IndexError on empty list), but the overall design is solid with proper validation, logging, and startup error recovery
  • backend/open_webui/main.py requires a fix for the IndexError in the API key access logic

Important Files Changed

Filename Overview
backend/open_webui/main.py Added auto-activation of top Gatewayz models on startup via new activate_top_gatewayz_models function with error handling
backend/open_webui/routers/gatewayz.py Added ranking API integration with /rankings and /rankings/top-models endpoints, plus helper functions for fetching and extracting top models
backend/open_webui/config.py Changed default values for ENABLE_OLLAMA_API and ENABLE_OPENAI_API from True to False

Sequence Diagram

sequenceDiagram
    participant App as FastAPI App
    participant Startup as Lifespan Startup
    participant ActFunc as activate_top_gatewayz_models
    participant FetchFunc as fetch_rankings_from_gatewayz
    participant ExtractFunc as extract_top_models_by_provider
    participant Config as GATEWAYZ_API_CONFIGS
    participant GatewayAPI as Gatewayz API

    App->>Startup: Start application
    Startup->>Startup: Check ENABLE_GATEWAYZ_API
    
    alt ENABLE_GATEWAYZ_API is true
        Startup->>ActFunc: Call function
        ActFunc->>ActFunc: Check GATEWAYZ_API_BASE_URLS exists
        
        alt URLs configured
            ActFunc->>ActFunc: Get first URL and API key
            ActFunc->>FetchFunc: Fetch rankings
            FetchFunc->>FetchFunc: Construct rankings URL
            FetchFunc->>GatewayAPI: GET /ranking/apps with Bearer token
            GatewayAPI-->>FetchFunc: Return rankings data or error
            FetchFunc-->>ActFunc: Return rankings list or empty array
            
            alt Rankings received
                ActFunc->>ExtractFunc: Extract top models by provider
                ExtractFunc->>ExtractFunc: Parse rankings data
                ExtractFunc->>ExtractFunc: Group models by provider
                ExtractFunc->>ExtractFunc: Select top 3 per provider
                ExtractFunc-->>ActFunc: Return list of top model IDs
                
                alt Top models found
                    ActFunc->>Config: Update config index 0
                    ActFunc->>Config: Set enable=true, model_ids=top_models
                    Config-->>ActFunc: Configuration persisted
                    ActFunc->>ActFunc: Log success
                else No top models
                    ActFunc->>ActFunc: Log warning
                end
            else No rankings
                ActFunc->>ActFunc: Log warning
            end
        else No URLs configured
            ActFunc->>ActFunc: Log info message
        end
    end
    
    Startup->>App: Continue startup process
Loading

vdimarco and others added 2 commits February 2, 2026 01:43
…tion

- Disable OpenAI and Ollama APIs by default (config.py)
- Add explicit env vars for Gatewayz-only mode in Dockerfile
- Add /rankings and /rankings/top-models endpoints to fetch popular models
- Auto-activate top 3 models from each provider (OpenAI, Anthropic, Google, xAI) on startup
- Add frontend API functions for rankings
- Add unit tests for extract_top_models_by_provider

The rankings are synced on every startup to keep models current.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix PersistentConfig mutation by creating new dict before assignment
- Add documentation for /ranking/apps endpoint verification
- Improve logging for missing API keys and empty rankings
- Make error messages more actionable for users

Addresses PR comments:
- backend/open_webui/main.py:606 - Fixed config mutation
- backend/open_webui/routers/gatewayz.py:410 - Verified endpoint
- backend/open_webui/main.py:569 - Added helpful logging

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@vdimarco has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 6 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gatewayz-code/update-openweb-ui-gatewayz-active-pfqupq

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +576 to +580
api_key = (
app.state.config.GATEWAYZ_API_KEYS[0]
if app.state.config.GATEWAYZ_API_KEYS
else ""
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Potential IndexError if GATEWAYZ_API_KEYS is an empty list

Suggested change
api_key = (
app.state.config.GATEWAYZ_API_KEYS[0]
if app.state.config.GATEWAYZ_API_KEYS
else ""
)
api_key = (
app.state.config.GATEWAYZ_API_KEYS[0]
if app.state.config.GATEWAYZ_API_KEYS and len(app.state.config.GATEWAYZ_API_KEYS) > 0
else ""
)
Prompt To Fix With AI
This is a comment left during a code review.
Path: backend/open_webui/main.py
Line: 576:580

Comment:
Potential `IndexError` if `GATEWAYZ_API_KEYS` is an empty list

```suggestion
        api_key = (
            app.state.config.GATEWAYZ_API_KEYS[0]
            if app.state.config.GATEWAYZ_API_KEYS and len(app.state.config.GATEWAYZ_API_KEYS) > 0
            else ""
        )
```

How can I resolve this? If you propose a fix, please make it concise.

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.

1 participant