api.services.ai.settings¶
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¶
Classes¶
How the chains react to rate limits (HTTP 429). |
|
An "AI model": a provider model with its own directives and limits. |
|
Functions¶
|
|
|
Settings saved before AI models existed ({feature: {model, ...}}) |
|
Estimated cost at list prices; price (USD per million tokens, input and |
Module Contents¶
- api.services.ai.settings.Provider¶
- api.services.ai.settings.Capability¶
- api.services.ai.settings.ANTHROPIC_PRICES: dict[str, tuple[float, float, float]]¶
- api.services.ai.settings.CACHE_WRITE_FACTOR = 1.25¶
- api.services.ai.settings.WEB_SEARCH_USD = 0.01¶
- api.services.ai.settings.FEATURE_LABELS¶
- api.services.ai.settings.FEATURE_REQUIREMENTS: dict[str, set[str]]¶
- class api.services.ai.settings.ProviderSettings¶
Bases:
pydantic.BaseModel- enabled: bool = True¶
- daily_limit: int | None¶
- monthly_budget_usd: float | None¶
- class api.services.ai.settings.GeneralSettings¶
Bases:
pydantic.BaseModelHow the chains react to rate limits (HTTP 429).
- rate_limit_retries: int¶
- retry_after_seconds: int¶
- max_wait_seconds: int¶
- class api.services.ai.settings.ModelProfile¶
Bases:
pydantic.BaseModelAn “AI model”: a provider model with its own directives and limits.
- id: str¶
- label: str¶
- model: str¶
- enabled: bool = True¶
- directives: str¶
- effort: Literal['low', 'medium', 'high'] | None = None¶
- max_output_tokens: int | None¶
- daily_limit: int | None¶
- monthly_budget_usd: float | None¶
- retry_after_seconds: int | None¶
- input_price: float | None¶
- output_price: float | None¶
- images: bool = True¶
- web: bool = False¶
- json_output: bool = True¶
- property free: bool¶
- capabilities() set[str]¶
- class api.services.ai.settings.FeatureSettings¶
Bases:
pydantic.BaseModel- enabled: bool = True¶
- chain: list[str]¶
- daily_limit: int | None¶
- use_images: bool = False¶
- max_images: int¶
- suggestions: int¶
- ocr_fallback: bool = True¶
- api.services.ai.settings.default_models() list[ModelProfile]¶
- class api.services.ai.settings.AISettings¶
Bases:
pydantic.BaseModel- version: int = 3¶
- general: GeneralSettings¶
- providers: dict[Provider, ProviderSettings]¶
- models: list[ModelProfile]¶
- product_research: FeatureSettings¶
- reference_suggestion: FeatureSettings¶
- description_writing: FeatureSettings¶
- document_search: FeatureSettings¶
- pdf_extraction: FeatureSettings¶
- monthly_budget_usd: float | None¶
- feature(name: str) FeatureSettings¶
- profile(profile_id: str) ModelProfile | None¶
- api.services.ai.settings.LIMIT_KEYS = ('daily_limit', 'monthly_budget_usd')¶
- api.services.ai.settings.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.
- api.services.ai.settings.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.