上线与运维

日志与 usage

如何按用户、产品和模型记录 AI 调用。

Downcity 不决定日志存哪里,但 hook 会给你统一入口。

推荐字段

  • user_id
  • town_id
  • model
  • started_at
  • ended_at
  • status
  • error

记录位置

ai.hook.after(async (ctx) => {
  await logService.write({
    user_id: ctx.user?.user_id,
    town_id: ctx.town?.town_id,
    model: ctx.variant?.id,
    model_meta: ctx.variant?.meta,
    started_at: ctx.started_at,
    ended_at: ctx.ended_at,
  });
});

多产品共用同一套 runtime 后,usage 数据天然集中,后续做成本分析和商业决策会更简单。