AI 0.22.0: Daily spend caps, a request cache and structured JSON output
AI 0.22.0 lets a site cap what it spends on AI each day, answer repeated requests from a cache without paying again, and ask models for JSON that comes back already parsed.
Daily spend caps
Three settings cap spending over the last 24 hours: ai_daily_budget for every call, ai_daily_budget_per_endpoint for each endpoint and ai_daily_budget_per_user for each user a call names with user_uuid:. Amounts are in millionths of a dollar (1000000 is $1), and 0 means no cap. Once a cap is reached, every call is refused, cached answers included, with a message such as “The AI budget for the last 24 hours has been used up”. At 80 percent by default (ai_budget_warn_percent) a warning is logged and a telemetry event fires, once per crossing.
A request cache
Any call can pass cache: true (or a TTL, a key of its own, or :refresh) to reuse an earlier identical answer. A cached answer calls no provider and still writes a usage row, at zero cost and marked as cached. The cache is set up with config :phoenix_kit_ai, request_cache: [...]. Answers are shared between users, so give a personal answer a key of its own.
JSON and text extraction
ask/3, complete/3 and describe_image/3 accept schema: or json: true and return the parsed JSON. A model that refuses the JSON format setting gets one retry without it. The new extract_text/3 reads text from images with a vision model and returns typed blocks, the language, a legibility score and any fields you name.
Smaller changes
Host apps can add their own content to AI translation with config :phoenix_kit_ai, translatables: [...]. Every usage row records user_uuid:, and a telemetry event fires for each row. A paid vision call whose answer is prose instead of the requested JSON now keeps its cost in the usage log. A usage row that fails to insert logs a warning instead of vanishing.
Upgrading
No migration. The caps are off until you set them, and the cache is off unless a call asks for it or the config sets default: true.
Full release notes: AI 0.22.0
0.22.0 · 14 September 2026
Added
- Spend caps (PR #26).
PhoenixKitAI.Budgetenforces daily caps over the trailing 24 hours, globally, per endpoint and peruser_uuid:, set as nanodollar settings (ai_daily_budget,ai_daily_budget_per_endpoint,ai_daily_budget_per_user;0= no cap). Every provider-calling verb returns{:error, {:budget_exceeded, scope}}once a cap is reached, cached answers included. A[:phoenix_kit_ai, :budget, :warning]event and a log line fire once per crossing ofai_budget_warn_percent(default 80).Budget.status/2reads spend without side effects. - Request cache.
PhoenixKitAI.RequestCache(ETS, supervised bychildren/0):cache: true | [ttl:, key:, refresh:] | :refreshon every verb, configured throughconfig :phoenix_kit_ai, request_cache: [...]. A hit calls no provider and writes a zero-cost usage row markedcached: true, keeping the attribution and prompt link. - Structured output.
schema:/json: trueonask/3,complete/3anddescribe_image/3return the parsed JSON under"json"/:json. A model that rejectsresponse_formatgets one retry without it. extract_text/3: OCR by vision model, with typed blocks, the language, a legibility score,has_illegible_textand caller-namedfields:.- Host apps join the AI-translation pipeline via
config :phoenix_kit_ai, translatables: [{type, module}]. - A
[:phoenix_kit_ai, :request]telemetry event fires per usage row. user_uuid:is recorded on every verb’s usage row.- Saved-prompt rows carry
metadata.prompt_snapshot.hash. get_usage_stats/1acceptsuntil:.- Guide:
dev_docs/guides/spend-caps-and-caching.md.
Fixed
dry_run:no longer lifts the spend cap on verbs that ignore it. Onlyprocess_image/4honoursdry_run:. Any other verb given the option skipped the cap and still called the provider.- A prose answer to a JSON vision request keeps its cost. It covers
describe_image/3,extract_text/3andcompare_images/4. The paid call used to leave only a zero-cost error row, invisible to the spend caps. It now writes its normal success row, usage included, and the verb still returns{:error, {:no_json_in_response, text}}.Images.describe/3takes an:on_no_jsoncallback for this. - A caller cache key (
cache: [key: …]) onextract_text/3now includesfields:. A different field set no longer gets another set’s stored answer. - A usage row that fails to insert, such as one with an unknown
user_uuid:, is logged as a warning instead of vanishing. - The reorder audit rows name the first id that exists, not the first one given.
AI 0.22.0. Install or update: {:phoenix_kit_ai, "~> 0.22"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.