Operations
Logging and Usage
How to record AI calls by user, city, and model.
Downcity does not decide where your logs live, but hooks give you one consistent integration point.
Recommended fields
- user_id
- city_id
- model
- started_at
- ended_at
- status
- error
Where to record
ai.hook.after(async (ctx) => {
await logService.write({
user_id: ctx.user?.user_id,
city_id: ctx.city?.city_id,
model: ctx.variant?.id,
model_meta: ctx.variant?.meta,
started_at: ctx.started_at,
ended_at: ctx.ended_at,
});
});Once many products share one runtime, usage data becomes centralized by default, which makes cost analysis and business decisions much easier later.