Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { compileUnitCard } from '@modelschemas/rate-card'
4
5import { parseKlingPricing } from './kling-pricing.ts'
6
7/** Excerpt of the English table embedded in https://kling.ai/dev/pricing. */
8const PAGE = JSON.stringify({
9 en: {
10 newImageApi: {
11 main: {
12 list: [
13 {
14 table: {
15 data: [
16 {
17 model: 'Kling Image O1',
18 price: '8 Units ($0.028) / image',
19 quality: '1K, 2K',
20 },
21 {
22 model: 'Kling Image 2.1',
23 price: [
24 '4 Units ($0.014) / image',
25 '8 Units ($0.028) / image',
26 ],
27 quality: ['1K, 2K', '1K, 2K'],
28 },
29 ],
30 },
31 },
32 ],
33 },
34 },
35 newVideoApi: {
36 main: {
37 list: [
38 {
39 table: {
40 data: [
41 {
42 model: 'Kling 3.0',
43 spec: 'Per second',
44 function: [
45 'No Native Audio',
46 'With Native Audio x No Voice Control',
47 ],
48 p720: ['0.6 Units ($0.084) /s', '0.9 Units ($0.126) /s'],
49 p1080: ['0.8 Units ($0.112) /s', '1.2 Units ($0.168) /s'],
50 p4k: ['3.0 Units ($0.42) /s', '3.0 Units ($0.42) /s'],
51 },
52 ],
53 },
54 },
55 ],
56 },
57 },
58 },
59})
60
61const SOURCE = {
62 url: 'https://kling.ai/dev/pricing',
63 hash: 'b'.repeat(64),
64 extractedAt: '2026-10-03T00:00:00.000Z',
65}
66
67describe('kling pricing page', () => {
68 it('prices a single-amount model and leaves an unpriced id null', () => {
69 const rates = parseKlingPricing(PAGE)
70 const image = rates.get('kling-image-o1')
71 expect(image?.rates).toBe(0.028)
72 expect(image ? compileUnitCard(image, SOURCE) : null).toMatchObject({
73 price: { '*': [{ var: 'n' }, 0.028] },
74 })
75 const video = rates.get('kling-v3')
76 expect(video?.rates).toEqual({
77 off: { std: 0.084, pro: 0.112 },
78 on: { std: 0.126, pro: 0.168 },
79 })
80 expect(video ? compileUnitCard(video, SOURCE) : null).not.toBeNull()
81 expect(rates.has('kling-v2-1')).toBe(false)
82 expect(rates.has('kling-v1')).toBe(false)
83 })
84})