api.services.ai.settings ======================== .. py:module:: api.services.ai.settings .. autoapi-nested-parse:: AI settings (edited from the app): providers, AI models (profiles) and, per feature, the ordered chain of AI models tried until one succeeds. API keys never live here: they come from the environment (ANTHROPIC_API_KEY, OPENROUTER_API_KEY). Attributes ---------- .. autoapisummary:: api.services.ai.settings.Provider api.services.ai.settings.PROVIDERS api.services.ai.settings.Capability api.services.ai.settings.ANTHROPIC_PRICES api.services.ai.settings.CACHE_WRITE_FACTOR api.services.ai.settings.WEB_SEARCH_USD api.services.ai.settings.FEATURE_LABELS api.services.ai.settings.FEATURE_REQUIREMENTS api.services.ai.settings.LIMIT_KEYS Classes ------- .. autoapisummary:: api.services.ai.settings.ProviderSettings api.services.ai.settings.GeneralSettings api.services.ai.settings.ModelProfile api.services.ai.settings.FeatureSettings api.services.ai.settings.AISettings Functions --------- .. autoapisummary:: api.services.ai.settings.default_models api.services.ai.settings.migrate api.services.ai.settings.anthropic_cost Module Contents --------------- .. py:data:: Provider .. py:data:: PROVIDERS :type: tuple[Provider, ...] :value: ('anthropic', 'openrouter') .. py:data:: Capability .. py:data:: ANTHROPIC_PRICES :type: dict[str, tuple[float, float, float]] .. py:data:: CACHE_WRITE_FACTOR :value: 1.25 .. py:data:: WEB_SEARCH_USD :value: 0.01 .. py:data:: FEATURE_LABELS .. py:data:: FEATURE_REQUIREMENTS :type: dict[str, set[str]] .. py:class:: ProviderSettings Bases: :py:obj:`pydantic.BaseModel` .. py:attribute:: enabled :type: bool :value: True .. py:attribute:: daily_limit :type: int | None .. py:attribute:: monthly_budget_usd :type: float | None .. py:class:: GeneralSettings Bases: :py:obj:`pydantic.BaseModel` How the chains react to rate limits (HTTP 429). .. py:attribute:: rate_limit_retries :type: int .. py:attribute:: retry_after_seconds :type: int .. py:attribute:: max_wait_seconds :type: int .. py:class:: ModelProfile Bases: :py:obj:`pydantic.BaseModel` An "AI model": a provider model with its own directives and limits. .. py:attribute:: id :type: str .. py:attribute:: label :type: str .. py:attribute:: provider :type: Provider .. py:attribute:: model :type: str .. py:attribute:: enabled :type: bool :value: True .. py:attribute:: directives :type: str .. py:attribute:: effort :type: Literal['low', 'medium', 'high'] | None :value: None .. py:attribute:: max_output_tokens :type: int | None .. py:attribute:: daily_limit :type: int | None .. py:attribute:: monthly_budget_usd :type: float | None .. py:attribute:: retry_after_seconds :type: int | None .. py:attribute:: input_price :type: float | None .. py:attribute:: output_price :type: float | None .. py:attribute:: images :type: bool :value: True .. py:attribute:: web :type: bool :value: False .. py:attribute:: json_output :type: bool :value: True .. py:property:: free :type: bool .. py:method:: capabilities() -> set[str] .. py:class:: FeatureSettings Bases: :py:obj:`pydantic.BaseModel` .. py:attribute:: enabled :type: bool :value: True .. py:attribute:: chain :type: list[str] .. py:attribute:: daily_limit :type: int | None .. py:attribute:: use_images :type: bool :value: False .. py:attribute:: max_images :type: int .. py:attribute:: suggestions :type: int .. py:attribute:: ocr_fallback :type: bool :value: True .. py:function:: default_models() -> list[ModelProfile] .. py:class:: AISettings Bases: :py:obj:`pydantic.BaseModel` .. py:attribute:: version :type: int :value: 3 .. py:attribute:: general :type: GeneralSettings .. py:attribute:: providers :type: dict[Provider, ProviderSettings] .. py:attribute:: models :type: list[ModelProfile] .. py:attribute:: product_research :type: FeatureSettings .. py:attribute:: reference_suggestion :type: FeatureSettings .. py:attribute:: description_writing :type: FeatureSettings .. py:attribute:: document_search :type: FeatureSettings .. py:attribute:: pdf_extraction :type: FeatureSettings .. py:attribute:: monthly_budget_usd :type: float | None .. py:method:: feature(name: str) -> FeatureSettings .. py:method:: profile(profile_id: str) -> ModelProfile | None .. py:data:: LIMIT_KEYS :value: ('daily_limit', 'monthly_budget_usd') .. py:function:: migrate(stored: dict[str, Any]) -> AISettings Settings saved before AI models existed ({feature: {model, ...}}) keep their switches, limits and budget; the chosen Claude model goes first. .. py:function:: anthropic_cost(model: str, *, input_tokens: int, output_tokens: int, cache_read_tokens: int, cache_write_tokens: int, web_searches: int, price: tuple[float | None, float | None] = (None, None)) -> float Estimated cost at list prices; `price` (USD per million tokens, input and output) overrides them, cache reads keeping their ratio. Free (0, 0) = 0.