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: AbstractSAMMetadataBase

Smarter API Proxy Manifest - Metadata class.

class_identifier: ClassVar[str] = 'Proxy.metadata'
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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

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: ProxyBaseModel

Smarter API Proxy Manifest Proxy.spec.

allowedPaths: list[str]
apiKey: str | None
auth: SAMProxySpecAuth
baseUrl: str | None
class_identifier: ClassVar[str] = 'Proxy.spec'
headers: dict[str, str]
isActive: bool
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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

provider: str
timeout: int
classmethod validate_allowed_paths(v)[source]

Normalize allowedPaths, stripping whitespace and slashes, and reject invalid patterns.

Parameters:

v (list[str]) – The glob patterns.

Return type:

list[str]

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:

str | None

Returns:

The stripped name, or None.

Raises:

SAMValidationError – when it is not a valid Secret name.

classmethod validate_base_url(v)[source]

Check that baseUrl is a plain http(s) URL, and give it a trailing slash.

Parameters:

v (str | None) – The URL, or None.

Return type:

str | None

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.

Parameters:

v (dict[str, str]) – The headers, by name.

Return type:

dict[str, str]

Returns:

The headers, with stripped names.

Raises:

SAMValidationError – when a name is invalid or reserved, or a value has a line break.

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:

str

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: ProxyBaseModel

Spec.auth: how the provider expects its API key.

class_identifier: ClassVar[str] = 'Proxy.spec.auth'
header: str
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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

scheme: str | None
classmethod validate_header(v)[source]

Check that auth.header is a header name that can carry an API key.

Hop-by-hop headers, Host, Content-Length, Content-Type and Cookie cannot.

Parameters:

v (str) – The header name.

Return type:

str

Returns:

The stripped header name.

Raises:

SAMValidationError – when it is not a valid header name, or cannot carry an API key.

classmethod validate_scheme(v)[source]

Normalize auth.scheme to a single word, or an empty string for none.

Parameters:

v (str | None) – The scheme, e.g. Bearer, or None.

Return type:

str

Returns:

The stripped scheme, or an empty string.

Raises:

SAMValidationError – when it is not a single word.

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: AbstractSAMStatusBase

Smarter API Proxy Manifest - Status class.

Read only. Besides ownership, it reports where the Proxy is, and where it forwards to.

accountNumber: str
apiKeySecret: str | None
class_identifier: ClassVar[str] = 'Proxy.status'
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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

upstreamUrl: str | None
url: str | None
username: str

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: AbstractSAMBase

Smarter API Manifest - Proxy.

class_identifier: ClassVar[str] = '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.

Parameters:
  • self (BaseModel) – The BaseModel instance.

  • context (Any) – The context.

Return type:

None

spec: SAMProxySpec
status: SAMProxyStatus | None