Commit graph

33167 commits

Author SHA1 Message Date
Yuneng Jiang
79c3fc9738
chore: fixes
Some checks failed
Unit Tests: Caching (Redis) / caching-redis (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (auth-checks, tests/proxy_unit_tests/test_auth_checks.py tests/proxy_unit_tests/test_user_api_key_auth.py, 20, 8) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (key-generation, tests/proxy_unit_tests/test_key_generate_prisma.py, 30, 0) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (remaining, tests/proxy_unit_tests --ignore=tests/proxy_unit_tests/test_key_generate_prisma.py --ignore=tests/proxy_unit_tests/test_auth_checks.py --ignore=tests/proxy_unit_tests/test_user_api_key_auth.py, 20, 8) (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled
2026-04-05 00:15:54 -07:00
Ishaan Jaffer
8d93a02c80 fix(config): deduplicate keywords across code and technical lists 2026-02-21 13:09:18 -08:00
Ishaan Jaffer
a5f1460d1b fix(complexity_router): align .get() fallbacks with config.py defaults, document system prompt scoring 2026-02-21 13:09:13 -08:00
Ishaan Jaffer
4d9c83f35a test(complexity_router): add false positive tests for error/class/merge keyword matching 2026-02-21 12:46:55 -08:00
Ishaan Jaffer
8281f97206 docs(README): fix token thresholds to match config.py defaults 2026-02-21 12:46:47 -08:00
Ishaan Jaffer
2ba44c6b51 fix(router): clarify circular import comment for ComplexityRouter 2026-02-21 12:46:43 -08:00
Ishaan Jaffer
2ad36dd2a6 fix(complexity_router): use word boundary matching for all single-word keywords, avoid double-scanning reasoning keywords 2026-02-21 12:46:29 -08:00
Ishaan Jaffer
1943991f6d fix(config): remove unused DEFAULT_MULTI_STEP_PATTERNS and DEFAULT_CREATIVE_KEYWORDS exports 2026-02-21 12:46:23 -08:00
Ishaan Jaffer
e6c4e38b0a fix(router): remove or {} masking None complexity_router_config 2026-02-21 12:20:31 -08:00
Ishaan Jaffer
25391a8c10 fix(complexity_router): skip empty string content in async_pre_routing_hook 2026-02-21 12:20:16 -08:00
Ishaan Jaffer
4755c8f5b8 docs(auto_routing): fix dimension weights and tier boundaries to match config.py defaults 2026-02-21 12:20:07 -08:00
OpenClaw Assistant
93688aea8d fix(complexity_router): Address Greptile review round 2
1. **Empty user message handling** - Changed from falsy check to None check
   to properly distinguish 'no user message' from 'empty string message'

2. **ReDoS prevention** - Changed 'first.*then' to 'first.*?then' (non-greedy)
   to prevent regex backtracking on pathological inputs

3. **Documentation sync** - Updated README.md to match actual config values:
   - Tier boundaries: 0.15/0.35/0.60 (not 0.25/0.50/0.75)
   - Dimension weights: tokenCount=0.10, codePresence=0.30, technicalTerms=0.25,
     simpleIndicators=0.05, multiStepPatterns=0.03, questionComplexity=0.02

4. **Missing UI component** - Added ComplexityRouterConfig.tsx with:
   - Tier-to-model dropdown selectors
   - Descriptions and examples for each tier
   - How classification works explanation

5. **Inline import comment** - Added explanation for why ComplexityRouter
   import is inline (matches AutoRouter pattern, avoids circular imports)
2026-02-21 19:58:10 +00:00
OpenClaw Assistant
c73b8ec385 feat(complexity_router): Add eval suite + tune scoring parameters
Added comprehensive evaluation suite with 29 test cases covering:
- SIMPLE tier: greetings, definitions, factual questions
- MEDIUM tier: technical explanations, comparisons, debugging
- COMPLEX tier: architecture design, complex coding
- REASONING tier: explicit reasoning requests
- Regression tests: substring false positive prevention

Tuned scoring parameters based on eval results:
- Lowered tier boundaries (0.15/0.35/0.60) for better tier distribution
- Increased code/technical weights (0.30/0.25) for complex prompts
- Reduced simple indicator weight (0.05) to avoid over-penalizing
- Fixed 'hey'/'hi' keywords to require leading space

Eval results: 29/29 passed (100%)
2026-02-21 19:47:57 +00:00
Shin (LiteLLM AI)
1c5d8e3020 docs(auto_routing): Add complexity router documentation
- Add Complexity Router section to auto_routing.md
- Include comparison table with semantic auto router
- Add Python SDK and Proxy Server configuration examples
- Document all configuration options (tier boundaries, token thresholds, dimension weights)
- Explain how complexity scoring works
2026-02-21 19:43:55 +00:00
Shin (LiteLLM AI)
cc7d12a57a fix(complexity_router): Address Greptile review feedback
- Use word boundary matching for short keywords (<5 chars) to avoid
  false positives (e.g., 'api' matching 'capital', 'git' matching 'digital')
- Remove 'ok' from simple keywords (too many false positives)
- Add tests for keyword false positive prevention
- Fix test expectations for edge cases (empty string content, list content)

Addresses: 2/5 Greptile score feedback on PR #21789
2026-02-21 19:42:25 +00:00
OpenClaw Assistant
35aa12200a fix(complexity_router): Address Greptile review feedback
Fixes 5 issues flagged in code review:

1. **Mutable singleton mutation bug** - Now always creates a new
   ComplexityRouterConfig instance instead of reusing DEFAULT_COMPLEXITY_CONFIG
   singleton, preventing cross-instance config pollution.

2. **Substring matching false positives** - Added word boundaries (spaces)
   to short keywords like 'ok', 'try', 'api', 'git', 'node', 'java', 'vue'
   to prevent matching within longer words (e.g., 'capital' matching 'api').

3. **Redundant message extraction** - Simplified to single reverse loop that
   extracts both last user message and last system prompt efficiently.

4. **Unused imports** - Removed unused DEFAULT_CREATIVE_KEYWORDS and
   DEFAULT_MULTI_STEP_PATTERNS imports.

5. **Missing async_pre_routing_hook tests** - Added comprehensive tests for:
   - Multi-turn conversations
   - List-type content handling
   - No user message case
   - Empty string content
   - Message preservation
   - Singleton mutation prevention
2026-02-21 19:38:02 +00:00
OpenClaw Assistant
9d575bc2c9 fix: exclude complexity_router from auto_router check
The _is_auto_router_deployment() was matching all auto_router/* models,
causing complexity_router to fail initialization. Now it explicitly
excludes auto_router/complexity_router which has its own handler.
2026-02-21 19:32:06 +00:00
OpenClaw Assistant
95c6bfaa06 chore: remove preset feature, keep simple tier config 2026-02-21 19:27:48 +00:00
OpenClaw Assistant
f096d9dce6 docs: update PR description with UI changes 2026-02-21 19:27:05 +00:00
OpenClaw Assistant
cad68281d4 feat(ui): update auto router submit handler for complexity router
- Handle complexity_router model type in submit handler
- Generate correct litellm_params for complexity router:
  - model: auto_router/complexity_router
  - complexity_router_config: { tiers: { SIMPLE, MEDIUM, COMPLEX, REASONING } }
- Keep existing semantic router handling intact
- Add success notification with router type name
2026-02-21 19:25:48 +00:00
OpenClaw Assistant
a12ea42953 feat: add enterprise presets for complexity router
Adds preset configurations for different cloud providers:
- bedrock: AWS Bedrock (Claude models)
- vertex: Google Vertex AI (Gemini models)
- azure: Azure OpenAI (GPT + o1)
- standard: Direct API (OpenAI + Anthropic)
- cost_optimized: Maximum savings (Gemini Flash + cheaper models)

Usage:
```yaml
complexity_router_config:
  preset: bedrock  # or vertex, azure, standard, cost_optimized
```
2026-02-21 19:25:48 +00:00
OpenClaw Assistant
cf0965f23f feat(router): Add complexity-based auto routing strategy
Adds a new rule-based routing strategy that classifies requests by complexity
and routes them to appropriate models - without any external API calls.

- Weighted scoring across 7 dimensions: token count, code presence, reasoning
  markers, technical terms, simple indicators, multi-step patterns, questions
- Maps to 4 tiers: SIMPLE, MEDIUM, COMPLEX, REASONING
- Each tier configurable to a different model
- Zero API calls, <1ms latency
- Inspired by ClawRouter

```yaml
model_list:
  - model_name: smart_router
    litellm_params:
      model: auto_router/complexity_router
      complexity_router_config:
        tiers:
          SIMPLE: gemini-2.0-flash
          MEDIUM: gpt-4o-mini
          COMPLEX: claude-sonnet-4
          REASONING: claude-opus-4
```

- Cost optimization: route simple queries to cheaper models
- Quality optimization: route complex queries to capable models
- Zero configuration: works out of the box with sensible defaults
2026-02-21 19:25:48 +00:00
OpenClaw Assistant
030e868663 feat(router): Add complexity-based auto routing strategy
Adds a new rule-based routing strategy that classifies requests by complexity
and routes them to appropriate models - without any external API calls.

## Features
- Weighted scoring across 7 dimensions: token count, code presence, reasoning
  markers, technical terms, simple indicators, multi-step patterns, questions
- Maps to 4 tiers: SIMPLE, MEDIUM, COMPLEX, REASONING
- Each tier configurable to a different model
- Zero API calls, <1ms latency
- Inspired by ClawRouter

## Configuration
```yaml
model_list:
  - model_name: smart_router
    litellm_params:
      model: auto_router/complexity_router
      complexity_router_config:
        tiers:
          SIMPLE: gemini-2.0-flash
          MEDIUM: gpt-4o-mini
          COMPLEX: claude-sonnet-4
          REASONING: claude-opus-4
```

## Use Cases
- Cost optimization: route simple queries to cheaper models
- Quality optimization: route complex queries to capable models
- Zero configuration: works out of the box with sensible defaults
2026-02-21 19:25:48 +00:00
OpenClaw Assistant
292a0f8d07 feat(router): Add complexity-based auto routing strategy
Adds a rule-based routing strategy that classifies requests by complexity
and routes them to appropriate models - with zero API calls and sub-millisecond
latency.

## Features

- **Zero external API calls** - all scoring is local
- **Sub-millisecond latency** - typically <1ms per classification
- **Weighted multi-dimensional scoring** across 7 dimensions:
  - Token count (short=simple, long=complex)
  - Code presence (code keywords → complex)
  - Reasoning markers ("step by step" → reasoning tier)
  - Technical terms (domain complexity)
  - Simple indicators ("what is" → simple, negative weight)
  - Multi-step patterns (numbered steps)
  - Question complexity (multiple questions)
- **Configurable tier boundaries** and model mappings
- **Reasoning override** - 2+ reasoning markers force REASONING tier

## Usage

```yaml
model_list:
  - model_name: smart-router
    litellm_params:
      model: auto_router/complexity_router
      complexity_router_config:
        tiers:
          SIMPLE: gpt-4o-mini
          MEDIUM: gpt-4o
          COMPLEX: claude-sonnet-4
          REASONING: o1-preview
```

Inspired by ClawRouter: https://github.com/BlockRunAI/ClawRouter

## Files Added

- litellm/router_strategy/complexity_router/complexity_router.py - Main router class
- litellm/router_strategy/complexity_router/config.py - Configuration and defaults
- litellm/router_strategy/complexity_router/__init__.py - Package exports
- litellm/router_strategy/complexity_router/README.md - Documentation
- tests/test_litellm/router_strategy/test_complexity_router.py - Test suite (37 tests)

## Files Modified

- litellm/router.py - Integration with pre_routing_hook
- litellm/types/router.py - New config params
2026-02-21 19:25:48 +00:00
Ishaan Jaff
21a549d78d
fix(tests): isolate flaky files endpoint tests from global proxy state (#21788)
* fix(tests): isolate flaky files endpoint tests from global proxy state

* test(secret_managers): add mocked unit test for write/read JSON secret cycle
2026-02-21 11:20:32 -08:00
Ishaan Jaff
2acc5cc457
fix(security): fix CVE-2025-69873, CVE-2026-26996 in docs deps; allowlist nodejs_wheel CVEs in Grype scan (#21787)
* fix(security): fix CVE-2025-69873 and CVE-2026-26996 in docs dependencies

Use npm overrides to pin patched versions:
- ajv@6.12.6 → 6.14.0 (fixes ReDoS CVE-2025-69873)
- ajv@8.17.1 → 8.18.0 (fixes ReDoS CVE-2025-69873)
- minimatch@3.1.2 → 10.2.1 (fixes DoS CVE-2026-26996)

serve-handler only calls minimatch(path, pattern) so the 3.x→10.x
upgrade is safe.

* fix(ruff): add missing Set and Dict imports to fix F821 errors

* fix(security): scope ajv overrides to avoid top-level version conflict

Replacing global 'ajv: 8.18.0' override with scoped 'schema-utils@4'
override. The global override conflicted with the nested file-loader/
null-loader/url-loader overrides, causing npm to install ajv@6 at the
top level where ajv-keywords@5.x requires ajv@8 (ajv/dist/compile/codegen).

Now:
- schema-utils@3 + loaders → ajv@6.14.0 (safe minor bump)
- schema-utils@4 → ajv@8.18.0 (safe minor bump)
- top-level ajv unmodified (stays at 8.x for ajv-keywords@5)

* fix(security): allowlist minimatch and tar CVEs from nodejs_wheel, bump tar override to >=7.5.8
2026-02-21 11:18:52 -08:00
Ishaan Jaff
d95c3e9cd4
fix(ruff): add missing Set and Dict imports (F821) (#21785)
* fix(ruff): add missing Set and Dict imports to fix F821 errors

* fix(ci): add semantic_router dep to guardrails_testing job

The test_build_routes_combined_templates test calls build_routes() which
imports from semantic_router, but the guardrails_testing CI job didn't
install it.
2026-02-21 10:56:27 -08:00
Ishaan Jaff
8a145da793
fix(security): fix CVE-2025-69873 and CVE-2026-26996 in docs dependencies (#21782)
* fix(security): fix CVE-2025-69873 and CVE-2026-26996 in docs dependencies

Use npm overrides to pin patched versions:
- ajv@6.12.6 → 6.14.0 (fixes ReDoS CVE-2025-69873)
- ajv@8.17.1 → 8.18.0 (fixes ReDoS CVE-2025-69873)
- minimatch@3.1.2 → 10.2.1 (fixes DoS CVE-2026-26996)

serve-handler only calls minimatch(path, pattern) so the 3.x→10.x
upgrade is safe.

* fix(ruff): add missing Set and Dict imports to fix F821 errors

* fix(security): scope ajv overrides to avoid top-level version conflict

Replacing global 'ajv: 8.18.0' override with scoped 'schema-utils@4'
override. The global override conflicted with the nested file-loader/
null-loader/url-loader overrides, causing npm to install ajv@6 at the
top level where ajv-keywords@5.x requires ajv@8 (ajv/dist/compile/codegen).

Now:
- schema-utils@3 + loaders → ajv@6.14.0 (safe minor bump)
- schema-utils@4 → ajv@8.18.0 (safe minor bump)
- top-level ajv unmodified (stays at 8.x for ajv-keywords@5)
2026-02-21 10:56:11 -08:00
Ishaan Jaff
a5e886de79
fix(tests): read CI_CD_DEFAULT_ANTHROPIC_MODEL env var instead of hardcoding model (#21781)
* fix(tests): read CI_CD_DEFAULT_ANTHROPIC_MODEL env var in bedrock KB tests

* fix(tests): read CI_CD_DEFAULT_ANTHROPIC_MODEL env var in test_router

* fix(tests): read CI_CD_DEFAULT_ANTHROPIC_MODEL env var in test_router_retries

* fix(tests): read CI_CD_DEFAULT_ANTHROPIC_MODEL env var in test_router_timeout
2026-02-21 10:46:49 -08:00
Ishaan Jaff
0726bdb67c
fix(tests): update gcs pubsub v1 fixture with new SpendLogsMetadata fields (#21779)
SpendLogsMetadata added new fields (user_api_key, status, error_information,
etc.) that weren't in the expected spend_logs_payload.json fixture, causing
test_async_gcs_pub_sub_v1 to fail.
2026-02-21 10:40:26 -08:00
shin-bot-litellm
32b09b29fc
feat(ui): add forward_client_headers_to_llm_api toggle to general settings (#21776)
* feat(ui): add forward_client_headers_to_llm_api toggle to general settings

* feat(ui): add forward_client_headers_to_llm_api toggle to UI Settings tab

- Add toggle to UISettings.tsx frontend (switch + label + description)
- Add field to UISettings model and ALLOWED_UI_SETTINGS_FIELDS
- Sync setting to general_settings on get/update so proxy picks it up at runtime

---------

Co-authored-by: shin-bot-litellm <shin-bot-litellm@users.noreply.github.com>
2026-02-21 10:38:40 -08:00
Ishaan Jaff
c5b695e71c
fix(test): skip 'projects' field in team update assertion (#21777) 2026-02-21 10:24:53 -08:00
Ishaan Jaff
afdf70be73
fix(test): update claude model name in test_get_valid_models_from_dynamic_api_key (#21771) 2026-02-21 10:15:23 -08:00
Ishaan Jaff
3840497109
fix: resolve 7 mypy linting errors on main (#21768)
* fix(types): add session_id to LitellmMetadataFromRequestHeaders TypedDict

* fix(mypy): resolve no-redef and typeddict-item errors in competitor intent base

* fix(mypy): add type annotation for words_in_match in airline competitor check

* fix(mypy): suppress typeddict-item error for tracing_kw expansion

* fix(mypy): add type annotations in test_eval.py

* Apply suggestion from @greptile-apps[bot]

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Apply suggestion from @greptile-apps[bot]

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-21 10:05:59 -08:00
Ishaan Jaff
3e67cb5287
fix: resolve flaky test failures in health, spend logs, and CLI tests (#21769)
* fix: reset db_health_cache in source module to prevent stale cache hits

The test was reassigning db_health_cache via `global` in the test module,
which doesn't affect the _health_endpoints module's variable. When a prior
test set the cache to "connected" within 2 minutes, _db_health_readiness_check
returned early without calling health_check(), causing assert_called_once to fail.

Also use PrismaError with a connection message so it's properly recognized
as a connection error by PrismaDBExceptionHandler.is_database_connection_error.

* fix: replace asyncio.sleep with polling loop in spend logs tests

The GLOBAL_LOGGING_WORKER processes callbacks via an async queue, so
asyncio.sleep(1) is a race condition - under CI load the worker may not
have processed the queued task within 1 second. Replace with a polling
helper that waits up to 10 seconds for the mock to be called.

Also add metadata.attempted_retries and metadata.max_retries to
ignored_keys since these are new fields.

* fix: isolate test_skip_server_startup from CI environment

Remove mix_stderr=False (unsupported in some Click versions). Strip
DATABASE_URL/DIRECT_URL from environment during the test to prevent
real prisma operations when these are set in CI.
2026-02-21 10:02:24 -08:00
Ishaan Jaff
061a3cdc3e
Fix ruff PLR0915 lint errors (#21766)
* fix(content_filter): extract helpers to reduce __init__ statement count

Fixes PLR0915 ruff lint error (too many statements).

* fix(test_eval): extract print/save helpers to reduce statement count

Fixes PLR0915 ruff lint error (too many statements).

* fix(proxy/utils): extract lock-timeout logic to reduce statement count

Fixes PLR0915 ruff lint error (too many statements).
2026-02-21 09:48:31 -08:00
Henrique Cavarsan
977ad015ca
fix(proxy): recover from prisma-query-engine zombie process (#21707) 2026-02-21 09:31:44 -08:00
yuneng-jiang
1e452338b9
Merge pull request #21765 from BerriAI/yj_build_fix
[Infra] Building UI for Release
2026-02-21 09:15:09 -08:00
yuneng-jiang
b35869a3ba chore: update Next.js build artifacts (2026-02-21 17:14 UTC, node v22.16.0) 2026-02-21 09:14:05 -08:00
yuneng-jiang
8ebaeb7229 fixing build 2026-02-21 09:13:33 -08:00
yuneng-jiang
425f4e53f1
Merge pull request #21502 from milan-berri/fix/ui-model-credentials-batch-files
fix: resolve credentials for UI-created models in batch file uploads
2026-02-21 09:05:00 -08:00
Harshit Jain
e463fc22d9
Merge pull request #21763 from Harshit28j/litellm_feat_sticky_sessions
feat: add session_id to have better routing
2026-02-21 21:21:52 +05:30
Harshit Jain
f3ff9bf54f
Merge pull request #21009 from BerriAI/litellm_docker-count-no-req
add tests for hotpath & docker container
2026-02-21 20:57:28 +05:30
Harshit Jain
456d8f5524 feat: add session_id to have better routing 2026-02-21 18:45:50 +05:30
github-actions[bot]
e487d711d6
chore: regenerate poetry.lock to match pyproject.toml (#21758)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-21 11:26:55 +00:00
Harshit Jain
1df9bd96c7
Merge pull request #21743 from Harshit28j/litellm_rollback_safety_checks
doc: add rollback safety check
2026-02-21 13:13:43 +05:30
kang hee yong
03ecdf9284
feat(openrouter): add openrouter/minimax/minimax-m2.5 pricing (#21664) 2026-02-20 22:24:58 -08:00
yuneng-jiang
1fb7320b6d
Merge pull request #21745 from BerriAI/litellm_org_member_email_ui
[Feature] UI - Organization Info: Show member email, AntD tabs, reusable MemberTable
2026-02-20 21:49:27 -08:00
yuneng-jiang
ffc673da09 fix: use include user:True instead of nested select for Prisma Python compat
Prisma Python client does not support nested select within include.
Use include user:True to fetch the full user object; model_validator
extracts user_email from it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 21:41:53 -08:00
yuneng-jiang
4597d34344 feat: org info page - AntD tabs, MemberTable with user_email
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 21:41:53 -08:00