Pydantic Models
Smarter API Proxy Manifest Constants.
Smarter API Manifest - Proxy.metadata.
- class smarter.apps.proxy.manifest.models.proxy.metadata.SAMProxyMetadata(*, name: str, description: str | None, version: str | None, tags: List[str] | None = <factory>, annotations: dict[str, str] | None=<factory>)[source]
Bases:
AbstractSAMMetadataBaseSmarter API Proxy Manifest - Metadata class.
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
Smarter API Manifest - Proxy.spec.
A Proxy forwards requests, as they are, to an LLM provider’s native API, and adds the provider’s API key, which Smarter keeps in a Secret. Callers authenticate with a Smarter API key instead, and so never see the provider’s.
spec:
provider: anthropic # the name of a Provider
apiKey: anthropic_api_key # the name of a Secret. Optional: defaults to the Provider's.
baseUrl: https://api.anthropic.com/v1/ # Optional: defaults to the Provider's.
auth:
header: x-api-key # where the provider expects its API key
scheme: "" # its prefix, e.g. Bearer. Empty for none.
headers:
anthropic-version: "2023-06-01" # added to every request
allowedPaths: # glob patterns. Empty allows every path.
- messages
- messages/count_tokens
- models
- models/*
timeout: 120 # seconds
isActive: true
A request to /api/v1/proxy/<name>/messages is forwarded to
https://api.anthropic.com/v1/messages.
- class smarter.apps.proxy.manifest.models.proxy.spec.SAMProxySpec(*, provider: str, apiKey: str | None = None, baseUrl: str | None = None, auth: SAMProxySpecAuth = <factory>, headers: dict[str, str]=<factory>, allowedPaths: list[str] = <factory>, timeout: Annotated[int, ~annotated_types.Ge(ge=1), ~annotated_types.Le(le=600)] = 120, isActive: bool = True)[source]
Bases:
ProxyBaseModelSmarter API Proxy Manifest Proxy.spec.
- auth: SAMProxySpecAuth
- model_config = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- classmethod validate_allowed_paths(v)[source]
Normalize
allowedPaths, stripping whitespace and slashes, and reject invalid patterns.- Parameters:
- Return type:
- Returns:
The normalized patterns.
- Raises:
SAMValidationError – when a pattern is empty, has invalid characters, contains
://, or has an empty,.or..segment.
- classmethod validate_api_key(v)[source]
Strip
apiKey, and check that it is a Secret’s name rather than a key.- Parameters:
v (
str|None) – The Secret’s name, or None for the Provider’s API key.- Return type:
- Returns:
The stripped name, or None.
- Raises:
SAMValidationError – when it is not a valid Secret name.
- classmethod validate_base_url(v)[source]
Check that
baseUrlis a plain http(s) URL, and give it a trailing slash.- Parameters:
- Return type:
- Returns:
The URL with a trailing slash, or None when it is None or blank.
- Raises:
SAMValidationError – when it is not http(s), has no host, or contains credentials, a query or a fragment.
- classmethod validate_headers(v)[source]
Check the names and values of
headers, and reject reserved names.
- classmethod validate_provider(v)[source]
Strip
provider, and check that it is a valid Provider name.- Parameters:
v (
str) – The Provider’s name.- Return type:
- Returns:
The stripped name.
- Raises:
SAMValidationError – when it is not a valid name.
- class smarter.apps.proxy.manifest.models.proxy.spec.SAMProxySpecAuth(*, header: str = 'Authorization', scheme: str | None = 'Bearer')[source]
Bases:
ProxyBaseModelSpec.auth: how the provider expects its API key.
- model_config = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- classmethod validate_header(v)[source]
Check that
auth.headeris a header name that can carry an API key.Hop-by-hop headers,
Host,Content-Length,Content-TypeandCookiecannot.- Parameters:
v (
str) – The header name.- Return type:
- Returns:
The stripped header name.
- Raises:
SAMValidationError – when it is not a valid header name, or cannot carry an API key.
Smarter API Manifest - Proxy.status.
- class smarter.apps.proxy.manifest.models.proxy.status.SAMProxyStatus(*, recordLocator: str, created: datetime, modified: datetime, dependencies: List[SAMDependency] | None = None, accountNumber: str, username: str, url: str | None = None, upstreamUrl: str | None = None, apiKeySecret: str | None = None)[source]
Bases:
AbstractSAMStatusBaseSmarter API Proxy Manifest - Status class.
Read only. Besides ownership, it reports where the Proxy is, and where it forwards to.
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
Smarter API Proxy Manifest.
- class smarter.apps.proxy.manifest.models.proxy.model.SAMProxy(*, apiVersion: str, kind: str, metadata: SAMProxyMetadata, spec: SAMProxySpec, status: SAMProxyStatus | None = None)[source]
Bases:
AbstractSAMBaseSmarter API Manifest - Proxy.
- metadata: SAMProxyMetadata
- model_config = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- spec: SAMProxySpec
- status: SAMProxyStatus | None