Skip to content

feat: configurable API endpoints via {PROVIDER}_BASE_URL convention#6

Merged
Star-Lotus merged 1 commit intomainfrom
feature/configurable-endpoints
Mar 10, 2026
Merged

feat: configurable API endpoints via {PROVIDER}_BASE_URL convention#6
Star-Lotus merged 1 commit intomainfrom
feature/configurable-endpoints

Conversation

@Star-Lotus
Copy link
Collaborator

Summary

  • Add unified endpoint registry (src/utils/endpoints.py) with get_provider_base_url() utility and PROVIDER_DEFAULTS dict
  • Replace all hardcoded API URLs in 6 model adapters (DashScope, Kling, Vidu) with env-var-driven lookups
  • Add "Advanced: API Endpoints" collapsible section in EnvConfigDialog for UI-based endpoint configuration
  • Convention: {PROVIDER}_BASE_URL env var overrides default, empty string falls back to default

Motivated by PR #4's idea of endpoint configurability, but implemented with a convention-over-configuration approach. New provider onboarding = 3 lines of code (one in PROVIDER_DEFAULTS, one in model class, one in frontend registry).

Changes

Backend:

  • New src/utils/endpoints.py — provider registry + get_provider_base_url() with trailing-slash stripping and empty-string fallback
  • wanx.py, image.py, qwen_vl.py, llm_adapter.py, kling.py, vidu.py — replaced hardcoded URLs
  • api.pyEnvConfig.endpoint_overrides dict with allowlist validation, remove_user_config_keys() for proper override clearing, deduplicated GET route

Frontend:

  • EnvConfigDialog.tsxENDPOINT_PROVIDERS registry, collapsible endpoint section, safe ?? {} fallback
  • api.ts — updated saveEnvConfig type signature

Tests & Config:

  • 28 new vitest tests covering validation, state transforms, data normalization, and registry structure
  • .env.example documents {PROVIDER}_BASE_URL convention with international endpoint examples

Test plan

  • No env vars set → all providers use default URLs (backward compatible)
  • DASHSCOPE_BASE_URL=https://test.example.com → requests go to new endpoint
  • Empty string override → falls back to default
  • Trailing slash in URL → stripped automatically
  • EnvConfigDialog loads/saves endpoint overrides correctly
  • Unknown keys in endpoint_overrides rejected (allowlist validation)
  • Override removal persisted to config file (.env / JSON)
  • 56 frontend tests passing (28 endpoint + 28 video-params)
  • All Python module imports verified
  • TypeScript compilation: zero errors in changed files

Add a unified endpoint registry (src/utils/endpoints.py) with
get_provider_base_url() utility. All hardcoded API URLs in model
adapters (DashScope, Kling, Vidu) now read from environment variables,
enabling international deployment with a single env var change.

Backend:
- New src/utils/endpoints.py with PROVIDER_DEFAULTS + helper
- Replace hardcoded URLs in wanx.py, image.py, qwen_vl.py,
  llm_adapter.py, kling.py, vidu.py
- EnvConfig gains endpoint_overrides dict with allowlist validation
- GET/POST /config/env handle endpoint collection and persistence
- Add remove_user_config_keys() for proper override clearing

Frontend:
- ENDPOINT_PROVIDERS registry in EnvConfigDialog.tsx
- Collapsible "Advanced: API Endpoints" section with .map() rendering
- Safe endpoint_overrides loading with ?? {} fallback
- Update api.ts saveEnvConfig type for nested Record
- 28 new vitest tests covering all extracted logic

Config:
- .env.example documents {PROVIDER}_BASE_URL convention
- vitest added as devDependency
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Star-Lotus Star-Lotus merged commit b683f41 into main Mar 10, 2026
3 of 4 checks passed
@Star-Lotus Star-Lotus deleted the feature/configurable-endpoints branch March 10, 2026 17:04
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.

3 participants