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(sdk): price OpenAI models by Bedrock region and inference route (#2362)
Michael D'Angelo31a42e9ba74a
diff --git a/docs/bedrock.md b/docs/bedrock.mdindex 57432c90e..5d52a3cb8 100644--- a/docs/bedrock.md+++ b/docs/bedrock.md@@ -93,7 +93,8 @@ Use the exact Bedrock identifier for the model your account can invoke:| Daybreak Blue | `openai.gpt-daybreak-blue-5.6-sol` | [Blue](https://docs.aws.amazon.com/en_en/bedrock/latest/userguide/model-card-openai-gpt-daybreak-blue-56-sol.html) || Daybreak Red | `openai.gpt-5.6-cyber` | [Red](https://docs.aws.amazon.com/en_en/bedrock/latest/userguide/model-card-openai-gpt-56-cyber.html) |-AWS lists `us-east-2` and the Bedrock Mantle Responses API for both models.+AWS lists the Bedrock Mantle Responses API in `us-east-2` for both models.+Red is also available in `us-gov-east-1`.The native provider handles that endpoint; no custom base URL or connector isneeded. Access requires OpenAI Trusted Access for Cyber enrollment and approval,followed by AWS provisioning through your account team. Red requires separate@@ -117,12 +118,47 @@ npx @openai/codex-security scan /path/to/repository \--provider amazon-bedrock --model openai.gpt-5.6-cyber --effort high```-Cost estimates and `--max-cost` recognize both exact Bedrock IDs using their-AWS model cards' Standard commercial in-region rates, including the AWS fee.-Blue reports a short/long-context range because aggregate usage does not identify-each request's context tier. Red's card lists a 272K context window and only-short-context pricing, so its upper estimate remains unavailable. Spending limits-use the short-context baseline. AWS bills the actual usage.+## Scan cost estimates++Estimates and `--max-cost` use the published Standard token rates for the exact+Bedrock model ID and inference route. For example, `openai.gpt-6.1-sol` and+`us.openai.gpt-6.1-sol` cost $2.20 per million short-context input tokens.+`global.openai.gpt-6.1-sol` costs $2.00. All three prices already include any+applicable AWS fee. See the [AWS model cards](https://docs.aws.amazon.com/bedrock/latest/userguide/model-cards-openai.html).++Live scans use the region in an explicit AWS Bedrock endpoint. Without an+endpoint override, they use the selected provider's `aws.region`, then+`AWS_REGION`, then `AWS_DEFAULT_REGION`. If the native provider obtains+its region from an AWS profile or managed credentials, set one of those values+to that same region for cost estimates and `--max-cost`. For a Red scan with+`AWS_REGION=us-gov-east-1`, the short-context input rate is $16.875 per million+tokens. The same model in Ohio costs $13.75. Open-weight GPT models can also+have different prices between commercial regions. Each estimate records the+price source and the rates used. When estimating from token counts in the SDK,+pass the region as the third argument, for example+`estimateScanCost("openai.gpt-5.6-cyber", usage, "us-gov-east-1")`.+With only a frontier model ID and usage, the SDK uses the commercial+in-region price for an unprefixed route.++The frontier model cards and the AWS Price List give different GovCloud West+prices for GPT-5.4, GPT-5.6 Terra, and GPT-5.6 Luna. Estimates use the+model-card rates for those three. The GPT-5.4 GovCloud East estimate comes+from the [regional price list](https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrock/current/us-gov-east-1/index.json).++For the open-weight models, estimates use regional Standard SKUs where available.+For example, the GPT OSS Safeguard 120B output SKU in Tokyo and São Paulo is+$0.73 per million tokens. The [Bedrock pricing page](https://aws.amazon.com/bedrock/pricing/#OpenAI)+groups both regions at $0.71. AWS bills actual usage.++Usage is reported across the scan, so the estimate gives a range where AWS+publishes both short- and long-context rates. Spending limits use the+short-context baseline. For Red, AWS publishes only short-context rates and+the upper estimate stays unavailable. A model or route without published rates+has no cost estimate and cannot be used with `--max-cost`. For example, AWS+lists global inference profiles for GPT-5.4 and GPT-5.5 but gives no exact+Standard rate for either global profile. The GPT OSS and Safeguard cards also+list Melbourne, Seoul, and Singapore. The regional price list has no Standard+token rates for those models in those three regions.<a id="repeatable-live-smoke-test"></a>diff --git a/sdk/typescript/docs/cli.md b/sdk/typescript/docs/cli.mdindex 5e0288ee1..64c7361a9 100644--- a/sdk/typescript/docs/cli.md+++ b/sdk/typescript/docs/cli.md@@ -1140,10 +1140,12 @@ their own timestamps, window durations, and reset times. These are historicalobservations, not a live allowance check or scan-only consumption. Empty readingsmean allowance was unavailable. There is no token-to-allowance conversion here.-Cost displays use [standard API prices](https://developers.openai.com/api/docs/pricing)-and show a short/long-context range. They estimate model usage, excluding other-tiers, fees, surcharges, and account-specific pricing. They do not measure ChatGPT-subscription allowance. Models without known prices have no estimate.+Cost displays use Standard token rates for the model. OpenAI models use+[OpenAI API pricing](https://developers.openai.com/api/docs/pricing). OpenAI+models on Bedrock use [AWS pricing for the model, inference route, and region](https://github.com/openai/codex-security/blob/main/docs/bedrock.md#scan-cost-estimates).+The short/long-context range estimates usage at published rates. Other service+tiers, account discounts, and ChatGPT subscription allowance are outside that+estimate. Models without known prices have no estimate.JSON, history, and bulk receipts include `cost.estimatedUsdRange` (`min`, `max`,and `context: "unknown"`). A null maximum means no upper estimate is available.diff --git a/sdk/typescript/scripts/package-dist-files.mjs b/sdk/typescript/scripts/package-dist-files.mjsindex 30e3ffa2e..064f43def 100644--- a/sdk/typescript/scripts/package-dist-files.mjs+++ b/sdk/typescript/scripts/package-dist-files.mjs@@ -77,6 +77,8 @@ const distModules = ["contract","cost","cost-model",+ "bedrock-pricing",+ "bedrock-oss-pricing","coverage-presentation","custom-validation","custom-validation-prompt",diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.tsindex 3da0dbb24..6f4c62b2f 100644--- a/sdk/typescript/src/api.ts+++ b/sdk/typescript/src/api.ts@@ -90,6 +90,7 @@ import {MODEL_FILE_SETTINGS,resolveNestedConfigPaths,scanApprovalPolicy,+ scanPricingContext,scanCyberAccessConfig,scanModelConfiguration,scanModelProvider,@@ -111,7 +112,7 @@ import {type ScanUsageObservation,type ScanWorkerEvent,} from "./cost.js";-import type { ScanTokenUsage } from "./cost-model.js";+import type { ScanPricingContext, ScanTokenUsage } from "./cost-model.js";import { measuredScanCost, combineMeasurements } from "./scan-measurement.js";import { ScanProgressTracker, type DeepScanProgress } from "./scan-progress.js";import { findScanSession } from "./scan-logs.js";@@ -345,6 +346,7 @@ interface PreparedRuntime {}interface PreparedSession {+ pricingContext?: ScanPricingContext;safetyIdentifier?: string;runtime: PreparedRuntime;runtimeHome: string;@@ -1368,6 +1370,7 @@ export class CodexSecurity {tracker = new ScanCostTracker({codexHome: runtime.codexHome,model: scanModelConfiguration(session.effectiveConfig).model,+ pricingContext: session.pricingContext,repository: inputs.repository,onMeasurement: (measurement) => {if (this.#operationTelemetry !== null)@@ -1538,6 +1541,7 @@ export class CodexSecurity {? repository.replace(/[A-Z]/g, (letter) => letter.toLowerCase()): repository;const configured = scanModelConfiguration(session.effectiveConfig);+ const { pricingContext } = session;const model = options.model ?? configured.model;const reasoningEffort =options.reasoningEffort ?? configured.reasoningEffort;@@ -1565,6 +1569,7 @@ export class CodexSecurity {tracker = new ScanCostTracker({codexHome: session.runtime.codexHome,model,+ pricingContext,repository,onMeasurement: (measurement) => {if (this.#operationTelemetry !== null)@@ -1661,7 +1666,10 @@ export class CodexSecurity {tracker = null;const snapshot = await activeTracker.stop(turn.usage).catch((error) => {reportTrackingError(error);- return { usage: turn.usage, cost: estimateScanCost(model, turn.usage) };+ return {+ usage: turn.usage,+ cost: estimateScanCost(model, turn.usage, pricingContext),+ };});return {...outcome,@@ -1715,7 +1723,11 @@ export class CodexSecurity {);const model = scanModelConfiguration(configuration);const modelProvider = scanModelProvider(configuration);- validateScanCostLimit(options.maxCostUsd, model.model);+ validateScanCostLimit(+ options.maxCostUsd,+ model.model,+ scanPricingContext(configuration, this.#dependencies.environment),+ );const archiveDir =options.archiveExisting === true? await planOutputArchive(inputs.outputDir)@@ -1861,9 +1873,9 @@ export class CodexSecurity {signal,temporaryRoot,);- const { runtime, effectiveConfig } = session;+ const { runtime, effectiveConfig, pricingContext } = session;const model = scanModelConfiguration(effectiveConfig);- validateScanCostLimit(options.maxCostUsd, model.model);+ validateScanCostLimit(options.maxCostUsd, model.model, pricingContext);for (const path of ["references/threat-model.md","references/security-guidance.md",@@ -2017,6 +2029,7 @@ export class CodexSecurity {const tracker = new ScanCostTracker({codexHome: runtime.codexHome,model: model.model,+ pricingContext,repository: target.repository,scanDirectory: outputDir,maxCostUsd: options.maxCostUsd,@@ -2026,6 +2039,7 @@ export class CodexSecurity {this.#operationTelemetry.measurement = combineMeasurements([...stageMeasurements.values()],model.model,+ pricingContext,);},onCost:@@ -2072,7 +2086,7 @@ export class CodexSecurity {warn(`Could not track policy-generation cost: ${errorMessage(error)}`,);- const cost = estimateScanCost(model.model, usage);+ const cost = estimateScanCost(model.model, usage, pricingContext);if (cost !== null) reportCost(cost);return { usage, cost };});@@ -2192,6 +2206,7 @@ export class CodexSecurity {pythonPath: string;protectedRoot: string;model: string;+ pricingContext?: ScanPricingContext;threadId: string | null;} | null = null;let preparedTargetWarnings: string[] = [];@@ -2328,6 +2343,7 @@ export class CodexSecurity {effectiveConfig,preflightConfig,modelProvider,+ pricingContext,authentication,approvalPolicy,python,@@ -2508,7 +2524,7 @@ export class CodexSecurity {pluginVersion: runtime.plugin.version,};const { model } = scanModelConfiguration(effectiveConfig);- validateScanCostLimit(options.maxCostUsd, model);+ validateScanCostLimit(options.maxCostUsd, model, pricingContext);if (mode === "deep" && options.maxCostUsd !== undefined) {budgetRecovery = {expectation,@@ -2516,6 +2532,7 @@ export class CodexSecurity {pythonPath: session.python,protectedRoot,model,+ pricingContext,threadId: null,};}@@ -2929,6 +2946,7 @@ export class CodexSecurity {const tracker = new ScanCostTracker({codexHome: runtime.codexHome,model,+ pricingContext,repository: repo,scanDirectory: scanDir,...(mode === "deep"@@ -3482,6 +3500,7 @@ export class CodexSecurity {modelProvider,workbenchValidated: true,model,+ pricingContext,onTurnStatus: (status, message) => {scanTurnStatus = status;// A later caller abort during iterator cleanup cannot undo a reported failure.@@ -3606,7 +3625,7 @@ export class CodexSecurity {reportTrackingError(error);return {usage,- cost: estimateScanCost(model, usage),+ cost: estimateScanCost(model, usage, pricingContext),measurement: latestMeasurement,};});@@ -3759,6 +3778,7 @@ export class CodexSecurity {protectedRoot,expectation,model,+ pricingContext,onReconnect: options.onReconnect,onWorkerStatus: options.onWorkerStatus,onObserverError: options.onObserverError,@@ -3987,6 +4007,7 @@ export class CodexSecurity {{status: "completed",model: budgetRecovery.model,+ ...turnPricingMetadata(budgetRecovery.pricingContext),usage: snapshot.usage,},budgetRecovery.threadId,@@ -4961,6 +4982,10 @@ export class CodexSecurity {preflightConfig,sessionConfig,modelProvider,+ pricingContext: scanPricingContext(+ effectiveConfig,+ runtime.environment,+ ),providerEnvKey,nativeProviderEnvironment:providerEnvKey !== undefined &&@@ -5174,11 +5199,14 @@ export class CodexSecurity {notifyObserver(options, "onOutputDirReady")(scanDir);}const revision = await repositoryRevision(local.repository, signal);- const { model } = scanModelConfiguration(- await mergedCodexConfig(- this.config,- scanCodexHome(this.#dependencies.environment),- ),+ const config = await mergedCodexConfig(+ this.config,+ scanCodexHome(this.#dependencies.environment),+ );+ const { model } = scanModelConfiguration(config);+ const pricingContext = scanPricingContext(+ config,+ this.#dependencies.environment,);const workbenchOptions: WorkbenchCommandOptions = {python,@@ -5265,7 +5293,7 @@ export class CodexSecurity {cached_input_tokens: 0,output_tokens: 0,};- const cost = estimateScanCost(model, usage);+ const cost = estimateScanCost(model, usage, pricingContext);await workbench(workbenchOptions,workbenchArgs("prepare-scan-completion", { scanId }),@@ -5297,6 +5325,7 @@ export class CodexSecurity {model,usage,mock: true,+ ...turnPricingMetadata(pricingContext),finalResponse:"Synthetic mock scan; no security analysis was performed.",},@@ -5690,6 +5719,7 @@ interface ScanEventRunOptions extends Pick<ScanOptions, "onReconnect"> {modelProvider?: unknown;workbenchValidated?: boolean;model?: string;+ pricingContext?: ScanPricingContext;onFinalize?: (usage: unknown) => Promise<unknown>;onTurnStatus?: (status: "completed" | "failed", message?: string) => void;onThreadStarted?: (threadId: string) => Promise<void> | void;@@ -5857,6 +5887,7 @@ export async function runScanEvents(finalResponse,usage,...(options.model === undefined ? {} : { model: options.model }),+ ...turnPricingMetadata(options.pricingContext),},threadId,options.scanDir,@@ -6250,14 +6281,31 @@ async function prepareScanOutputDir(return output;}+function turnPricingMetadata(context?: ScanPricingContext) {+ return context === undefined ? {} : { bedrockRegion: context.region };+}+function validateScanCostLimit(maxCostUsd: number | undefined,model: string,+ pricingContext?: ScanPricingContext,): void {if (maxCostUsd === undefined) return;- if (estimateScanCost(model, { input_tokens: 0, output_tokens: 0 }) === null) {+ if (+ estimateScanCost(+ model,+ { input_tokens: 0, output_tokens: 0 },+ pricingContext,+ ) === null+ ) {+ const region = pricingContext?.region;+ const location = region ? ` in ${region}` : "";+ const detail =+ region === null+ ? " Set the Bedrock billing region to check its regional price."+ : "";throw new CodexSecurityError(- `A scan cost limit is not available for the configured model: ${model}.`,+ `A scan cost limit is not available for the configured model: ${model}${location}.${detail}`,);}}diff --git a/sdk/typescript/src/bedrock-oss-pricing.ts b/sdk/typescript/src/bedrock-oss-pricing.tsnew file mode 100644index 000000000..80b890c52--- /dev/null+++ b/sdk/typescript/src/bedrock-oss-pricing.ts@@ -0,0 +1,81 @@+// Standard on-demand input and output in USD per million tokens (AWS quotes+// 1K-token units in the bulk catalog). The four OSS models have a 128K context+// window and one input/output rate for the whole request.+type Prices = readonly [input: number, output: number];+type ModelRates = Readonly<Record<string, Prices | undefined>>;++function models(+ base20b: Prices,+ base120b: Prices,+ safeguard20b?: Prices,+ safeguard120b?: Prices,+): ModelRates {+ return {+ "openai.gpt-oss-20b": base20b,+ "openai.gpt-oss-120b": base120b,+ "openai.gpt-oss-20b-1:0": base20b,+ "openai.gpt-oss-120b-1:0": base120b,+ "openai.gpt-oss-safeguard-20b": safeguard20b,+ "openai.gpt-oss-safeguard-120b": safeguard120b,+ };+}++const us = models([0.07, 0.3], [0.15, 0.6], [0.07, 0.2], [0.15, 0.6]);+const gov = models([0.084, 0.36], [0.18, 0.72]);+const tokyo = models([0.08, 0.36], [0.18, 0.73], [0.08, 0.24], [0.18, 0.73]);++const regions: Readonly<Record<string, ModelRates>> = {+ "us-east-1": us,+ "us-east-2": us,+ "us-west-2": us,+ "us-gov-east-1": gov,+ "us-gov-west-1": gov,+ "ap-northeast-1": tokyo,+ "ap-south-1": models([0.08, 0.35], [0.18, 0.71], [0.08, 0.24], [0.18, 0.71]),+ // The Standard table on AWS's pricing page explicitly lists Sydney, where+ // the bulk catalog only has Mantle SKUs.+ "ap-southeast-2": models(+ [0.0721, 0.309],+ [0.1545, 0.618],+ [0.0721, 0.206],+ [0.1545, 0.618],+ ),+ "ap-southeast-3": models(+ [0.07, 0.31],+ [0.16, 0.62],+ [0.084, 0.24],+ [0.18, 0.72],+ ),+ "eu-central-1": models([0.09, 0.4], [0.2, 0.79], [0.084, 0.24], [0.18, 0.72]),+ "eu-north-1": models([0.07, 0.3], [0.15, 0.6], [0.084, 0.24], [0.18, 0.72]),+ "eu-south-1": models([0.09, 0.4], [0.2, 0.79], [0.08, 0.23], [0.18, 0.7]),+ "eu-west-1": models([0.08, 0.35], [0.18, 0.7], [0.08, 0.23], [0.18, 0.7]),+ "eu-west-2": models([0.11, 0.47], [0.23, 0.93], [0.11, 0.31], [0.23, 0.93]),+ "sa-east-1": tokyo,+};++export function bedrockOssPricing(model: string, region?: string | null) {+ const govProfile =+ model === "us-gov.openai.gpt-oss-20b-1:0" ||+ model === "us-gov.openai.gpt-oss-120b-1:0";+ // Both possible source regions of these inference profiles have the same+ // rates. A bare model ID requires the billing region to resolve its price.+ const origin = region ?? (govProfile ? "us-gov-east-1" : undefined);+ if (origin === undefined || !Object.hasOwn(regions, origin)) return undefined;+ if (govProfile && origin !== "us-gov-east-1" && origin !== "us-gov-west-1")+ return undefined;+ const rates = regions[origin]!;+ const id = govProfile ? model.slice("us-gov.".length) : model;+ const price = Object.hasOwn(rates, id) ? rates[id] : undefined;+ if (!price) return undefined;+ const [input, output] = price;+ const tokens = [input, input, input, output] as const;+ return {+ short: tokens,+ long: tokens,+ source:+ origin === "ap-southeast-2" && model.endsWith("-1:0")+ ? "https://aws.amazon.com/bedrock/pricing/#OpenAI"+ : "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrock/20261102165015/index.json",+ };+}diff --git a/sdk/typescript/src/bedrock-pricing.ts b/sdk/typescript/src/bedrock-pricing.tsnew file mode 100644index 000000000..31ab2f239--- /dev/null+++ b/sdk/typescript/src/bedrock-pricing.ts@@ -0,0 +1,256 @@+import { bedrockOssPricing } from "./bedrock-oss-pricing.js";++// AWS Bedrock Standard prices, in USD per million tokens. Each route lists+// the source regions of the request (not cross-region routing destinations).+type Prices = readonly [+ input: number,+ read: number,+ write: number,+ output: number,+];+type Route = "regional" | "us" | "us-gov" | "in" | "global";+type Origins = Partial<Record<Route, readonly string[]>>;++const usEast = ["us-east-1", "us-east-2"];+const usMantle = [...usEast, "us-west-2"];+const usGeo = [...usMantle, "us-west-1", "ca-central-1", "ca-west-1"];+const gov = ["us-gov-east-1", "us-gov-west-1"];+const india = ["ap-south-1", "ap-south-2"];+const astraGlobal = [+ ...usGeo,+ "eu-central-1",+ "eu-north-1",+ "eu-west-1",+ "eu-west-2",+ "eu-west-3",+ "ap-northeast-1",+ "ap-northeast-2",+ "ap-northeast-3",+ "ap-south-1",+ "ap-southeast-1",+ "ap-southeast-2",+ "sa-east-1",+];+const commonGlobal = [+ ...astraGlobal,+ "eu-central-2",+ "eu-south-1",+ "eu-south-2",+ "ap-east-2",+ "ap-south-2",+ "ap-southeast-3",+ "ap-southeast-4",+ "ap-southeast-5",+ "ap-southeast-6",+ "ap-southeast-7",+ "il-central-1",+ "af-south-1",+];+const gpt56Global = [...commonGlobal, "me-central-1", "me-south-1"];+// GPT-6.1 Sol links here for its global source regions:+// https://docs.aws.amazon.com/bedrock/latest/userguide/models-region-compatibility.html#model-regions-openai+const gpt6Global = [...commonGlobal, "mx-central-1"];++function perToken([input, read, write, output]: Prices, scale: number): Prices {+ return [+ Math.round(input * scale),+ Math.round(read * scale),+ Math.round(write * scale),+ Math.round(output * scale),+ ];+}++function offer(+ origins: Origins,+ short: Prices,+ long?: Prices,+ source?: string,+) {+ return { origins, short, long, source };+}++function card(slug: string, ...offers: ReturnType<typeof offer>[]) {+ return {+ source: `https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-${slug}.html`,+ offers,+ };+}++// Prefer AWS's route-specific model card, including its GovCloud prices.+// GPT-5.4 and GPT-5.5 list no separate write fee for their implicit cache.+// Their cards publish regional rates. AWS prices geographic inference at the+// source region's Standard rate, and does not specify the Global rate here:+// https://docs.aws.amazon.com/bedrock/latest/userguide/models-region-compatibility.html+const cards: Readonly<Record<string, ReturnType<typeof card>>> = {+ "openai.gpt-5.4": card(+ "54",+ offer(+ { regional: usMantle, us: usGeo },+ [2.75, 0.275, 2.75, 16.5],+ [5.5, 0.55, 5.5, 24.75],+ ),+ offer({ regional: ["us-gov-west-1"] }, [3.375, 0.3375, 3.375, 20.25]),+ offer(+ { regional: ["us-gov-east-1"] },+ [3.3, 0.33, 3.3, 19.8],+ undefined,+ "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrock/20261102165015/us-gov-east-1/index.json",+ ),+ ),+ "openai.gpt-5.5": card(+ "55",+ offer(+ { regional: usEast, us: usGeo },+ [5.5, 0.55, 5.5, 33],+ [11, 1.1, 11, 49.5],+ ),+ ),+ "openai.gpt-daybreak-blue-5.6-sol": card(+ "daybreak-blue-56-sol",+ offer(+ { regional: ["us-east-2"] },+ [4.4, 0.44, 5.5, 22],+ [8.8, 0.88, 11, 33],+ ),+ ),+ "openai.gpt-5.6-cyber": card(+ "56-cyber",+ offer({ regional: ["us-east-2"] }, [13.75, 1.375, 17.1875, 82.5]),+ offer({ regional: ["us-gov-east-1"] }, [16.875, 1.6875, 21.09375, 101.25]),+ ),+ "openai.gpt-5.6-luna": card(+ "56-luna",+ offer(+ { regional: usMantle, us: usGeo, in: india },+ [0.22, 0.022, 0.275, 1.32],+ [0.44, 0.044, 0.55, 1.98],+ ),+ offer(+ { global: gpt56Global },+ [0.2, 0.02, 0.25, 1.2],+ [0.4, 0.04, 0.5, 1.8],+ ),+ offer(+ { regional: gov, "us-gov": gov },+ [0.27, 0.027, 0.3375, 1.62],+ [0.54, 0.054, 0.675, 2.43],+ ),+ ),+ "openai.gpt-5.6-terra": card(+ "56-terra",+ offer(+ { regional: usMantle, us: usGeo, in: india },+ [2.2, 0.22, 2.75, 13.2],+ [4.4, 0.44, 5.5, 19.8],+ ),+ offer({ global: gpt56Global }, [2, 0.2, 2.5, 12], [4, 0.4, 5, 18]),+ offer(+ { regional: gov, "us-gov": gov },+ [2.7, 0.27, 3.375, 16.2],+ [5.4, 0.54, 6.75, 24.3],+ ),+ ),+ "openai.gpt-5.6-sol": card(+ "56-sol",+ offer(+ { regional: usEast, us: usGeo },+ [4.4, 0.44, 5.5, 22],+ [8.8, 0.88, 11, 33],+ ),+ offer({ global: gpt56Global }, [4, 0.4, 5, 20], [8, 0.8, 10, 30]),+ ),+ "openai.gpt-6-astra": card(+ "6-astra",+ offer(+ { regional: ["us-east-1", "us-west-2"], us: usGeo },+ [11, 1.1, 13.75, 55],+ [22, 2.2, 27.5, 82.5],+ ),+ offer({ global: astraGlobal }, [10, 1, 12.5, 50], [20, 2, 25, 75]),+ ),+ "openai.gpt-6-luna": card(+ "6-luna",+ offer(+ { regional: ["us-east-1"], us: usGeo },+ [0.11, 0.011, 0.1375, 0.55],+ [0.22, 0.022, 0.275, 0.825],+ ),+ offer(+ { global: gpt6Global },+ [0.1, 0.01, 0.125, 0.5],+ [0.2, 0.02, 0.25, 0.75],+ ),+ ),+ "openai.gpt-6-sol": card(+ "6-sol",+ offer(+ { regional: ["us-east-1"], us: usGeo },+ [2.2, 0.22, 2.75, 11],+ [4.4, 0.44, 5.5, 16.5],+ ),+ offer({ global: gpt6Global }, [2, 0.2, 2.5, 10], [4, 0.4, 5, 15]),+ ),+ "openai.gpt-6.1-sol": card(+ "6-1-sol",+ offer(+ { regional: ["us-east-1"], us: usGeo },+ [2.2, 0.11, 2.75, 11],+ [4.4, 0.22, 5.5, 16.5],+ ),+ offer({ global: gpt6Global }, [2, 0.1, 2.5, 10], [4, 0.2, 5, 15]),+ ),+ "openai.gpt-6.1-terra": card(+ "6-1-terra",+ offer(+ { regional: ["us-east-1"], us: usGeo },+ [1.1, 0.055, 1.375, 5.5],+ [2.2, 0.11, 2.75, 8.25],+ ),+ offer({ global: gpt6Global }, [1, 0.05, 1.25, 5], [2, 0.1, 2.5, 7.5]),+ ),+};++function frontierPricing(model: string, region?: string | null) {+ const match = /^(?:(us|us-gov|in|global)\.)?(openai\.gpt-[\w.-]+)$/.exec(+ model,+ );+ if (!match) return undefined;+ const modelCard = cards[match[2]!];+ if (!modelCard) return undefined;+ const route = (match[1] ?? "regional") as Route;+ // The first regional offer is the model-only SDK's commercial default.+ // A live scan with an unresolved region (null) needs an unambiguous rate.+ const offers = modelCard.offers.filter(+ ({ origins }) =>+ origins[route] && (region == null || origins[route].includes(region)),+ );+ if (region === null && offers.length > 1) return undefined;+ const rate = offers[0];+ if (!rate) return undefined;+ return {+ short: rate.short,+ long: rate.long,+ source: rate.source ?? modelCard.source,+ };+}++export function bedrockModelPricing(model: string, region?: string | null) {+ const rate =+ frontierPricing(model, region) ?? bedrockOssPricing(model, region);+ if (!rate) return undefined;++ // Keep nanodollar arithmetic where possible. GovCloud Cyber cache writes+ // require quarter-nanodollars, and Sydney OSS prices need tenths.+ const prices = [...rate.short, ...(rate.long ?? [])];+ const scale = [1_000, 2_000, 4_000, 10_000].find((scale) =>+ prices.every((price) => Math.round(price * scale) / scale === price),+ );+ if (!scale) throw new Error("Bedrock price exceeds supported precision");+ return {+ short: perToken(rate.short, scale),+ long: rate.long && perToken(rate.long, scale),+ unitsPerUsd: scale * 1_000_000,+ source: rate.source,+ asOf: "2026-11-05",+ };+}diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex 9bba63c6d..4421bf78c 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -195,6 +195,7 @@ import {resolveCodexProfile,mergedCodexConfig,readCodexFileProfile,+ scanPricingContext,scanModel,scanModelConfiguration,scanModelProvider,@@ -5863,14 +5864,17 @@ export async function main(dependencies.environment["CI"] === undefined &&dependencies.environment["TERM"] !== "dumb") {+ const dashboardConfig = await mergedCodexConfig(+ config,+ scanCodexHome(dependencies.environment),+ );const candidate = new ScanDashboard(errorOutput, {repository,presentation: "components",- model: scanModelConfiguration(- await mergedCodexConfig(- config,- scanCodexHome(dependencies.environment),- ),+ model: scanModelConfiguration(dashboardConfig),+ pricingContext: scanPricingContext(+ dashboardConfig,+ dependencies.environment,),mode: settings.mode,maxCostUsd: settings.maxCostUsd,@@ -10391,6 +10395,10 @@ async function executeScan(mode: arguments_.mode,showCost,model: scanModelConfiguration(effectiveConfiguration),+ pricingContext: scanPricingContext(+ effectiveConfiguration,+ dependencies.environment,+ ),...(arguments_.maxCostUsd === undefined? {}: { maxCostUsd: arguments_.maxCostUsd }),diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.tsindex 1ffa9d0f6..0f679535d 100644--- a/sdk/typescript/src/config.ts+++ b/sdk/typescript/src/config.ts@@ -1,3 +1,4 @@+import type { ScanPricingContext } from "./cost-model.js";import { randomUUID } from "node:crypto";import { mkdir, open, readFile, rename, unlink } from "node:fs/promises";import { dirname, join, resolve } from "node:path";@@ -122,6 +123,50 @@ export function scanModelProvider(config: Readonly<JsonObject>): unknown {return selectedProfile?.["model_provider"] ?? config["model_provider"];}+function bedrockPricingRegion(+ provider: JsonValue | undefined,+ environment: Readonly<Record<string, string | undefined>>,+): string | null {+ const baseUrl = isObject(provider) ? provider["base_url"] : undefined;+ if (typeof baseUrl === "string") {+ // Codex sends inference to an explicit endpoint even when aws.region differs.+ const host = URL.parse(baseUrl)?.hostname ?? "";+ return (+ /^bedrock-(?:mantle|runtime)(?:-fips)?\.([a-z0-9-]+)\.(?:api\.aws|amazonaws\.com(?:\.cn)?)$/.exec(+ host,+ )?.[1] ?? null+ );+ }+ const aws = isObject(provider) ? provider["aws"] : undefined;+ const region = isObject(aws) ? aws["region"] : undefined;+ return (+ (typeof region === "string" && region.trim()) ||+ environment["AWS_REGION"]?.trim() ||+ environment["AWS_DEFAULT_REGION"]?.trim() ||+ null+ );+}++/** @internal Keep billing selection separate from model names shared by providers. */+export function scanPricingContext(+ config: Readonly<JsonObject>,+ environment: Readonly<Record<string, string | undefined>>,+): ScanPricingContext | undefined {+ const selected = scanModelProvider(config);+ if (selected !== "amazon-bedrock" && selected !== "amazon-bedrock-runtime") {+ return undefined;+ }+ const resolved = selectedScanProfile(config)+ ? resolveCodexProfile(config)+ : config;+ const providers = resolved["model_providers"];+ const provider = isObject(providers) ? providers[selected] : undefined;+ return {+ provider: "amazon-bedrock",+ region: bedrockPricingRegion(provider, environment),+ };+}+/** @internal Use the selected native provider's configured credential key. */export function scanProviderEnvKey(config: Readonly<JsonObject>,diff --git a/sdk/typescript/src/cost-model.ts b/sdk/typescript/src/cost-model.tsindex 98200d173..752e51c29 100644--- a/sdk/typescript/src/cost-model.ts+++ b/sdk/typescript/src/cost-model.ts@@ -1,6 +1,12 @@+import { bedrockModelPricing } from "./bedrock-pricing.js";import { isRecord } from "./record.js";import { isSafeNonNegativeInteger } from "./value.js";+export interface ScanPricingContext {+ provider: "amazon-bedrock";+ region: string | null;+}+export interface ScanCost {model: string;inputTokens: number;@@ -47,38 +53,6 @@ export interface ScanTokenUsage {total_tokens: number;}-const BEDROCK_MODEL_PRICING: Readonly<- Record<- string,- {- short: ModelPricing;- long?: ModelPricing;- unitsPerUsd: number;- source: string;- asOf: string;- }- >-> = {- // AWS commercial in-region Standard prices already include the 10% fee.- "openai.gpt-daybreak-blue-5.6-sol": {- short: [4_400, 440, 5_500, 22_000],- long: [8_800, 880, 11_000, 33_000],- unitsPerUsd: 1_000_000_000,- source:- "https://docs.aws.amazon.com/en_en/bedrock/latest/userguide/model-card-openai-gpt-daybreak-blue-56-sol.html",- asOf: "2026-10-01",- },- "openai.gpt-5.6-cyber": {- // Half-nanodollar units preserve the $17.1875/M cache-write rate exactly,- // including an odd number of cache-write tokens.- short: [27_500, 2_750, 34_375, 165_000],- unitsPerUsd: 2_000_000_000,- source:- "https://docs.aws.amazon.com/en_en/bedrock/latest/userguide/model-card-openai-gpt-56-cyber.html",- asOf: "2026-10-01",- },-};-const MODEL_PRICING_NANODOLLARS: Readonly<Record<string, ModelPricing>> = {// GPT-5.5 has no additional cache-write charge."gpt-5.5": [5_000, 500, 5_000, 30_000],@@ -169,22 +143,25 @@ export function tokenUsage(value: unknown): ScanTokenUsage | null {};}+/**+ * Estimates Standard token costs using the selected provider's published rates.+ * A string (or null for an unknown region) selects Bedrock for compatibility.+ * Model-only Bedrock frontier estimates use the commercial in-region price.+ */export function estimateScanCost(model: string | undefined,usage: unknown,+ context?: ScanPricingContext | string | null,): ScanCost | null {if (model === undefined) return null;- 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 region =+ typeof context === "object" && context !== null ? context.region : context;+ const providerPricing = bedrockModelPricing(model, region);+ const unitsPerUsd = providerPricing?.unitsPerUsd ?? 1_000_000_000;const pricing =- bedrockPricing?.short ??- (Object.hasOwn(MODEL_PRICING_NANODOLLARS, pricingModel)- ? MODEL_PRICING_NANODOLLARS[pricingModel]+ providerPricing?.short ??+ (context === undefined && Object.hasOwn(MODEL_PRICING_NANODOLLARS, model)+ ? MODEL_PRICING_NANODOLLARS[model]: undefined);const normalized = tokenUsage(usage);if (pricing === undefined || normalized === null) return null;@@ -203,9 +180,9 @@ export function estimateScanCost(outputTokens * outputRate;if (!Number.isSafeInteger(costUnits)) return null;- const longPricing = bedrockPricing- ? bedrockPricing.long- : LONG_CONTEXT_PRICING_NANODOLLARS[pricingModel];+ const longPricing = providerPricing+ ? providerPricing.long+ : LONG_CONTEXT_PRICING_NANODOLLARS[model];let maximumUnits: number | null = null;if (longPricing !== undefined) {const [longInput, longRead, longWrite, longOutput] = longPricing;@@ -239,22 +216,22 @@ export function estimateScanCost(context: "unknown",},pricing: {- source: bedrockPricing- ? bedrockPricing.source- : pricingModel.startsWith("gpt-5.5")+ source: providerPricing+ ? providerPricing.source+ : model.startsWith("gpt-5.5")? "https://developers.openai.com/api/docs/models/gpt-5.5"- : pricingModel === "gpt-6-sol"+ : model === "gpt-6-sol"? "https://developers.openai.com/api/docs/models/gpt-6-sol": "https://developers.openai.com/api/docs/pricing",- asOf: bedrockPricing- ? bedrockPricing.asOf- : pricingModel === "gpt-6-sol"+ asOf: providerPricing+ ? providerPricing.asOf+ : model === "gpt-6-sol"? "2026-10-10"- : pricingModel === "gpt-5.6-cyber"+ : model === "gpt-5.6-cyber"? "2026-10-06"- : pricingModel === "gpt-6-cyber"+ : model === "gpt-6-cyber"? "2026-11-05"- : pricingModel === "gpt-6.1-sol" || pricingModel === "gpt-6-luna"+ : model === "gpt-6.1-sol" || model === "gpt-6-luna"? "2026-09-30": "2026-09-14",serviceTier: "standard",diff --git a/sdk/typescript/src/cost.ts b/sdk/typescript/src/cost.tsindex 580511537..dfa362db5 100644--- a/sdk/typescript/src/cost.ts+++ b/sdk/typescript/src/cost.ts@@ -21,6 +21,7 @@ import {estimateScanCost,tokenUsage,type ScanCost,+ type ScanPricingContext,type ScanTokenUsage,} from "./cost-model.js";import {@@ -332,6 +333,7 @@ function sessionObservation<T>(interface ScanCostTrackerOptions {codexHome: string;+ pricingContext?: ScanPricingContext;model: string;repository?: string;scanDirectory?: string;@@ -2445,7 +2447,11 @@ export class ScanCostTracker {this.#snapshot.measurement.missingThreadCount > 0)return this.#snapshot;- const cost = estimateScanCost(this.#options.model, fallbackUsage);+ const cost = estimateScanCost(+ this.#options.model,+ fallbackUsage,+ this.#options.pricingContext,+ );const usage = tokenUsage(fallbackUsage);this.#setSnapshot(usage, cost, usage !== null, usage === null ? 0 : 1, 0);this.#reportUsage(usage);@@ -2835,7 +2841,11 @@ export class ScanCostTracker {details?: Pick<ScanUsageMeasurement, "coverageScope" | "warnings">,reportCost = true,): void {- const cost = estimateScanCost(this.#options.model, usage);+ const cost = estimateScanCost(+ this.#options.model,+ usage,+ this.#options.pricingContext,+ );this.#setSnapshot(usage,cost,diff --git a/sdk/typescript/src/index.ts b/sdk/typescript/src/index.tsindex 29f6060ac..ec1114745 100644--- a/sdk/typescript/src/index.ts+++ b/sdk/typescript/src/index.ts@@ -94,7 +94,7 @@ export type {ScanUsageObservation,ScanWorkerEvent,} from "./cost.js";-export type { ScanTokenUsage } from "./cost-model.js";+export type { ScanPricingContext, ScanTokenUsage } from "./cost-model.js";export type { DeepScanProgress } from "./scan-progress.js";export type { CustomValidationResult } from "./custom-validation.js";export type { ScanActivity, ScanActivityStatus } from "./scan-activity.js";diff --git a/sdk/typescript/src/result.ts b/sdk/typescript/src/result.tsindex d413ea336..31fca3fe6 100644--- a/sdk/typescript/src/result.ts+++ b/sdk/typescript/src/result.ts@@ -15,6 +15,8 @@ export interface TurnResultMetadata {id?: string;status?: string;model?: string;+ /** Source region recorded for Bedrock scans. */+ bedrockRegion?: string | null;durationMs?: number;finalResponse?: string;usage?: unknown;@@ -88,7 +90,11 @@ export class ScanResult {this.threatModelPath = options.threatModelPath ?? null;this.cost =options.recordedCost ??- estimateScanCost(options.turnResult.model, options.turnResult.usage);+ estimateScanCost(+ options.turnResult.model,+ options.turnResult.usage,+ options.turnResult.bedrockRegion,+ );if (options.sarifPath !== undefined) {this.sarifPath = options.sarifPath;} else {diff --git a/sdk/typescript/src/scan-dashboard.ts b/sdk/typescript/src/scan-dashboard.tsindex d99a11642..bc54a73fc 100644--- a/sdk/typescript/src/scan-dashboard.ts+++ b/sdk/typescript/src/scan-dashboard.ts@@ -26,6 +26,7 @@ import {formatScanCosts,formatScanCostTokens,formatTokenUsage,+ type ScanPricingContext,type ScanTokenUsage,} from "./cost-model.js";import { formatDeepScanReviews } from "./scan-progress.js";@@ -92,6 +93,7 @@ interface ScanDashboardOptions {componentName?: string;mode?: ScanMode;model?: ScanModelConfiguration;+ pricingContext?: ScanPricingContext;maxCostUsd?: number;showCost?: boolean;clock: DashboardClock;@@ -1165,10 +1167,11 @@ export class ScanDashboard {if (this.#cost === null &&this.#options.maxCostUsd === undefined &&- estimateScanCost(this.#options.model?.model, {- input_tokens: 0,- output_tokens: 0,- }) === null+ estimateScanCost(+ this.#options.model?.model,+ { input_tokens: 0, output_tokens: 0 },+ this.#options.pricingContext,+ ) === null) {return [];}diff --git a/sdk/typescript/src/scan-measurement.ts b/sdk/typescript/src/scan-measurement.tsindex 178cda879..3b7cf1a39 100644--- a/sdk/typescript/src/scan-measurement.ts+++ b/sdk/typescript/src/scan-measurement.ts@@ -2,17 +2,19 @@ import { addTokenUsage, type ScanUsageMeasurement } from "./cost.js";import {estimateScanCost,tokenUsage,+ type ScanPricingContext,type ScanTokenUsage,} from "./cost-model.js";export function measurementFromUsage(value: unknown,model: string,+ pricingContext?: ScanPricingContext,): ScanUsageMeasurement {const usage = tokenUsage(value);return {usage,- cost: estimateScanCost(model, usage),+ cost: estimateScanCost(model, usage, pricingContext),coverage: usage === null ? "unavailable" : "complete",observedAt: new Date().toISOString(),threadCount: usage === null ? 0 : 1,@@ -24,6 +26,7 @@ export function measurementFromUsage(export function combineMeasurements(values: readonly Readonly<ScanUsageMeasurement>[],model: string,+ pricingContext?: ScanPricingContext,): ScanUsageMeasurement {let usage: ScanTokenUsage | null = null;for (const value of values) {@@ -33,7 +36,7 @@ export function combineMeasurements(...new Set(values.flatMap((value) => value.warnings ?? [])),].sort();return {- ...measurementFromUsage(usage, model),+ ...measurementFromUsage(usage, model, pricingContext),...(warnings.length ? { warnings } : {}),coverage:usage === nulldiff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex b48d3e705..e9d763f1a 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -1176,6 +1176,7 @@ describe("CodexSecurity orchestration", () => {CODEX_API_KEY: "synthetic-codex-key",OPENROUTER_API_KEY: "synthetic-openrouter-key",FIREWORKS_API_KEY: "synthetic-fireworks-key",+ AWS_DEFAULT_REGION: "us-east-2",...credentials,};const client = new TestClient(@@ -1246,11 +1247,13 @@ describe("CodexSecurity orchestration", () => {const { root, repository, codexHome, scanDir } = await scanDirectories();const createCodex = mock(completedCodex(root));const onAuthentication = mock<(selected: ScanAuthentication) => void>();+ const onCost = mock<(cost: ScanCost) => void>();+ let savedCost: ScanCost | undefined;let savedRecipe: Record<string, unknown> | undefined;const environment = {OPENAI_API_KEY: "synthetic-openai-key-must-not-be-used",AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer",- AWS_REGION: "us-east-2",+ AWS_REGION: "us-gov-west-1",};const client = new TestClient({@@ -1259,13 +1262,13 @@ describe("CodexSecurity orchestration", () => {model_provider: "openai",profiles: {bedrock: {- model: "openai.gpt-5.6-luna",+ model: "openai.gpt-5.6-cyber",model_provider: "amazon-bedrock",},},model_providers: {"amazon-bedrock": {- aws: { region: "us-east-2", profile: "security-prod" },+ aws: { region: "us-gov-east-1", profile: "security-prod" },},},},@@ -1281,6 +1284,9 @@ describe("CodexSecurity orchestration", () => {): Promise<JsonObject> => {if (args[0] === "register-cli-scan") {savedRecipe = JSON.parse(input!).recipe;+ } else if (args[0] === "complete-scan") {+ const costJson = args[args.indexOf("--cost-json") + 1]!;+ savedCost = JSON.parse(costJson).cost;}return mockWorkbench(args, input);},@@ -1293,7 +1299,7 @@ describe("CodexSecurity orchestration", () => {await expect(client.preflight(repository, { maxCostUsd: 1 }),).resolves.toMatchObject({- model: "openai.gpt-5.6-luna",+ model: "openai.gpt-5.6-cyber",modelProvider: "amazon-bedrock",maxCostUsd: 1,authentication: {@@ -1305,6 +1311,7 @@ describe("CodexSecurity orchestration", () => {const result = await client.run(repository, {maxCostUsd: 1,onAuthentication,+ onCost,});expect(onAuthentication.mock.lastCall?.[0]).toEqual({@@ -1314,7 +1321,7 @@ describe("CodexSecurity orchestration", () => {});expect(createCodex.mock.lastCall?.[0]?.env).toMatchObject({AWS_BEARER_TOKEN_BEDROCK: "synthetic-bedrock-bearer",- AWS_REGION: "us-east-2",+ AWS_REGION: "us-gov-west-1",});expect(createCodex.mock.lastCall?.[0]?.config).toMatchObject({model_reasoning_summary: "none",@@ -1323,20 +1330,38 @@ describe("CodexSecurity orchestration", () => {expect(createCodex.mock.lastCall?.[0]?.env).not.toHaveProperty("OPENAI_API_KEY",);- expect(result.cost).toMatchObject({ model: "openai.gpt-5.6-luna" });+ expect(result.turnResult.bedrockRegion).toBe("us-gov-east-1");+ expect(result.cost).toMatchObject({+ model: "openai.gpt-5.6-cyber",+ inputTokens: 10,+ cachedInputTokens: 2,+ outputTokens: 3,+ estimatedUsd: 0.000442125,+ estimatedUsdRange: { min: 0.000442125, max: null },+ pricing: {+ usdPerMillionTokens: {+ input: 16.875,+ cacheRead: 1.6875,+ cacheWrite: 21.09375,+ output: 101.25,+ },+ },+ });+ expect(onCost.mock.lastCall?.[0]).toEqual(result.cost!);+ expect(savedCost).toEqual(result.cost!);expect(savedRecipe).toMatchObject({config: {model_provider: "openai",profile: "bedrock",profiles: {bedrock: {- model: "openai.gpt-5.6-luna",+ model: "openai.gpt-5.6-cyber",model_provider: "amazon-bedrock",},},model_providers: {"amazon-bedrock": {- aws: { region: "us-east-2", profile: "security-prod" },+ aws: { region: "us-gov-east-1", profile: "security-prod" },},},},@@ -1344,6 +1369,36 @@ describe("CodexSecurity orchestration", () => {await client.close();});+ test.each([+ ["missing", {}],+ [+ "unsupported",+ { AWS_REGION: "us-gov-west-1", AWS_DEFAULT_REGION: "us-gov-east-1" },+ ],+ ] as const)(+ "rejects Bedrock budgets when the billing region is %s",+ async (_reason, environment) => {+ const { repository } = await repositoryDirectories();+ const { client, prepareRuntime } = localClient(+ {+ codexOverrides: {+ model: "openai.gpt-5.6-cyber",+ model_provider: "amazon-bedrock",+ },+ },+ environment,+ );+ await expect(+ client.preflight(repository, { maxCostUsd: 1 }),+ ).rejects.toThrow("cost limit is not available for the configured model");+ await expect(client.preflight(repository)).resolves.toMatchObject({+ model: "openai.gpt-5.6-cyber",+ });+ expect(prepareRuntime).not.toHaveBeenCalled();+ await client.close();+ },+ );+test.each(["standard", "deep"] as const)("identifies Bedrock account advisory applicability in the %s parent prompt",async (mode) => {diff --git a/sdk/typescript/tests-ts/bedrock-oss-pricing.test.ts b/sdk/typescript/tests-ts/bedrock-oss-pricing.test.tsnew file mode 100644index 000000000..57e46b217--- /dev/null+++ b/sdk/typescript/tests-ts/bedrock-oss-pricing.test.ts@@ -0,0 +1,53 @@+import { expect, test } from "bun:test";+import { estimateScanCost } from "../src/cost-model.js";++test.each([+ ["openai.gpt-oss-20b-1:0", "ap-southeast-2", 0.0721, 0.309],+ ["openai.gpt-oss-20b", "us-east-1", 0.07, 0.3],+ ["openai.gpt-oss-20b-1:0", "eu-west-2", 0.11, 0.47],+ ["openai.gpt-oss-safeguard-20b", "ap-southeast-2", 0.0721, 0.206],+ ["openai.gpt-oss-safeguard-120b", "ap-southeast-2", 0.1545, 0.618],+ ["openai.gpt-oss-120b", "us-gov-west-1", 0.18, 0.72],+ ["us-gov.openai.gpt-oss-120b-1:0", "us-gov-east-1", 0.18, 0.72],+ ["us-gov.openai.gpt-oss-20b-1:0", null, 0.084, 0.36],+] as const)(+ "prices Standard tokens for %s in %s",+ (model, region, input, output) => {+ const cost = estimateScanCost(+ model,+ {+ input_tokens: 3,+ cached_input_tokens: 1,+ cache_write_input_tokens: 1,+ output_tokens: 1,+ },+ region,+ );+ expect(cost?.pricing?.usdPerMillionTokens).toEqual({+ input,+ cacheRead: input,+ cacheWrite: input,+ output,+ });+ expect(cost?.estimatedUsd).toBeCloseTo(+ (3 * input + output) / 1_000_000,+ 16,+ );+ expect(cost?.estimatedUsdRange?.max).toBe(cost?.estimatedUsd);+ },+);++test.each([+ ["openai.gpt-oss-20b", undefined],+ ["openai.gpt-oss-20b", null],+ ["openai.gpt-oss-20b-1:0", "ap-southeast-4"],+ ["openai.gpt-oss-safeguard-20b", "us-gov-east-1"],+ ["us-gov.openai.gpt-oss-20b-1:0", "us-west-2"],+ ["us-gov.openai.gpt-oss-20b", "us-gov-east-1"],+ ["global.openai.gpt-oss-120b-1:0", "us-east-1"],+ ["openai.gpt-oss-safeguard-120b-1:0", "us-east-1"],+] as const)("keeps %s in %s unpriced", (model, region) => {+ expect(+ estimateScanCost(model, { input_tokens: 1, output_tokens: 1 }, region),+ ).toBeNull();+});diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.tsindex 7e710fa84..a6558936c 100644--- a/sdk/typescript/tests-ts/config.test.ts+++ b/sdk/typescript/tests-ts/config.test.ts@@ -11,6 +11,7 @@ import {modelProviderConfigOverride,resolveCodexProfile,resolveCommandAuthConfig,+ scanPricingContext,scanModelConfiguration,scanModelProvider,} from "../src/config.js";@@ -637,6 +638,74 @@ describe("Codex configuration", () => {}});+ test.each(["amazon-bedrock", "amazon-bedrock-runtime"])(+ "uses the selected %s provider's AWS region before the environment",+ (provider) => {+ const config = {+ profile: "gov",+ model_provider: "openai",+ model_providers: { [provider]: { aws: { region: "us-east-2" } } },+ profiles: {+ gov: {+ model_provider: provider,+ model_providers: {+ [provider]: { aws: { region: " us-gov-east-1 " } },+ },+ },+ },+ };+ expect(scanPricingContext(config, { AWS_REGION: "us-west-1" })).toEqual({+ provider: "amazon-bedrock",+ region: "us-gov-east-1",+ });+ },+ );++ test("resolves Bedrock environment regions and preserves an unknown region", () => {+ const config = { model_provider: "amazon-bedrock" };+ const environment = {+ AWS_REGION: "us-gov-west-1",+ AWS_DEFAULT_REGION: "us-east-1",+ };+ expect(scanPricingContext(config, environment)).toEqual({+ provider: "amazon-bedrock",+ region: "us-gov-west-1",+ });+ expect(+ scanPricingContext(config, { ...environment, AWS_REGION: " " }),+ ).toEqual({ provider: "amazon-bedrock", region: "us-east-1" });+ expect(scanPricingContext(config, { AWS_PROFILE: "synthetic" })).toEqual({+ provider: "amazon-bedrock",+ region: null,+ });+ expect(+ scanPricingContext({ model_provider: "openai" }, environment),+ ).toBeUndefined();+ });++ test.each([+ ["https://bedrock-mantle.us-gov-east-1.api.aws/openai/v1", "us-gov-east-1"],+ [+ "https://bedrock-runtime-fips.us-gov-west-1.amazonaws.com",+ "us-gov-west-1",+ ],+ ["https://gateway.example.test", null],+ ])(+ "uses the billing region from a Bedrock endpoint override %s",+ (baseUrl, region) => {+ const config = {+ model_provider: "amazon-bedrock",+ model_providers: {+ "amazon-bedrock": { base_url: baseUrl, aws: { region: "us-east-1" } },+ },+ };+ expect(scanPricingContext(config, { AWS_REGION: "us-west-2" })).toEqual({+ provider: "amazon-bedrock",+ region,+ });+ },+ );+test("rejects invalid model settings from the selected Codex profile", async () => {for (const [profile, message] of [[{ model: " " }, "model must be a nonempty string"],diff --git a/sdk/typescript/tests-ts/cost-context.test.ts b/sdk/typescript/tests-ts/cost-context.test.tsindex 2e10b1895..70ce0045e 100644--- a/sdk/typescript/tests-ts/cost-context.test.ts+++ b/sdk/typescript/tests-ts/cost-context.test.ts@@ -20,20 +20,18 @@ test.each(["%s bounds each token category with verified rates",(model, short, long) => {for (const category of [0, 1, 2, 3] as const) {- for (const selected of [model, `openai.${model}`]) {- const cost = estimateScanCost(selected, {- input_tokens: category === 3 ? 0 : 1_000_000,- cached_input_tokens: category === 1 ? 1_000_000 : 0,- cache_write_input_tokens: category === 2 ? 1_000_000 : 0,- output_tokens: category === 3 ? 1_000_000 : 0,- })!;- expect(cost.estimatedUsd).toBe(short[category]);- expect(cost.estimatedUsdRange).toEqual({- min: short[category],- max: long[category],- context: "unknown",- });- }+ const cost = estimateScanCost(model, {+ input_tokens: category === 3 ? 0 : 1_000_000,+ cached_input_tokens: category === 1 ? 1_000_000 : 0,+ cache_write_input_tokens: category === 2 ? 1_000_000 : 0,+ output_tokens: category === 3 ? 1_000_000 : 0,+ })!;+ expect(cost.estimatedUsd).toBe(short[category]);+ expect(cost.estimatedUsdRange).toEqual({+ min: short[category],+ max: long[category],+ context: "unknown",+ });}},);@@ -62,8 +60,8 @@ test("prices the exact Bedrock Daybreak Blue ID with AWS short and long contextestimatedUsdRange: { min: 6.138, max: 11.176, context: "unknown" },pricing: {source:- "https://docs.aws.amazon.com/en_en/bedrock/latest/userguide/model-card-openai-gpt-daybreak-blue-56-sol.html",- asOf: "2026-10-01",+ "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-daybreak-blue-56-sol.html",+ asOf: "2026-11-05",serviceTier: "standard",context: "short",usdPerMillionTokens: {@@ -135,8 +133,8 @@ test("prices the exact Bedrock Daybreak Red ID without inventing long-context raestimatedUsdRange: { min: 20.55625, max: null, context: "unknown" },pricing: {source:- "https://docs.aws.amazon.com/en_en/bedrock/latest/userguide/model-card-openai-gpt-56-cyber.html",- asOf: "2026-10-01",+ "https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-openai-gpt-56-cyber.html",+ asOf: "2026-11-05",serviceTier: "standard",context: "short",usdPerMillionTokens: {@@ -162,6 +160,69 @@ test.each([1, 3])(},);+// USD per million tokens in the AWS Standard short-context tables.+test.each([+ ["us.openai.gpt-5.4", "us-east-2", 2.75, 0.275, 2.75, 16.5],+ ["us.openai.gpt-5.5", "us-east-1", 5.5, 0.55, 5.5, 33],+ ["openai.gpt-5.4", "us-gov-west-1", 3.375, 0.3375, 3.375, 20.25],+ ["openai.gpt-5.6-cyber", "us-gov-east-1", 16.875, 1.6875, 21.09375, 101.25],+ ["openai.gpt-5.6-terra", "us-gov-west-1", 2.7, 0.27, 3.375, 16.2],+ ["us-gov.openai.gpt-5.6-luna", "us-gov-east-1", 0.27, 0.027, 0.3375, 1.62],+ ["openai.gpt-6.1-sol", "us-east-1", 2.2, 0.11, 2.75, 11],+ ["us.openai.gpt-6.1-sol", "us-east-1", 2.2, 0.11, 2.75, 11],+ ["global.openai.gpt-6.1-sol", "us-east-1", 2, 0.1, 2.5, 10],+] as const)(+ "uses the Standard rates for %s in %s",+ (model, region, input, cacheRead, cacheWrite, output) => {+ const cost = estimateScanCost(+ model,+ {+ input_tokens: 3,+ cached_input_tokens: 1,+ cache_write_input_tokens: 1,+ output_tokens: 1,+ },+ region,+ );+ expect(cost?.pricing?.usdPerMillionTokens).toEqual({+ input,+ cacheRead,+ cacheWrite,+ output,+ });+ expect(cost?.estimatedUsd).toBeCloseTo(+ (input + cacheRead + cacheWrite + output) / 1_000_000,+ 15,+ );+ },+);++test("keeps unverified Bedrock IDs, regions, and long-context rates unpriced", () => {+ const usage = { input_tokens: 1_000_000, output_tokens: 0 };+ for (const [model, region] of [+ ["global.openai.gpt-5.5", "us-east-1"],+ ["openai.gpt-6-cyber", "us-east-2"],+ ["gpt-5.6-cyber", "us-gov-east-1"],+ ["openai.gpt-5.5-2026-04-23", "us-east-1"],+ ["openai.gpt-5.6-cyber", "us-gov-west-1"],+ ["openai.gpt-daybreak-blue-5.6-sol", "us-gov-east-1"],+ ["global.openai.gpt-5.6-terra", "us-gov-west-1"],+ ] as const) {+ expect(estimateScanCost(model, usage, region)).toBeNull();+ }+ expect(+ estimateScanCost("openai.gpt-5.4", usage, "us-gov-west-1")+ ?.estimatedUsdRange,+ ).toEqual({ min: 3.375, max: null, context: "unknown" });+ expect(+ estimateScanCost(+ "openai.gpt-5.6-luna",+ { ...usage, cache_write_input_tokens: 0 },+ "us-gov-west-1",+ )?.estimatedUsdRange,+ ).toEqual({ min: 0.27, max: 0.54, context: "unknown" });+});+test("reports a range for cache-heavy scans without changing the budget baseline", () => {const cost = estimateScanCost("gpt-5.6-sol", {input_tokens: 150_000_000,diff --git a/sdk/typescript/tests-ts/cost-model.property.test.ts b/sdk/typescript/tests-ts/cost-model.property.test.tsindex aa9297265..7ed0a495e 100644--- a/sdk/typescript/tests-ts/cost-model.property.test.ts+++ b/sdk/typescript/tests-ts/cost-model.property.test.ts@@ -13,6 +13,9 @@ const rates = [["gpt-5.6-sol", 4000n, 400n, 5000n, 20000n],["gpt-5.6-terra", 2000n, 200n, 2500n, 12000n],["gpt-5.6-luna", 200n, 20n, 250n, 1200n],+ ["openai.gpt-6-sol", 2200n, 220n, 2750n, 11000n],+ ["openai.gpt-6.1-sol", 2200n, 110n, 2750n, 11000n],+ ["global.openai.gpt-6-sol", 2000n, 200n, 2500n, 10000n],["openai.gpt-daybreak-blue-5.6-sol", 4400n, 440n, 5500n, 22000n],] as const;const count = fc.integer({ min: 0, max: 1_000_000_000 });@@ -49,7 +52,7 @@ describe("cost-model invariants", () => {expect(formatUsd(1234.5)).toBe("$1,234.50");});- test("matches an integer nanodollar oracle for every priced model", () => {+ test("matches an integer nanodollar oracle for direct and Bedrock models", () => {fc.assert(fc.property(usageParts, (parts) => {const tokens = usage(parts);@@ -69,19 +72,14 @@ describe("cost-model invariants", () => {BigInt(parts.cached) * cachedRate +BigInt(parts.written) * writeRate +BigInt(parts.output) * outputRate;- const identifiers = model.startsWith("openai.")- ? [model]- : [model, `openai.${model}`];- for (const selected of identifiers) {- expect(estimateScanCost(selected, tokens)).toMatchObject({- model: selected,- inputTokens: tokens.input_tokens,- cachedInputTokens: parts.cached,- cacheWriteInputTokens: parts.written,- outputTokens: parts.output,- estimatedUsd: Number(nanos) / 1_000_000_000,- });- }+ expect(estimateScanCost(model, tokens)).toMatchObject({+ model,+ inputTokens: tokens.input_tokens,+ cachedInputTokens: parts.cached,+ cacheWriteInputTokens: parts.written,+ outputTokens: parts.output,+ estimatedUsd: Number(nanos) / 1_000_000_000,+ });}}),propertyOptions,diff --git a/sdk/typescript/tests-ts/cost.test.ts b/sdk/typescript/tests-ts/cost.test.tsindex 238db1766..649c48608 100644--- a/sdk/typescript/tests-ts/cost.test.ts+++ b/sdk/typescript/tests-ts/cost.test.ts@@ -2292,45 +2292,43 @@ describe("scan cost", () => {},});});- test.each(["gpt-6-sol", "openai.gpt-6-sol"])(- "prices every token category and both context ranges for %s",- (model) => {- expect(- estimateScanCost(model, {- input_tokens: 1_000_000,- cached_input_tokens: 200_000,- cache_write_input_tokens: 300_000,- output_tokens: 100_000,- }),- ).toEqual({- model,- inputTokens: 1_000_000,- cachedInputTokens: 200_000,- cacheWriteInputTokens: 300_000,- outputTokens: 100_000,- estimatedUsd: 2.79,- estimatedUsdRange: { min: 2.79, max: 5.08, context: "unknown" },- pricing: {- source: "https://developers.openai.com/api/docs/models/gpt-6-sol",- asOf: "2026-10-10",- serviceTier: "standard",- context: "short",- usdPerMillionTokens: {- input: 2,- cacheRead: 0.2,- cacheWrite: 2.5,- output: 10,- },- longContextUsdPerMillionTokens: {- input: 4,- cacheRead: 0.4,- cacheWrite: 5,- output: 15,- },+ test("prices every token category and both context ranges for gpt-6-sol", () => {+ const model = "gpt-6-sol";+ expect(+ estimateScanCost(model, {+ input_tokens: 1_000_000,+ cached_input_tokens: 200_000,+ cache_write_input_tokens: 300_000,+ output_tokens: 100_000,+ }),+ ).toEqual({+ model,+ inputTokens: 1_000_000,+ cachedInputTokens: 200_000,+ cacheWriteInputTokens: 300_000,+ outputTokens: 100_000,+ estimatedUsd: 2.79,+ estimatedUsdRange: { min: 2.79, max: 5.08, context: "unknown" },+ pricing: {+ source: "https://developers.openai.com/api/docs/models/gpt-6-sol",+ asOf: "2026-10-10",+ serviceTier: "standard",+ context: "short",+ usdPerMillionTokens: {+ input: 2,+ cacheRead: 0.2,+ cacheWrite: 2.5,+ output: 10,},- });- },- );+ longContextUsdPerMillionTokens: {+ input: 4,+ cacheRead: 0.4,+ cacheWrite: 5,+ output: 15,+ },+ },+ });+ });test.each([[{ cache_write_tokens: 15 }, 15],[{ cache_write_input_tokens: 0, cache_write_tokens: 15 }, 15],diff --git a/sdk/typescript/tests-ts/scan-dashboard.test.ts b/sdk/typescript/tests-ts/scan-dashboard.test.tsindex 83f16b329..b549b8f8e 100644--- a/sdk/typescript/tests-ts/scan-dashboard.test.ts+++ b/sdk/typescript/tests-ts/scan-dashboard.test.ts@@ -732,21 +732,35 @@ describe("live scan dashboard", () => {});test.each([- ["unknown-model", false],- ["gpt-5.6-cyber", true],- ] as const)("shows a cost row only when %s has pricing", (model, priced) => {- const stderr = capture(true);- const dashboard = createDashboard(stderr.stream, {- model: { model, reasoningEffort: "xhigh" },- showCost: true,- });- dashboard.start();- const frame = lastFrame(stderr);- expect(/^\s*COST\b/m.test(frame)).toBe(priced);- if (priced) expect(frame).toMatch(/COST\s+waiting for usage/);- expect(frame).not.toContain("model pricing missing");- dashboard.stop();- });+ ["unknown-model", undefined, false],+ ["gpt-5.6-cyber", undefined, true],+ [+ "openai.gpt-5.6-cyber",+ { provider: "amazon-bedrock", region: "us-gov-east-1" },+ true,+ ],+ [+ "openai.gpt-5.6-cyber",+ { provider: "amazon-bedrock", region: "us-gov-west-1" },+ false,+ ],+ ] as const)(+ "shows a cost row only when %s has pricing in %j",+ (model, pricingContext, priced) => {+ const stderr = capture(true);+ const dashboard = createDashboard(stderr.stream, {+ model: { model, reasoningEffort: "xhigh" },+ pricingContext,+ showCost: true,+ });+ dashboard.start();+ const frame = lastFrame(stderr);+ expect(/^\s*COST\b/m.test(frame)).toBe(priced);+ if (priced) expect(frame).toMatch(/COST\s+waiting for usage/);+ expect(frame).not.toContain("model pricing missing");+ dashboard.stop();+ },+ );test("keeps cost bounds and assumptions readable on a narrow terminal", () => {const stderr = capture(true);