Skip to content

fix(providers): reject provider names containing '/' - #1409

Closed
caideyi wants to merge 3 commits into
TencentCloud:mainfrom
caideyi:main
Closed

caideyi wants to merge 3 commits into
TencentCloud:mainfrom
caideyi:main

Conversation

@caideyi

@caideyi caideyi commented Oct 1, 2026

Copy link
Copy Markdown

Problem

A custom provider can be saved with a URL as its name (e.g. https://api.openai.com/), but every subsequent model operation on that provider fails — e.g. "Set as preferred model" returns 400:

  {"error": {"code": "SLASH_BAD_ARGS", "message": "Invalid arguments."}}

Root cause

Model refs have the form <provider_name>/<model_id> and are parsed with str.partition("/") (infra/agents/providers/store.py). When the provider name itself contains /, the split is wrong, the provider lookup always
misses, is_model_ref_usable() returns False, and the request is rejected with 400.

None of the three creation entry points (admin API, setup wizard, CLI) validated the name, so such names could be persisted.

Fix

  • Add infra/agents/providers/names.py: validate_provider_name() — rejects empty names and names containing /, strips surrounding whitespace
  • Add error code PROVIDER_NAME_INVALID (HTTP 400) with zh/en i18n messages (the zh message points users to the Base URL field)
  • Enforce validation at all three creation entry points: api/routers/providers.py, api/routers/setup.py, cli/support/offline_ops.py
  • Existing providers with / in their names are untouched (only new creations are blocked); users can delete and recreate them

Tests

  • New unit tests tests/unit/providers/test_provider_names.py: valid name, whitespace trimming, / rejection, empty rejection (7 cases)
  • New integration tests test_admin_create_rejects_slash_in_name / test_admin_create_rejects_empty_name: assert 400 + error code + nothing persisted

@caideyi caideyi closed this Oct 2, 2026
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