Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/api/src/routes/keys-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export const providerKeySchema = z.object({
alibaba_region: z
.enum(["singapore", "us-virginia", "cn-beijing"])
.optional(),
aws_mantle_region: z
.enum(["us-east-1", "us-east-2", "us-west-2"])
.optional(),
vertex_openai_project_id: z.string().optional(),
})
.nullable(),
Expand Down Expand Up @@ -244,6 +247,9 @@ const createProviderKeySchema = z.object({
alibaba_region: z
.enum(["singapore", "us-virginia", "cn-beijing"])
.optional(),
aws_mantle_region: z
.enum(["us-east-1", "us-east-2", "us-west-2"])
.optional(),
google_vertex_project_id: z.string().optional(),
vertex_openai_project_id: z.string().optional(),
})
Expand Down
144 changes: 143 additions & 1 deletion apps/gateway/src/lib/openai-gpt56-pricing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, expect, it } from "vitest";

import { models, type ProviderModelMapping } from "@llmgateway/models";
import {
expandProviderRegions,
models,
providers,
type ProviderModelMapping,
} from "@llmgateway/models";

// OpenAI GPT-5.6 pricing invariants per
// https://developers.openai.com/api/docs/pricing and
Expand Down Expand Up @@ -118,3 +123,140 @@ describe("OpenAI GPT-5.6 family pricing", () => {
},
);
});

// Bedrock Mantle in-region inference is priced at OpenAI's data-residency
// tier, a flat 10% premium over the first-party rates, and AWS caps the
// deployment at a 272 * 1024 token context (upstream rejects prompts of
// 278528 tokens or more), so the over-272K tier can never apply.
const BEDROCK_PREMIUM = 1.1;
const MANTLE_CONTEXT_SIZE = 272 * 1024;

describe("GPT-5.6 on AWS Bedrock Mantle", () => {
const mantleEntries = models.flatMap((model) =>
model.id.startsWith("gpt-5.6")
? model.providers
.filter((provider) => provider.providerId === "aws-mantle")
.map((provider) => ({
modelId: model.id,
provider: provider as ProviderModelMapping,
openai: model.providers.find(
(p) => p.providerId === "openai",
) as ProviderModelMapping,
}))
: [],
);

it("has the three aws-mantle mappings to validate", () => {
expect(mantleEntries.map((e) => e.modelId).sort()).toEqual([
"gpt-5.6-luna",
"gpt-5.6-sol",
"gpt-5.6-terra",
]);
});

it.each(mantleEntries)(
"$modelId bills at a 10% premium over the first-party rates",
({ modelId, provider, openai }) => {
expectRatio(
`${modelId} aws-mantle inputPrice`,
provider.inputPrice,
openai.inputPrice,
BEDROCK_PREMIUM,
);
expectRatio(
`${modelId} aws-mantle outputPrice`,
provider.outputPrice,
openai.outputPrice,
BEDROCK_PREMIUM,
);
expectRatio(
`${modelId} aws-mantle cachedInputPrice`,
provider.cachedInputPrice,
openai.cachedInputPrice,
BEDROCK_PREMIUM,
);
expectRatio(
`${modelId} aws-mantle cacheWriteInputPrice`,
provider.cacheWriteInputPrice,
openai.cacheWriteInputPrice,
BEDROCK_PREMIUM,
);
// The 1.25x cache-write relationship survives the premium.
expectRatio(
`${modelId} aws-mantle cacheWriteInputPrice vs inputPrice`,
provider.cacheWriteInputPrice,
provider.inputPrice,
CACHE_WRITE_MULTIPLIER,
);
},
);

it.each(mantleEntries)(
"$modelId caps the context at 272 * 1024 with no long-context tier",
({ modelId, provider }) => {
expect(provider.contextSize, `${modelId}: aws-mantle context size`).toBe(
MANTLE_CONTEXT_SIZE,
);
expect(provider.pricingTiers).toBeUndefined();
},
);

// Sol is not deployed to us-west-2 — that region 404s "The model
// 'openai.gpt-5.6-sol' does not exist" — while Terra and Luna are in all
// three. Mantle offers no cross-region profiles, so no "global"/"us" entry
// may appear here.
const EXPECTED_REGIONS: Record<string, string[]> = {
"gpt-5.6-sol": ["us-east-1", "us-east-2"],
"gpt-5.6-terra": ["us-east-1", "us-east-2", "us-west-2"],
"gpt-5.6-luna": ["us-east-1", "us-east-2", "us-west-2"],
};

it.each(mantleEntries)(
"$modelId declares exactly the regions AWS deploys it to",
({ modelId, provider }) => {
expect(provider.regions?.map((r) => r.id)).toEqual(
EXPECTED_REGIONS[modelId],
);
},
);

it("only offers concrete AWS regions, never a cross-region profile", () => {
const def = providers.find((p) => p.id === "aws-mantle");
const configured = def?.regionConfig?.regions.map((r) => r.id) ?? [];

expect(configured).toEqual(["us-east-1", "us-east-2", "us-west-2"]);
// A synthetic default like aws-bedrock's `global` would be unroutable:
// Mantle has no cross-region inference profiles.
expect(def?.regionConfig?.pinDefaultRegion).toBeUndefined();
expect(configured).not.toContain("global");
// Every declared region needs an endpoint, and every model region must be
// one the provider actually configures.
for (const region of configured) {
expect(def?.regionConfig?.endpointMap[region]).toBe(
`https://bedrock-mantle.${region}.api.aws`,
);
}
const usedRegions = new Set(
mantleEntries.flatMap((e) => e.provider.regions?.map((r) => r.id) ?? []),
);
expect([...usedRegions].sort()).toEqual(configured);
});

it("expands each region without altering pricing", () => {
for (const { modelId, provider } of mantleEntries) {
const expanded = expandProviderRegions(provider);
// synthetic root + one entry per region
expect(expanded).toHaveLength(
(EXPECTED_REGIONS[modelId]?.length ?? 0) + 1,
);
for (const entry of expanded) {
expect(entry.inputPrice, `${modelId} ${entry.region}`).toBe(
provider.inputPrice,
);
expect(entry.outputPrice, `${modelId} ${entry.region}`).toBe(
provider.outputPrice,
);
}
}
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
});
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ export function CreateProviderKeyDialog({
</SelectContent>
</Select>
<p className="text-sm text-muted-foreground">
API keys are region-specific. Make sure your key matches the
selected region.
{selectedProviderDef.regionConfig.sharedCredentialAcrossRegions
? "One key works across every region for this provider."
: "API keys are region-specific. Make sure your key matches the selected region."}
</p>
</div>
)}
Expand Down
69 changes: 69 additions & 0 deletions packages/actions/src/get-provider-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,4 +834,73 @@ describe("getProviderEndpoint", () => {
);
});
});

describe("aws-mantle regions", () => {
it.each([
{ region: "us-east-1" },
{ region: "us-east-2" },
{ region: "us-west-2" },
])("routes to the $region Mantle endpoint", ({ region }) => {
const endpoint = getProviderEndpoint(
"aws-mantle",
undefined,
"openai.gpt-5.6-terra",
undefined,
false,
undefined,
undefined,
undefined,
undefined,
undefined,
region,
true,
);

expect(endpoint).toBe(
`https://bedrock-mantle.${region}.api.aws/openai/v1/responses`,
);
});

it("falls back to us-east-1 when no region is selected", () => {
const endpoint = getProviderEndpoint(
"aws-mantle",
undefined,
"openai.gpt-5.6-sol",
undefined,
false,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
true,
);

expect(endpoint).toBe(
"https://bedrock-mantle.us-east-1.api.aws/openai/v1/responses",
);
});

it("keeps an explicit base URL over the region-derived endpoint", () => {
const endpoint = getProviderEndpoint(
"aws-mantle",
"https://mantle-proxy.internal",
"openai.gpt-5.6-luna",
undefined,
false,
undefined,
undefined,
undefined,
undefined,
undefined,
"us-west-2",
true,
);

expect(endpoint).toBe(
"https://mantle-proxy.internal/openai/v1/responses",
);
});
});
});
12 changes: 8 additions & 4 deletions packages/actions/src/get-provider-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,19 @@ export function getProviderEndpoint(
}
case "aws-mantle": {
// Bedrock Mantle: OpenAI frontier models on AWS, Responses API only.
// GPT-5.6 Sol is deployed in us-east-1/us-east-2 only (Terra/Luna
// additionally in us-west-2), so default to us-east-1 where the
// whole family is available.
// The selected region normally resolves through regionConfig's
// endpointMap; the env var stays supported as a deployment-level
// override, and us-east-1 is the fallback because it is the only
// region carrying the whole GPT-5.6 family (Sol is not in us-west-2).
const envBaseUrl = skipEnvVars
? undefined
: getProviderEnvValue("aws-mantle", "baseUrl", configIndex);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const mantleRegion =
envValueOrDefault("aws-mantle", "region", "us-east-1") ?? "us-east-1";
url = envBaseUrl ?? `https://bedrock-mantle.${mantleRegion}.api.aws`;
url =
envBaseUrl ??
regionBaseUrl ??
`https://bedrock-mantle.${mantleRegion}.api.aws`;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
break;
}
case "azure": {
Expand Down
1 change: 1 addition & 0 deletions packages/db/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ export interface ProviderKeyOptions {
azure_ai_foundry_resource?: string;
azure_ai_foundry_api_version?: string;
alibaba_region?: "singapore" | "us-virginia" | "cn-beijing";
aws_mantle_region?: "us-east-1" | "us-east-2" | "us-west-2";
google_vertex_project_id?: string;
google_vertex_token_type?: "api-key" | "oauth";
vertex_openai_project_id?: string;
Expand Down
74 changes: 59 additions & 15 deletions packages/models/src/models/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1944,14 +1944,28 @@ export const openaiModels = [
{
providerId: "aws-mantle",
externalId: "openai.gpt-5.6-sol",
inputPrice: "5.0e-6",
outputPrice: "30.0e-6",
cachedInputPrice: "0.5e-6",
cacheWriteInputPrice: "6.25e-6",
// Sol is the one family member AWS has not deployed to us-west-2 —
// that region 404s with "The model 'openai.gpt-5.6-sol' does not
// exist". Pricing is identical across regions, so the entries carry
// no per-region overrides.
regions: [{ id: "us-east-1" }, { id: "us-east-2" }],
// Mantle is in-region-only (the model cards list Geo and Global
// cross-region as unsupported, and AWS lists global cross-region
// pricing as "coming soon"), and AWS prices in-region inference at
// OpenAI's data-residency tier — a flat 10% premium over the
// standard first-party rates. Unlike the usual Bedrock geo/global
// split there is no cheaper global rate to route to yet.
// AWS displays the cache-write rate rounded to $6.88/M.
inputPrice: "5.5e-6",
outputPrice: "33.0e-6",
cachedInputPrice: "0.55e-6",
cacheWriteInputPrice: "6.875e-6",
requestPrice: "0",
// AWS caps the Mantle deployment at a 272K context (vs 1.05M
// first-party), so OpenAI's over-272K pricing tier never applies.
contextSize: 272000,
// AWS's "272K" is 272 * 1024: upstream rejects prompts of 278528
// tokens or more.
contextSize: 278528,
maxOutput: 128000,
streaming: true,
// Bedrock Mantle only accepts data:/s3:// image URLs; the gateway
Expand Down Expand Up @@ -2089,14 +2103,29 @@ export const openaiModels = [
{
providerId: "aws-mantle",
externalId: "openai.gpt-5.6-terra",
inputPrice: "2.0e-6",
outputPrice: "12.0e-6",
cachedInputPrice: "0.2e-6",
cacheWriteInputPrice: "2.5e-6",
// Pricing is identical across regions, so the entries carry no
// per-region overrides.
regions: [
{ id: "us-east-1" },
{ id: "us-east-2" },
{ id: "us-west-2" },
],
// Mantle is in-region-only (the model cards list Geo and Global
// cross-region as unsupported, and AWS lists global cross-region
// pricing as "coming soon"), and AWS prices in-region inference at
// OpenAI's data-residency tier — a flat 10% premium over the
// standard first-party rates. Unlike the usual Bedrock geo/global
// split there is no cheaper global rate to route to yet.
inputPrice: "2.2e-6",
outputPrice: "13.2e-6",
cachedInputPrice: "0.22e-6",
cacheWriteInputPrice: "2.75e-6",
requestPrice: "0",
// AWS caps the Mantle deployment at a 272K context (vs 1.05M
// first-party), so OpenAI's over-272K pricing tier never applies.
contextSize: 272000,
// AWS's "272K" is 272 * 1024: upstream rejects prompts of 278528
// tokens or more.
contextSize: 278528,
maxOutput: 128000,
streaming: true,
// Bedrock Mantle only accepts data:/s3:// image URLs; the gateway
Expand Down Expand Up @@ -2234,14 +2263,29 @@ export const openaiModels = [
{
providerId: "aws-mantle",
externalId: "openai.gpt-5.6-luna",
inputPrice: "0.2e-6",
outputPrice: "1.2e-6",
cachedInputPrice: "0.02e-6",
cacheWriteInputPrice: "0.25e-6",
// Pricing is identical across regions, so the entries carry no
// per-region overrides.
regions: [
{ id: "us-east-1" },
{ id: "us-east-2" },
{ id: "us-west-2" },
],
// Mantle is in-region-only (the model cards list Geo and Global
// cross-region as unsupported, and AWS lists global cross-region
// pricing as "coming soon"), and AWS prices in-region inference at
// OpenAI's data-residency tier — a flat 10% premium over the
// standard first-party rates. Unlike the usual Bedrock geo/global
// split there is no cheaper global rate to route to yet.
inputPrice: "0.22e-6",
outputPrice: "1.32e-6",
cachedInputPrice: "0.022e-6",
cacheWriteInputPrice: "0.275e-6",
requestPrice: "0",
// AWS caps the Mantle deployment at a 272K context (vs 1.05M
// first-party), so OpenAI's over-272K pricing tier never applies.
contextSize: 272000,
// AWS's "272K" is 272 * 1024: upstream rejects prompts of 278528
// tokens or more.
contextSize: 278528,
maxOutput: 128000,
streaming: true,
// Bedrock Mantle only accepts data:/s3:// image URLs; the gateway
Expand Down
Loading
Loading