-- ============================================================
-- kimi-k3 定价接入
-- 数据来源: 用户提供
-- 定价: 输入(缓存命中)¥2.00/百万 输入(缓存未命中)¥20.00/百万 输出¥100.00/百万
-- 上下文: 1,048,576 tokens
-- ============================================================

-- 步骤1: 确认 modelprovider 已存在，如没有先创建
-- INSERT IGNORE INTO `modelprovider` (`id`, `name`) VALUES ('<provider_id>', '月之暗面');

-- 步骤2: 新建 pricing_program
INSERT IGNORE INTO `pricing_program` (`id`, `name`, `ownerid`, `providerid`, `pricing_belong`, `description`, `currency`)
VALUES (
  'kimi_k3_pricing',          -- id: 按需替换
  'kimi-k3 模型定价',
  '0',
  '<provider_id>',            -- 替换为月之暗面的 modelprovider.id
  'provider',
  'kimi-k3 按百万token计费，支持缓存命中差异化定价',
  'CNY'
);

-- 步骤3: 新建 pricing_program_timing (含分段定价 YAML)
INSERT IGNORE INTO `pricing_program_timing` (`id`, `ppid`, `name`, `enabled_date`, `expired_date`, `pricing_data`)
VALUES (
  'kimi_k3_timing',           -- id: 按需替换
  'kimi_k3_pricing',          -- ppid: 对应上一步的 pricing_program.id
  'kimi-k3 全价',
  '2026-07-17',               -- 启用日期
  '9999-12-31',
  'unit_values:
  百万: 1000000

fields:
  price_factors:
    type: string
    role: factor
    label: "计价因子"
  unit_prices:
    type: float
    role: factor
    label: "单位定价"
  unit:
    type: string
    role: factor
    label: "计价单位"

  prompt_tokens:
    type: int
    role: filter
    label: "输入Token数"
    value_mode: between

  completion_tokens:
    type: int
    role: factor
    label: "输出Token数"
    value_mode: between

  model:
    type: string
    role: filter
    label: "模型"

  uncached_prompt_tokens:
    type: int
    role: factor
    label: "非缓存输入Token"
    derived: "prompt_tokens - prompt_tokens_details.cached_tokens"

  cached_tokens:
    type: int
    role: factor
    label: "缓存Token"
    derived: "prompt_tokens_details.cached_tokens"

pricings:
  - price_factors: uncached_prompt_tokens
    unit_prices: 20.0
    unit: 百万
    prompt_tokens: "0.0 =~= 1048576.0"
    model: kimi-k3

  - price_factors: cached_tokens
    unit_prices: 2.0
    unit: 百万
    prompt_tokens: "0.0 =~= 1048576.0"
    model: kimi-k3

  - price_factors: completion_tokens
    unit_prices: 100.0
    unit: 百万
    prompt_tokens: "0.0 =~= 1048576.0"
    model: kimi-k3
'
);
