AI Features
AI transform fallback, content cleanup, and schema generation powered by a capability-first model registry.
Capability-first model registry
The AI service uses a capability-first model registry — each AI job is matched to the model best suited for it, with primary + fallback chains:
| Capability | Primary | Fallbacks | Used by |
|---|---|---|---|
chat | glm-5.2 | glm-5.1, claude-haiku-4-5 | Onboarding chat (future) |
classify | qwen2.5:7b (local) | glm-5.2 | Site analysis complexity |
generate | deepseek-v4-pro | glm-5.2, claude-haiku-4-5 | Meta descriptions |
json | deepseek-v4-pro | glm-5.2, gpt-4o-mini | Quotes, transforms, schema |
vision | claude-haiku-4-5 | gpt-4o-mini, gemini-2.5-flash | Alt text generation |
code | deepseek-v4-pro | claude-sonnet-4-6, gpt-4o | Schema generation |
long_context | gemini-2.5-pro | claude-sonnet-4-6, gpt-4o | Large site analysis |
Why glm-5.2 is excluded from vision: glm-5.2 doesn't handle images well. The vision capability deliberately routes to Claude Haiku / GPT-4o-mini / Gemini Flash instead — matching models to jobs.
AI Transform Fallback
When the deterministic page-builder parser returns confidence below 0.7, the Worker calls the AI service /api/transform route:
- The raw builder block (Elementor JSON, WPBakery shortcodes, etc.) is sent with the asset map and target schema.
- The
jsoncapability produces a Portable Text blocks array, validated against a Zod schema. - On validation failure, the router auto-retries with a stricter prompt.
- If every model fails, a deterministic fallback wraps the raw block in a
wpBlock(flaggedaiFallback: true) so no content is lost.
Results are cached for 24 hours by content hash.
AI Content Cleanup
The /api/cleanup route handles three cleanup types:
Alt text generation
Filters documents with empty mainImage.alt, sends the image URL + page title to the vision capability, and generates concise alt text (max 125 chars). Returns patches that the Worker applies via patchDocument.
Meta descriptions
Filters documents with empty seo.metaDescription, sends the title to the generate capability, and produces a 155-char SEO meta description.
Slug cleanup
Non-ASCII or invalid slugs are transliterated deterministically (NFKD normalization + combining-mark stripping + a Latin transliteration map). No model call needed — this runs for free.
Trigger cleanup via the dashboard or the Worker /v2/cleanup route.
AI Schema Generation
The /api/schema-generate route proposes a complete Sanity Studio schema from your site analysis:
- The
codecapability (deepseek-v4 → claude-sonnet → gpt-4o) receives your post types, ACF field groups, taxonomies, and builder distribution. - It returns an array of TypeScript files (one per document type + a
blocks.tsfor object types), each validated to containdefineType/defineField. - If every model is unavailable, a deterministic scaffold is generated from the raw counts.
Preview, copy, or download the schema from Altered Digital → Schema Preview.
Cost & budget enforcement
Each AI call has a tier (local or cloud). Cloud calls bill against your tenant's AI budget (set when you pay upfront). When the budget is exhausted, the router downshifts to local-only models; if no local model applies, the route uses its deterministic fallback.
You can monitor AI spend in your Altered Digital dashboard.