Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(sdk): use published Vertex AI prices for managed OpenAI models (#2363)

Michael D'Angelo37c1a5fd341a
diff --git a/sdk/typescript/docs/cli.md b/sdk/typescript/docs/cli.md
index 9e16b0148..ae07272f6 100644
--- a/sdk/typescript/docs/cli.md
+++ b/sdk/typescript/docs/cli.md
@@ -280,6 +280,45 @@ See the [Bedrock guide](https://github.com/openai/codex-security/blob/main/docs/
for credential alternatives, restricted-model access, cost estimates, and
reasoning-summary configuration.
+### Google Cloud Vertex AI cost estimates
+
+The SDK estimates Standard online inference costs for OpenAI models served by
+Google Cloud's Model as a Service (MaaS). Rates are in USD per million tokens.
+[Google Cloud partner model pricing](https://cloud.google.com/model-garden/partner-models/pricing)
+and [OpenAI model locations](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/maas/openai).
+
+| Managed model ID | Location | Input | Cached input | Output |
+| -------------------------- | ----------------------- | ----: | -----------: | -----: |
+| `openai/gpt-oss-120b-maas` | `global` | $0.09 | $0.09 | $0.36 |
+| `openai/gpt-oss-20b-maas` | `us-central1` (retired) | $0.07 | $0.007 | $0.25 |
+
+Google publishes a cache-hit discount only for 20B, so the estimator uses the
+ordinary input rate for cached 120B tokens. Google retired the managed 20B
+endpoint on October 21, 2026. The SDK retains its rates for historical usage.
+[Google Cloud retirement schedule](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/deprecations/open-models).
+
+To estimate recorded usage locally, pass the managed model ID and the GCP
+provider to `estimateScanCost`.
+
+```ts
+import { estimateScanCost } from "@openai/codex-security";
+
+const cost = estimateScanCost(
+ "openai/gpt-oss-120b-maas",
+ { input_tokens: 1_000_000, output_tokens: 500_000 },
+ { provider: "gcp" },
+);
+// cost?.estimatedUsd is 0.27.
+```
+
+Google documents the managed GPT OSS IDs on its shared chat-completions API.
+The bundled Codex `gcp` provider uses Google's Responses API with a separate
+frontier model catalog. Google has published no Standard token rates for that
+catalog, including GPT-6 Astra, GPT-6.1 Sol, GPT-6.1 Terra, and GPT-6 Luna.
+Those scans record token usage and require a published price to use
+`--max-cost`. Self-deployed Model Garden endpoints incur infrastructure charges.
+[Google Cloud's preview announcement](https://cloud.google.com/blog/products/ai-machine-learning/google-cloud-brings-openai-models-to-customers).
+
## Generate a security policy
Use `policy` to draft or update `SECURITY.md` before a scan. The policy describes
@@ -1143,6 +1182,7 @@ mean allowance was unavailable. There is no token-to-allowance conversion here.
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).
+For managed OpenAI models on Vertex AI, see [Google Cloud Vertex AI cost estimates](#google-cloud-vertex-ai-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.
diff --git a/sdk/typescript/scripts/package-dist-files.mjs b/sdk/typescript/scripts/package-dist-files.mjs
index 064f43def..a4387076b 100644
--- a/sdk/typescript/scripts/package-dist-files.mjs
+++ b/sdk/typescript/scripts/package-dist-files.mjs
@@ -79,6 +79,7 @@ const distModules = [
"cost-model",
"bedrock-pricing",
"bedrock-oss-pricing",
+ "vertex-pricing",
"coverage-presentation",
"custom-validation",
"custom-validation-prompt",
diff --git a/sdk/typescript/src/api.ts b/sdk/typescript/src/api.ts
index 6f4c62b2f..87541bbb6 100644
--- a/sdk/typescript/src/api.ts
+++ b/sdk/typescript/src/api.ts
@@ -6282,7 +6282,11 @@ async function prepareScanOutputDir(
}
function turnPricingMetadata(context?: ScanPricingContext) {
- return context === undefined ? {} : { bedrockRegion: context.region };
+ if (context === undefined) return {};
+ // Preserve the region field written on Bedrock scan results.
+ return context.provider === "amazon-bedrock"
+ ? { bedrockRegion: context.region }
+ : { pricingContext: context };
}
function validateScanCostLimit(
@@ -6298,8 +6302,16 @@ function validateScanCostLimit(
pricingContext,
) === null
) {
- const region = pricingContext?.region;
- const location = region ? ` in ${region}` : "";
+ const region =
+ pricingContext?.provider === "amazon-bedrock"
+ ? pricingContext.region
+ : undefined;
+ const location =
+ pricingContext?.provider === "gcp"
+ ? " on Google Cloud"
+ : region
+ ? ` in ${region}`
+ : "";
const detail =
region === null
? " Set the Bedrock billing region to check its regional price."
diff --git a/sdk/typescript/src/config.ts b/sdk/typescript/src/config.ts
index 0f679535d..4bcba8873 100644
--- a/sdk/typescript/src/config.ts
+++ b/sdk/typescript/src/config.ts
@@ -152,19 +152,47 @@ 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 selected = scanModelProvider(config) ?? "openai";
+ if (typeof selected !== "string") 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),
- };
+ if (selected === "amazon-bedrock" || selected === "amazon-bedrock-runtime") {
+ return {
+ provider: "amazon-bedrock",
+ region: bedrockPricingRegion(provider, environment),
+ };
+ }
+ // Native Codex only accepts inference routing for the built-in OpenAI
+ // provider through the top-level openai_base_url setting.
+ const baseUrl =
+ selected === "openai"
+ ? resolved["openai_base_url"]
+ : isObject(provider)
+ ? provider["base_url"]
+ : undefined;
+ if (baseUrl == null)
+ return selected === "gcp" ? { provider: "gcp" } : undefined;
+
+ const url = typeof baseUrl === "string" ? URL.parse(baseUrl) : null;
+ const host = url?.hostname.replace(/\.$/, "") ?? "";
+ if (host.endsWith(".prediction.vertexai.goog")) {
+ return { provider: "gcp", managedEndpoint: false };
+ }
+ const vertexHost =
+ url &&
+ /^(?:[a-z0-9-]+-)?aiplatform(?:\.mtls)?\.googleapis\.com$/.test(host);
+ if (selected !== "gcp" && !vertexHost) return undefined;
+ // A dedicated endpoint bills the serving infrastructure. Only publisher and
+ // shared OpenAPI endpoints identify the managed token-based service.
+ const managedEndpoint =
+ !!vertexHost &&
+ /^\/v1(?:beta1)?\/projects\/[^/]+\/locations\/[^/]+\/(?:publishers\/openai\/v1|endpoints\/openapi)\/?$/.test(
+ url.pathname,
+ );
+ return { provider: "gcp", managedEndpoint };
}
/** @internal Use the selected native provider's configured credential key. */
diff --git a/sdk/typescript/src/cost-model.ts b/sdk/typescript/src/cost-model.ts
index 752e51c29..705141bcb 100644
--- a/sdk/typescript/src/cost-model.ts
+++ b/sdk/typescript/src/cost-model.ts
@@ -1,11 +1,11 @@
+import { vertexModelPricing } from "./vertex-pricing.js";
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 type ScanPricingContext =
+ | { provider: "amazon-bedrock"; region: string | null }
+ | { provider: "gcp"; managedEndpoint?: boolean };
export interface ScanCost {
model: string;
@@ -143,6 +143,22 @@ export function tokenUsage(value: unknown): ScanTokenUsage | null {
};
}
+function providerModelPricing(
+ model: string,
+ context?: ScanPricingContext | string | null,
+) {
+ if (context == null || typeof context === "string") {
+ return bedrockModelPricing(model, context);
+ }
+ if (context.provider === "amazon-bedrock") {
+ return bedrockModelPricing(model, context.region);
+ }
+ if (context.provider === "gcp" && context.managedEndpoint !== false) {
+ return vertexModelPricing(model);
+ }
+ return undefined;
+}
+
/**
* Estimates Standard token costs using the selected provider's published rates.
* A string (or null for an unknown region) selects Bedrock for compatibility.
@@ -154,9 +170,7 @@ export function estimateScanCost(
context?: ScanPricingContext | string | null,
): ScanCost | null {
if (model === undefined) return null;
- const region =
- typeof context === "object" && context !== null ? context.region : context;
- const providerPricing = bedrockModelPricing(model, region);
+ const providerPricing = providerModelPricing(model, context);
const unitsPerUsd = providerPricing?.unitsPerUsd ?? 1_000_000_000;
const pricing =
providerPricing?.short ??
diff --git a/sdk/typescript/src/result.ts b/sdk/typescript/src/result.ts
index 31fca3fe6..957e7b0fb 100644
--- a/sdk/typescript/src/result.ts
+++ b/sdk/typescript/src/result.ts
@@ -1,3 +1,4 @@
+import type { ScanPricingContext } from "./cost-model.js";
import { statSync } from "node:fs";
import { join } from "node:path";
import type {
@@ -15,6 +16,7 @@ export interface TurnResultMetadata {
id?: string;
status?: string;
model?: string;
+ pricingContext?: ScanPricingContext;
/** Source region recorded for Bedrock scans. */
bedrockRegion?: string | null;
durationMs?: number;
@@ -93,7 +95,7 @@ export class ScanResult {
estimateScanCost(
options.turnResult.model,
options.turnResult.usage,
- options.turnResult.bedrockRegion,
+ options.turnResult.pricingContext ?? options.turnResult.bedrockRegion,
);
if (options.sarifPath !== undefined) {
this.sarifPath = options.sarifPath;
diff --git a/sdk/typescript/src/vertex-pricing.ts b/sdk/typescript/src/vertex-pricing.ts
new file mode 100644
index 000000000..df1ea6cf3
--- /dev/null
+++ b/sdk/typescript/src/vertex-pricing.ts
@@ -0,0 +1,27 @@
+// Standard MaaS prices in nanodollars per token. Google lists one price
+// across each model's 131,072-token context window. Only 20B discounts
+// implicit cache hits. Keep its rates for scans made before its retirement.
+const rates = new Map<
+ string,
+ readonly [
+ input: number,
+ cacheRead: number,
+ cacheWrite: number,
+ output: number,
+ ]
+>([
+ ["gpt-oss-20b-maas", [70, 7, 70, 250]],
+ ["gpt-oss-120b-maas", [90, 90, 90, 360]],
+]);
+
+export function vertexModelPricing(model: string) {
+ const price = rates.get(model.replace(/^openai\//, ""));
+ if (!price) return undefined;
+ return {
+ short: price,
+ long: price,
+ unitsPerUsd: 1_000_000_000,
+ source: "https://cloud.google.com/model-garden/partner-models/pricing",
+ asOf: "2026-11-05",
+ };
+}
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index e9d763f1a..4d86cad7f 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -14470,13 +14470,20 @@ if __name__ == "__main__":
}
});
- test("reports unpriced model usage without letting its observer stop the scan", async () => {
+ test("reports unpriced GCP usage without letting its observer stop the scan", async () => {
const { root, repository, codexHome, scanDir } = await scanDirectories();
const usages: unknown[] = [];
const observerErrors: string[] = [];
const commands: Array<readonly string[]> = [];
const client = new TestClient(
- { codexOverrides: { model: "synthetic-unpriced-model" } },
+ {
+ codexOverrides: {
+ model: "gpt-6-astra",
+ model_provider: "openai",
+ profile: "review",
+ profiles: { review: { model_provider: "gcp" } },
+ },
+ },
{
...scanRuntimeDependencies(codexHome, scanDir),
runWorkbench: recordingWorkbench(commands),
@@ -14484,6 +14491,13 @@ if __name__ == "__main__":
},
);
try {
+ 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: "gpt-6-astra",
+ modelProvider: "gcp",
+ });
const result = await client.run(repository, {
onUsage: async (usage) => {
usages.push(usage);
@@ -14516,9 +14530,15 @@ if __name__ == "__main__":
}
});
const prices = [
- { model: "gpt-6-astra", min: 0.000232, max: 0.000429 },
- { model: "gpt-6-cyber", min: 0.000464, max: null },
- { model: "gpt-5.6-cyber", min: 0.0003275, max: null },
+ { model: "gpt-6-astra", provider: "openai", min: 0.000232, max: 0.000429 },
+ { model: "gpt-6-cyber", provider: "openai", min: 0.000464, max: null },
+ { model: "gpt-5.6-cyber", provider: "openai", min: 0.0003275, max: null },
+ {
+ model: "openai/gpt-oss-120b-maas",
+ provider: "gcp",
+ min: 0.00000198,
+ max: 0.00000198,
+ },
];
test.each(prices)("tracks live and saved $model costs", async (price) => {
const { model, min, max } = price;
@@ -14535,6 +14555,7 @@ if __name__ == "__main__":
profiles: {
review: {
model,
+ model_provider: price.provider,
model_reasoning_effort: "high",
},
},
diff --git a/sdk/typescript/tests-ts/config.test.ts b/sdk/typescript/tests-ts/config.test.ts
index a6558936c..2670f2509 100644
--- a/sdk/typescript/tests-ts/config.test.ts
+++ b/sdk/typescript/tests-ts/config.test.ts
@@ -706,6 +706,65 @@ describe("Codex configuration", () => {
},
);
+ test("distinguishes managed Vertex APIs from dedicated endpoints and other gateways", () => {
+ const base =
+ "https://us-central1-aiplatform.googleapis.com/v1beta1/projects/example/locations/us-central1";
+ const fromUrl = (baseUrl: string) =>
+ scanPricingContext({ openai_base_url: baseUrl }, {});
+ expect(fromUrl(`${base}/endpoints/openapi`)).toEqual({
+ provider: "gcp",
+ managedEndpoint: true,
+ });
+ expect(fromUrl(`${base}/endpoints/1234`)).toEqual({
+ provider: "gcp",
+ managedEndpoint: false,
+ });
+ expect(
+ fromUrl("https://123.us-central1-example.prediction.vertexai.goog"),
+ ).toEqual({ provider: "gcp", managedEndpoint: false });
+ expect(
+ fromUrl(
+ "https://aiplatform.mtls.googleapis.com./v1/projects/example/locations/global/endpoints/openapi",
+ ),
+ ).toEqual({ provider: "gcp", managedEndpoint: true });
+ expect(fromUrl("https://gateway.example.test")).toBeUndefined();
+ expect(
+ scanPricingContext(
+ { model_providers: { openai: { base_url: base } } },
+ { OPENAI_BASE_URL: base },
+ ),
+ ).toBeUndefined();
+ const config = {
+ profile: "review",
+ profiles: {
+ review: {
+ model_provider: "vertex",
+ model_providers: {
+ vertex: {
+ base_url:
+ "https://aiplatform.googleapis.com/v1/projects/example/locations/global/publishers/openai/v1/",
+ },
+ },
+ },
+ },
+ };
+ expect(scanPricingContext(config, {})).toEqual({
+ provider: "gcp",
+ managedEndpoint: true,
+ });
+ expect(
+ scanPricingContext(
+ {
+ model_provider: "gcp",
+ model_providers: {
+ gcp: { base_url: "https://gateway.example.test" },
+ },
+ },
+ {},
+ ),
+ ).toEqual({ provider: "gcp", managedEndpoint: false });
+ });
+
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/scan-dashboard.test.ts b/sdk/typescript/tests-ts/scan-dashboard.test.ts
index b549b8f8e..8587dd858 100644
--- a/sdk/typescript/tests-ts/scan-dashboard.test.ts
+++ b/sdk/typescript/tests-ts/scan-dashboard.test.ts
@@ -744,6 +744,8 @@ describe("live scan dashboard", () => {
{ provider: "amazon-bedrock", region: "us-gov-west-1" },
false,
],
+ ["gpt-6-astra", { provider: "gcp" }, false],
+ ["openai/gpt-oss-120b-maas", { provider: "gcp" }, true],
] as const)(
"shows a cost row only when %s has pricing in %j",
(model, pricingContext, priced) => {
diff --git a/sdk/typescript/tests-ts/vertex-pricing.test.ts b/sdk/typescript/tests-ts/vertex-pricing.test.ts
new file mode 100644
index 000000000..d6750b783
--- /dev/null
+++ b/sdk/typescript/tests-ts/vertex-pricing.test.ts
@@ -0,0 +1,56 @@
+import { expect, test } from "bun:test";
+import { estimateScanCost } from "../src/cost-model.js";
+
+const usage = {
+ input_tokens: 16_000,
+ cached_input_tokens: 8_000,
+ cache_write_input_tokens: 2_000,
+ output_tokens: 1_000,
+};
+
+test.each([
+ ["gpt-oss-20b-maas", 0.07, 0.007, 0.25, 0.000866],
+ ["gpt-oss-120b-maas", 0.09, 0.09, 0.36, 0.0018],
+] as const)(
+ "estimates Vertex Standard usage for %s",
+ (id, input, cacheRead, output, cost) => {
+ for (const model of [id, `openai/${id}`]) {
+ const estimate = estimateScanCost(model, usage, { provider: "gcp" });
+ expect(estimate).toMatchObject({
+ model,
+ estimatedUsd: cost,
+ estimatedUsdRange: { min: cost, max: cost },
+ pricing: {
+ source:
+ "https://cloud.google.com/model-garden/partner-models/pricing",
+ serviceTier: "standard",
+ usdPerMillionTokens: { input, cacheRead, cacheWrite: input, output },
+ },
+ });
+ }
+ },
+);
+
+test.each([
+ "gpt-oss-20b",
+ "openai/gpt-oss-120b",
+ "gpt-oss-20b-maas:latest",
+ "meta/gpt-oss-20b-maas",
+ "gpt-6-sol",
+ "openai.gpt-5.6-cyber",
+])("leaves GCP usage for %s unpriced", (model) => {
+ expect(estimateScanCost(model, usage, { provider: "gcp" })).toBeNull();
+});
+
+test("requires a managed Vertex billing context for MaaS prices", () => {
+ expect(estimateScanCost("openai/gpt-oss-120b-maas", usage)).toBeNull();
+ expect(
+ estimateScanCost("openai/gpt-oss-120b-maas", usage, {
+ provider: "gcp",
+ managedEndpoint: false,
+ }),
+ ).toBeNull();
+ expect(
+ estimateScanCost("openai/gpt-oss-20b-maas", usage, "us-east-1"),
+ ).toBeNull();
+});