feat(providers): declare supported APIs for custom connections

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-10 01:33:02 +08:00
1 parent 73a27e0726
commit 34fd4ed75a
29 files changed
+799 -108

No files matched your search

+16 -3
View File
@@ -82,14 +82,14 @@ class DreamConfig(Base):
return f"every {hours}h"
class ModelAPIConfig(Base):
"""Allowed request APIs and preference for a model preset's endpoint."""
class ProviderAPIConfig(Base):
"""Request APIs accepted by a custom endpoint and its default API."""
supported_apis: tuple[RequestAPI, ...] = Field(min_length=1)
preferred_api: RequestAPI | None = None
@model_validator(mode="after")
def _validate_preference(self) -> "ModelAPIConfig":
def _validate_preference(self) -> "ProviderAPIConfig":
if self.preferred_api is not None and self.preferred_api not in self.supported_apis:
raise ValueError("preferred_api must be one of supported_apis")
return self
@@ -101,6 +101,18 @@ class ModelAPIConfig(Base):
)
class ModelAPIConfig(ProviderAPIConfig):
"""Allowed request APIs and preference for a model preset's endpoint."""
@model_validator(mode="after")
def _validate_api_family(self) -> "ModelAPIConfig":
if "anthropic_messages" in self.supported_apis and set(self.supported_apis) != {
"anthropic_messages",
}:
raise ValueError("anthropic_messages cannot be combined with OpenAI request APIs")
return self
class InlineFallbackConfig(Base):
"""One inline fallback model configuration."""
@@ -224,6 +236,7 @@ class ProviderConfig(Base):
)
api_key: str | None = Field(default=None, repr=False)
api_base: str | None = None
api: ProviderAPIConfig | None = Field(default=None, exclude_if=lambda value: value is None)
api_type: Literal["auto", "chat_completions", "responses"] = "auto" # Request API surface
extra_headers: dict[str, str] | None = None # Custom headers (e.g. APP-Code for AiHubMix)
extra_body: dict[str, Any] | None = None # Extra provider request fields; shape depends on provider/API surface