Skip to content

Schema: ai

The ai schema manages the AI model registry, provider catalog, pricing, and feature routing. Models are referenced by evaluations (as AI contenders and scorers) and by the AI chat/generation features.

Tables

providers

Registry of AI model providers (OpenAI, Anthropic, Google, etc.).

ColumnTypeNotes
iduuid (PK)
keytext (UNIQUE)Machine-readable provider key (e.g., anthropic)
nametextDisplay name
api_urltextBase API endpoint
created_attimestamptz

models

Registry of available AI models.

ColumnTypeNotes
iduuid (PK)
keytext (UNIQUE)Unique model identifier (e.g., claude-3-7-sonnet)
nametextDisplay name
provider_iduuid NOT NULLFK → ai.providers(id). Use this for all new code.
providerai.provider_enumDEPRECATED — use provider_id join to ai.providers. Will be dropped once all callers migrate.
versiontextModel version string
provider_urltextLink to provider documentation
descriptiontextModel description
capabilitiesai_capability_enum[]Array of text_generation, image_generation, video_generation, audio_generation
temperaturenumericDefault temperature setting
max_tokensintegerMaximum token output
pricing_tierai.model_tier_enumfree, paid, enterprise. NULL = no tier restriction.
is_publicbooleanWhether visible to all users
is_activebooleanWhether the model is currently enabled
created_attimestamptz

model_pricing

Per-unit pricing for AI models.

ColumnTypeNotes
iduuid (PK)
model_iduuidFK → ai.models(id)
unit_typeai.unit_type_enumtokens, image, video_second, audio_second. Default tokens.
price_per_unitnumericCost per billing unit
currencytextCurrency code (e.g., USD)
effective_fromtimestamptzPricing valid from this date
created_attimestamptz

features

Registry of AI feature keys. Used to enforce referential integrity on feature_model_policies.feature_key.

ColumnTypeNotes
keytext (PK)Machine-readable feature key (e.g., image_generation, summarization)
descriptiontextHuman-readable description
is_activebooleanWhether this feature is currently enabled

feature_model_policies

Routing rules that determine which AI model handles a given feature.

ColumnTypeNotes
iduuid (PK)
feature_keytextFK → ai.features(key) ON UPDATE CASCADE ON DELETE RESTRICT
model_iduuidFK → ai.models(id)
priorityintegerLower = higher priority
is_activeboolean
created_attimestamptz

Unique constraint: (feature_key, model_id)

generations

Log of AI generation requests and results.

ColumnTypeNotes
iduuid (PK)
lenser_iduuidFK → lensers.profiles
model_iduuidFK → models
media_iduuidFK → content.media_library (ownership enforced by trigger)
prompttextInput prompt
outputtextGenerated output
token_countintegerTokens used
created_attimestamptz

resources

Deprecated: ai.resources is superseded by media.objects. New code should use the media schema. See Media Schema.

Moved tables

billing.execution_margin_policies (previously ai.execution_margin_policies)

Execution margin policies were relocated to the billing schema for cohesion (migration 20260440000009). The billing.calculate_credit_cost() function reads from billing.execution_margin_policies. Cross-schema FK to ai.models(id) is documented.

Triggers

  • ai_generations_media_owner_enforce — Ensures media_id owner matches lenser_id before insert/update.

Evaluation integration

AI models participate in evaluations as contenders and score submissions as judges. See the execution schema for details on how models are referenced during runs.

RLS

  • ai_models_read_all — All users (including anonymous) can read model metadata.
  • Generation write policies — Only the owning lenser can create/delete their generations.

Enums

EnumValues
ai.provider_enumopenai, anthropic, google, meta, midjourney, stability, mistral, other
ai.ai_capability_enumtext_generation, image_generation, video_generation, audio_generation
ai.model_tier_enumfree, paid, enterprise. Relocated from public.pricing_tier_enum (deprecated).
ai.unit_type_enumtokens, image, video_second, audio_second

public.pricing_tier_enum is DEPRECATED — use ai.model_tier_enum. Retained only for backward compatibility with external tools.