Skip to content

AI Settings

Methods for managing per-user AI provider settings (/api/ai-settings).

API keys are stored as encrypted blobs — the caller encrypts with AES-256-GCM before sending; the Clann server never sees the plaintext key.

pyclann.client.AiSettingsClient

AiSettingsClient(http: _HttpSession)

Methods for user AI settings (/api/ai-settings).

get

get() -> UserAiSettings

Fetch AI settings for the authenticated user.

Returns:

Type Description
UserAiSettings

class:~pyclann.models.UserAiSettings.

Raises:

Type Description
ClannNotFoundError

If no settings have been configured.

ClannAuthError

If not authenticated.

upsert

upsert(provider: str, model: str, *, ollama_url: str | None = None, encrypted_key: str | None = None, iv: str | None = None, auth_tag: str | None = None) -> UserAiSettings

Create or replace AI settings for the authenticated user.

API keys must be encrypted by the caller (AES-256-GCM) before being sent. The server stores only the opaque encrypted blob.

Parameters:

Name Type Description Default
provider str

AI provider name, e.g. "openai", "anthropic", "ollama".

required
model str

Model identifier, e.g. "gpt-4o", "claude-3-5-sonnet".

required
ollama_url str | None

Base URL for Ollama, e.g. "http://localhost:11434".

None
encrypted_key str | None

AES-256-GCM encrypted API key (base64).

None
iv str | None

Initialisation vector (base64).

None
auth_tag str | None

GCM authentication tag (base64).

None

Returns:

Type Description
UserAiSettings

The upserted :class:~pyclann.models.UserAiSettings.

Raises:

Type Description
ClannAuthError

If not authenticated.

delete

delete() -> None

Delete AI settings for the authenticated user.

Raises:

Type Description
ClannNotFoundError

If no settings exist.

ClannAuthError

If not authenticated.