@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
172 lines • 7.68 kB
JavaScript
const ARN = /^arn:(aws|aws-us-gov|aws-cn):bedrock:([a-z0-9-]*):(\d*):(inference-profile|foundation-model|application-inference-profile)\/(.+)$/;
/** Cross-region inference profile prefixes. `us-gov` before `us`: the alternation is ordered. */
const GEO = /^(us-gov|us|eu|apac|au|jp|ca|in|global)\.(?=[a-z0-9-]+\.)/;
/** The partition an AWS region belongs to; `undefined` for an empty / missing region. */
export function awsPartitionOfRegion(region) {
if (region === undefined || region.length === 0)
return undefined;
if (region.startsWith('us-gov-'))
return 'aws-us-gov';
if (region.startsWith('cn-'))
return 'aws-cn';
return 'aws';
}
/**
* Parse a Bedrock model id: an ARN (`arn:aws[-us-gov|-cn]:bedrock:<region>:<acct>:(inference-profile|
* foundation-model|application-inference-profile)/<id>`), a geo-prefixed inference profile, or a base
* id. Returns `undefined` for an id that is not Bedrock-shaped (no ARN, no geo prefix) — a plain
* `gpt-4o-mini` is not guessed at.
*/
export function parseBedrockModelId(modelId) {
const arn = ARN.exec(modelId);
const profileId = arn !== null ? arn[5] : modelId;
const geo = GEO.exec(profileId)?.[1];
if (arn === null && geo === undefined)
return undefined;
const region = arn !== null && arn[2] !== '' ? arn[2] : undefined;
const isAppProfile = arn?.[4] === 'application-inference-profile';
const baseId = isAppProfile
? undefined
: geo !== undefined
? profileId.slice(geo.length + 1)
: profileId;
const partition = arn?.[1] ??
awsPartitionOfRegion(region) ??
(geo === 'us-gov' ? 'aws-us-gov' : undefined);
return { modelId, profileId, baseId, geo, region, partition, isArn: arn !== null };
}
/** Whether a model is reached through Bedrock: its provider says so, or its id is Bedrock-shaped. */
export function isBedrockModel(modelId, provider) {
if (provider !== undefined && /bedrock/i.test(provider))
return true;
return parseBedrockModelId(modelId) !== undefined;
}
/**
* The ids to look a Bedrock model's price up under, most specific first: the full id, the profile id
* (the ARN's resource), then the base foundation-model id. Deduplicated. A non-Bedrock-shaped id is
* its own only candidate.
*/
export function bedrockPriceCandidates(modelId) {
const parsed = parseBedrockModelId(modelId);
const out = [modelId];
if (parsed === undefined)
return out;
for (const id of [parsed.profileId, parsed.baseId]) {
if (id !== undefined && id.length > 0 && !out.includes(id))
out.push(id);
}
return out;
}
/** Where the built-in prices below come from, for the log and the docs. */
export const BEDROCK_BUILTIN_PRICES_SOURCE = 'AWS Price List, us-gov-west-1: AmazonBedrockFoundationModels published 2026-10-08 (Anthropic), AmazonBedrock published 2026-10-06 (Amazon, Meta, OpenAI, NVIDIA, xAI) — on-demand, standard (in-region) tier, standard context';
/**
* Built-in Bedrock prices (USD per 1M tokens) for partitions models.dev does not cover, keyed by base
* foundation-model id. Small and curated on purpose — it goes stale, so an app's own
* `priceCatalog.prices` (or a row it set) always wins over it. Commercial (`aws`) is not listed: it
* comes from models.dev. China (`aws-cn`) bills in CNY and is not covered: such a model is warned
* about and left unpriced until the app supplies a price.
*/
export const BEDROCK_BUILTIN_PRICES = {
'aws-us-gov': {
'anthropic.claude-3-haiku-20240307-v1:0': { inputPricePer1m: 0.3, outputPricePer1m: 1.5 },
'anthropic.claude-3-5-sonnet-20240620-v1:0': { inputPricePer1m: 3.6, outputPricePer1m: 18 },
'anthropic.claude-3-7-sonnet-20250219-v1:0': {
inputPricePer1m: 3.6,
outputPricePer1m: 18,
cacheReadPricePer1m: 0.36,
cacheWritePricePer1m: 4.5,
},
'anthropic.claude-sonnet-4-5-20250929-v1:0': {
inputPricePer1m: 3.6,
outputPricePer1m: 18,
cacheReadPricePer1m: 0.36,
cacheWritePricePer1m: 4.5,
},
'anthropic.claude-sonnet-5': {
inputPricePer1m: 2.4,
outputPricePer1m: 12,
cacheReadPricePer1m: 0.24,
cacheWritePricePer1m: 3,
},
'anthropic.claude-sonnet-5-5': {
inputPricePer1m: 2.4,
outputPricePer1m: 12,
cacheReadPricePer1m: 0.12,
cacheWritePricePer1m: 3,
},
'anthropic.claude-opus-4-8': {
inputPricePer1m: 6,
outputPricePer1m: 30,
cacheReadPricePer1m: 0.6,
cacheWritePricePer1m: 7.5,
},
'anthropic.claude-opus-5': {
inputPricePer1m: 6,
outputPricePer1m: 30,
cacheReadPricePer1m: 0.6,
cacheWritePricePer1m: 7.5,
},
'anthropic.claude-opus-5-5': {
inputPricePer1m: 4.8,
outputPricePer1m: 24,
cacheReadPricePer1m: 0.24,
cacheWritePricePer1m: 6,
},
'anthropic.claude-haiku-5-5': {
inputPricePer1m: 0.12,
outputPricePer1m: 0.6,
cacheReadPricePer1m: 0.012,
cacheWritePricePer1m: 0.15,
},
'anthropic.claude-fable-5-1': {
inputPricePer1m: 12,
outputPricePer1m: 60,
cacheReadPricePer1m: 0.3,
cacheWritePricePer1m: 15,
},
// Amazon. Nova lists a cache-read price only (no cache-write price on the standard tier).
'amazon.nova-micro-v1:0': {
inputPricePer1m: 0.042,
outputPricePer1m: 0.168,
cacheReadPricePer1m: 0.0105,
},
'amazon.nova-lite-v1:0': {
inputPricePer1m: 0.072,
outputPricePer1m: 0.288,
cacheReadPricePer1m: 0.018,
},
'amazon.nova-pro-v1:0': {
inputPricePer1m: 0.96,
outputPricePer1m: 3.84,
cacheReadPricePer1m: 0.24,
},
// An embedding model: input tokens only.
'amazon.titan-embed-text-v2:0': { inputPricePer1m: 0.11, outputPricePer1m: 0 },
// Meta.
'meta.llama3-8b-instruct-v1:0': { inputPricePer1m: 0.3, outputPricePer1m: 0.6 },
'meta.llama3-70b-instruct-v1:0': { inputPricePer1m: 2.65, outputPricePer1m: 3.5 },
// OpenAI open-weight.
'openai.gpt-oss-20b-1:0': { inputPricePer1m: 0.084, outputPricePer1m: 0.36 },
'openai.gpt-oss-120b-1:0': { inputPricePer1m: 0.18, outputPricePer1m: 0.72 },
// NVIDIA.
'nvidia.nemotron-nano-9b-v2': { inputPricePer1m: 0.072, outputPricePer1m: 0.276 },
'nvidia.nemotron-nano-12b-v2': { inputPricePer1m: 0.24, outputPricePer1m: 0.72 },
'nvidia.nemotron-nano-3-30b': { inputPricePer1m: 0.072, outputPricePer1m: 0.288 },
'nvidia.nemotron-super-3-120b': { inputPricePer1m: 0.18, outputPricePer1m: 0.78 },
// xAI, in-region (`us-gov.`) tier.
'xai.grok-4.6': { inputPricePer1m: 2.64, outputPricePer1m: 7.92, cacheReadPricePer1m: 0.66 },
},
};
/** The built-in price for a Bedrock model in a non-commercial partition, keyed by `modelId`. */
export function builtinBedrockPrice(modelId, partition) {
const table = BEDROCK_BUILTIN_PRICES[partition];
if (table === undefined)
return undefined;
for (const candidate of bedrockPriceCandidates(modelId)) {
const price = table[candidate];
if (price !== undefined)
return { modelId, ...price };
}
return undefined;
}
//# sourceMappingURL=bedrock.js.map