OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(cost): treat inherited model names as unpriced (#1727)
Michael D'Angelofab9482a690b
diff --git a/sdk/typescript/src/cost-model.ts b/sdk/typescript/src/cost-model.tsindex 5be059464..fa2fa63ea 100644--- a/sdk/typescript/src/cost-model.ts+++ b/sdk/typescript/src/cost-model.ts@@ -176,13 +176,18 @@ export function estimateScanCost(usage: unknown,): ScanCost | null {if (model === undefined) return null;- const bedrockPricing = BEDROCK_MODEL_PRICING[model];+ const bedrockPricing = Object.hasOwn(BEDROCK_MODEL_PRICING, model)+ ? BEDROCK_MODEL_PRICING[model]+ : undefined;const unitsPerUsd = bedrockPricing?.unitsPerUsd ?? 1_000_000_000;const pricingModel = model.startsWith("openai.")? model.slice("openai.".length): model;const pricing =- bedrockPricing?.short ?? MODEL_PRICING_NANODOLLARS[pricingModel];+ bedrockPricing?.short ??+ (Object.hasOwn(MODEL_PRICING_NANODOLLARS, pricingModel)+ ? MODEL_PRICING_NANODOLLARS[pricingModel]+ : undefined);const normalized = tokenUsage(usage);if (pricing === undefined || normalized === null) return null;const [inputRate, cachedInputRate, cacheWriteInputRate, outputRate] = pricing;diff --git a/sdk/typescript/tests-ts/cost.test.ts b/sdk/typescript/tests-ts/cost.test.tsindex 1d0740abc..1e64b998c 100644--- a/sdk/typescript/tests-ts/cost.test.ts+++ b/sdk/typescript/tests-ts/cost.test.ts@@ -488,6 +488,17 @@ describe("scan cost", () => {).toBe(0.0042);});+ test.each(Object.getOwnPropertyNames(Object.prototype))(+ "does not inherit prices for unknown model %s",+ (model) => {+ for (const selected of [model, `openai.${model}`]) {+ expect(+ estimateScanCost(selected, { input_tokens: 1, output_tokens: 1 }),+ ).toBeNull();+ }+ },+ );+test("does not invent prices for unknown models or incomplete usage", () => {for (const [model, usage] of [["unknown-model", { input_tokens: 1, output_tokens: 1 }],