jimeng-billing-policy.mjs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import assert from 'node:assert/strict';
  2. const APIG_ID = '6pFf6EAdKT';
  3. const APIG_PRICE_CNY = 0.1;
  4. const BILLABLE_ENDPOINTS = {
  5. getImgV4: { unit: 'image', cny: 0.22 },
  6. getText2ImgV3: { unit: 'call', cny: 0.2 },
  7. getText2ImgV31: { unit: 'call', cny: 0.2 },
  8. getImg2ImgV3: { unit: 'call', cny: 0.2 },
  9. getImgV4_pod: { unit: 'image', cny: 0.22 },
  10. getImgV4_goods: { unit: 'image', cny: 0.22 },
  11. getInpaint: { unit: 'call', cny: 0.2 },
  12. getSuperResolution: { unit: 'call', cny: 0.4 },
  13. getVideoV3_720p: { unit: 'second', cny: 0.28 },
  14. getVideoV3_1080p: { unit: 'second', cny: 0.63 },
  15. getVideoV3_Pro: { unit: 'second', cny: 1 },
  16. getActor: { unit: 'second', cny: 0.5 },
  17. getActorV2: { unit: 'second', cny: 0.4 },
  18. getOmniHuman: { unit: 'second', cny: 1 },
  19. };
  20. const NON_BILLABLE_ENDPOINTS = ['getDataByTask02', 'getOhDateByTask', 'getWorkResult'];
  21. function creditsFor(endpoint, quantity = 1) {
  22. const pricing = BILLABLE_ENDPOINTS[endpoint];
  23. assert.ok(pricing, `unknown billable endpoint: ${endpoint}`);
  24. return Math.ceil((pricing.cny * quantity) / APIG_PRICE_CNY);
  25. }
  26. function assertBillingCase(endpoint, quantity, expectedCredits) {
  27. const actualCredits = creditsFor(endpoint, quantity);
  28. assert.equal(
  29. actualCredits,
  30. expectedCredits,
  31. `${endpoint}(${quantity}) expected ${expectedCredits} credits, got ${actualCredits}`,
  32. );
  33. }
  34. function assertNonBillingEndpoint(endpoint) {
  35. assert.equal(
  36. BILLABLE_ENDPOINTS[endpoint],
  37. undefined,
  38. `${endpoint} should not be billed, but appears in the billable mapping`,
  39. );
  40. assert.ok(NON_BILLABLE_ENDPOINTS.includes(endpoint), `${endpoint} is missing from the no-charge list`);
  41. }
  42. function main() {
  43. assert.equal(APIG_ID, '6pFf6EAdKT', 'APIG id must remain 6pFf6EAdKT');
  44. assert.equal(APIG_PRICE_CNY, 0.1, 'APIG price must remain 0.1 CNY per credit');
  45. assertBillingCase('getImgV4', 1, 3);
  46. assertBillingCase('getText2ImgV3', 1, 2);
  47. assertBillingCase('getText2ImgV31', 1, 2);
  48. assertBillingCase('getImg2ImgV3', 1, 2);
  49. assertBillingCase('getImgV4_pod', 1, 3);
  50. assertBillingCase('getImgV4_goods', 1, 3);
  51. assertBillingCase('getInpaint', 1, 2);
  52. assertBillingCase('getSuperResolution', 1, 4);
  53. assertBillingCase('getVideoV3_720p', 5, 14);
  54. assertBillingCase('getVideoV3_1080p', 5, 32);
  55. assertBillingCase('getVideoV3_Pro', 10, 100);
  56. assertBillingCase('getActor', 5, 25);
  57. assertBillingCase('getActorV2', 5, 20);
  58. assertBillingCase('getOmniHuman', 10, 100);
  59. NON_BILLABLE_ENDPOINTS.forEach(assertNonBillingEndpoint);
  60. console.log('jimeng billing policy validation passed');
  61. }
  62. main();