const require_logger = require("./logger-DuG3amVa.cjs");
const require_responses = require("./responses-Gq3p9VLZ.cjs");
/**
* Whether a Bedrock OpenAI model id is a frontier model served through the Responses API
* (a bare `openai.` id that is not an open-weight `gpt-oss` model, e.g. `openai.gpt-5.5`).
*
* Only the bare ids are accepted. AWS's GPT-5.5 / GPT-5.4 model cards list just the bare model
* ids and explicitly mark the Geo and Global inference IDs as "Not supported", so a
* region/geo-prefixed id such as `us.openai.gpt-5.5` is not a real Bedrock model. Matching it
* here would route an invalid id to the mantle endpoint; instead it falls through to a clear
* error (see `getHandlerForModel` in ./index.ts) that points at the supported bare id.
*/
function isBedrockOpenAiResponsesModel(modelName) {
	return modelName.startsWith("openai.") && !modelName.includes("gpt-oss");
}
/**
* Build the regional Bedrock mantle base URL for the OpenAI frontier models.
*
* NOTE: the path is `/openai/v1`, not `/v1`. Verified live against gpt-5.5/gpt-5.4: the
* frontier models are served under the `/openai/v1/responses` path and return HTTP 400
* ("does not support the '/v1/responses' API") on the bare `/v1` path. The bare `/v1` path
* documented in the AWS Mantle guide serves the open-weight `gpt-oss` models instead — and
* those return 400 on `/openai/v1`. Do not "simplify" this to `/v1`.
*/
function getBedrockMantleBaseUrl(region) {
	if (!/^[a-z]{2}(?:-[a-z]+)+-\d+$/.test(region)) throw new Error(`Invalid AWS region "${region}" for the Bedrock mantle endpoint. Expected a region like "us-east-2". Set a valid region via config.region, AWS_BEDROCK_REGION, or AWS_REGION (or supply config.apiBaseUrl to target a custom endpoint).`);
	return `https://bedrock-mantle.${region}.api.aws/openai/v1`;
}
function resolveRegion(config, env) {
	return config.region || env?.AWS_BEDROCK_REGION || require_logger.getEnvString("AWS_BEDROCK_REGION") || env?.AWS_REGION || env?.AWS_DEFAULT_REGION || process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || "us-east-2";
}
function resolveApiKey(config, env) {
	return (typeof config.apiKey === "string" && !config.apiKey.includes("{{") ? config.apiKey : void 0) || env?.AWS_BEARER_TOKEN_BEDROCK || require_logger.getEnvString("AWS_BEARER_TOKEN_BEDROCK");
}
/**
* OpenAI Responses provider for Bedrock frontier models. Behaves exactly like the OpenAI
* Platform provider (shared request/response/usage handling).
*
* Bedrock model ids carry an `openai.` prefix (e.g. `openai.gpt-5.5`), which the base
* provider's GPT-5 detection (`gpt-5*` / `/gpt-5`) and billing lookups don't recognize.
* Without this, GPT-5 controls (reasoning effort, verbosity) would be dropped and a
* `temperature` default wrongly applied. We strip the prefix for those capability/billing
* checks while still sending the real `openai.gpt-5.5` id as the request `model` — Bedrock
* mirrors OpenAI first-party rates, so the OpenAI billing tables apply.
*/
var BedrockOpenAiResponsesProvider = class extends require_responses.OpenAiResponsesProvider {
	/**
	* Strip the Bedrock `openai.` prefix so the base provider's GPT-5 / o-series capability
	* detection and the OpenAI billing tables match. The request still sends the real
	* `this.modelName` (e.g. `openai.gpt-5.5`) as the model id. Only bare `openai.` ids reach
	* this provider (see {@link isBedrockOpenAiResponsesModel}), so no region prefix is expected.
	*/
	getCapabilityModelName() {
		return this.modelName.replace(/^openai\./, "");
	}
	/**
	* Pin requests to the Bedrock mantle endpoint configured on this provider. The base
	* `getApiUrl()` prefers `apiHost`/`OPENAI_API_HOST` over `apiBaseUrl`, so without this an
	* ambient `OPENAI_API_HOST` (set for an unrelated OpenAI-compatible provider) would hijack
	* Bedrock calls and send the Bedrock bearer token to the wrong host.
	*/
	getApiUrl() {
		return this.config.apiBaseUrl || super.getApiUrl();
	}
};
/**
* Construct an OpenAI Responses provider configured for a Bedrock frontier model. Resolves
* the region (config → AWS_BEDROCK_REGION → AWS_REGION → default) and the Amazon Bedrock
* API key (config.apiKey → AWS_BEARER_TOKEN_BEDROCK), and targets the mantle endpoint
* unless the caller supplies an explicit `apiBaseUrl`.
*/
function createBedrockOpenAiResponsesProvider(modelName, providerOptions = {}) {
	const config = providerOptions.config ?? {};
	const region = resolveRegion(config, providerOptions.env);
	const apiKey = resolveApiKey(config, providerOptions.env);
	if (!apiKey) throw new Error(`Amazon Bedrock model "${modelName}" is an OpenAI frontier model served through Bedrock's OpenAI-compatible Responses API, which authenticates with an Amazon Bedrock API key. Set the AWS_BEARER_TOKEN_BEDROCK environment variable (or config.apiKey). See https://www.promptfoo.dev/docs/providers/aws-bedrock/#openai-models`);
	const apiBaseUrl = config.apiBaseUrl || getBedrockMantleBaseUrl(region);
	return new BedrockOpenAiResponsesProvider(modelName, {
		...providerOptions,
		config: {
			...config,
			apiBaseUrl,
			apiKey
		}
	});
}
//#endregion
exports.createBedrockOpenAiResponsesProvider = createBedrockOpenAiResponsesProvider;
exports.isBedrockOpenAiResponsesModel = isBedrockOpenAiResponsesModel;

//# sourceMappingURL=openaiResponses-DpD16DII.cjs.map