isSpeechModelId (ttsProviders/openai.js)

krouter · open-sse/handlers/ttsProviders/openai.js · javascript · MIT
voice

Utility for validating OpenAI TTS model IDs and synthesizing speech.

// Source: https://github.com/sifxprime/krouter | License: MIT | Copyright 2026 Kodelyth AI Infrastructure
// Provided via justclaw.it.com; keep this notice with the code.
// OpenAI TTS — model format: "tts-model/voice", a bare speech model id, or a bare voice
import { Buffer } from "node:buffer";

const DEFAULT_MODEL = "gpt-4o-mini-tts";
const DEFAULT_VOICE = "alloy";
// 0.5.164 — a bare "tts-1" was sent as the voice; speech model ids (tts-1, tts-1-hd, gpt-4o-mini-tts + snapshots, future gpt-*-tts) are models
const SPEECH_MODEL_RE = /^(tts-\d[\w.-]*|gpt-[\w.-]*-tts(-[\w.-]+)?)$/i;
// 0.5.164 — the regex backtracks quadratically and `model` is raw request input; real ids are under 40 chars
const MAX_SPEECH_MODEL_ID_LENGTH = 64;

function isSpeechModelId(model) {
  return model.length <= MA

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key