import { n as readResponseWithLimit } from "./read-response-with-limit-MDCSJrlg.js";
import { r as fetchWithSsrFGuard } from "./fetch-guard-CVQ9AHan.js";
import { i as assertOkOrThrowProviderError } from "./provider-http-errors-BydAWT1D.js";
import "./ssrf-runtime-DCAardg-.js";
import "./response-limit-runtime-B0ZHF0eR.js";
import "./provider-http-C9DFqL98.js";
import { r as normalizeGradiumBaseUrl } from "./shared-BI174QeF.js";
//#region extensions/gradium/tts.ts
const DEFAULT_TTS_MAX_BYTES = 16 * 1024 * 1024;
async function gradiumTTS(params) {
	const { text, apiKey, baseUrl, voiceId, outputFormat, timeoutMs, maxBytes = DEFAULT_TTS_MAX_BYTES } = params;
	const normalizedBaseUrl = normalizeGradiumBaseUrl(baseUrl);
	const url = `${normalizedBaseUrl}/api/post/speech/tts`;
	const hostname = new URL(normalizedBaseUrl).hostname;
	const { response, release } = await fetchWithSsrFGuard({
		url,
		init: {
			method: "POST",
			headers: {
				"x-api-key": apiKey,
				"Content-Type": "application/json"
			},
			body: JSON.stringify({
				text,
				voice_id: voiceId,
				only_audio: true,
				output_format: outputFormat,
				json_config: JSON.stringify({ padding_bonus: 0 })
			})
		},
		timeoutMs,
		policy: { hostnameAllowlist: [hostname] },
		auditContext: "gradium.tts"
	});
	try {
		await assertOkOrThrowProviderError(response, "Gradium API error");
		return await readResponseWithLimit(response, maxBytes, { onOverflow: ({ maxBytes: maxBytesLocal }) => /* @__PURE__ */ new Error(`Gradium TTS audio response exceeds ${maxBytesLocal} bytes`) });
	} finally {
		await release();
	}
}
//#endregion
export { gradiumTTS as t };
