@openrouter/ai-sdk-provider 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1025,6 +1025,19 @@ function mapOpenRouterFinishReason(finishReason) {
1025
1025
  }
1026
1026
  }
1027
1027
 
1028
+ // src/types/openrouter-chat-completions-input.ts
1029
+ var OPENROUTER_AUDIO_FORMATS = [
1030
+ "wav",
1031
+ "mp3",
1032
+ "aiff",
1033
+ "aac",
1034
+ "ogg",
1035
+ "flac",
1036
+ "m4a",
1037
+ "pcm16",
1038
+ "pcm24"
1039
+ ];
1040
+
1028
1041
  // src/chat/is-url.ts
1029
1042
  function isUrl({
1030
1043
  url,
@@ -1066,6 +1079,34 @@ function getBase64FromDataUrl(dataUrl) {
1066
1079
  const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
1067
1080
  return match ? match[1] : dataUrl;
1068
1081
  }
1082
+ var MIME_TO_FORMAT = {
1083
+ // MP3 variants
1084
+ mpeg: "mp3",
1085
+ mp3: "mp3",
1086
+ // WAV variants
1087
+ "x-wav": "wav",
1088
+ wave: "wav",
1089
+ wav: "wav",
1090
+ // OGG variants
1091
+ ogg: "ogg",
1092
+ vorbis: "ogg",
1093
+ // AAC variants
1094
+ aac: "aac",
1095
+ "x-aac": "aac",
1096
+ // M4A variants
1097
+ m4a: "m4a",
1098
+ "x-m4a": "m4a",
1099
+ mp4: "m4a",
1100
+ // AIFF variants
1101
+ aiff: "aiff",
1102
+ "x-aiff": "aiff",
1103
+ // FLAC
1104
+ flac: "flac",
1105
+ "x-flac": "flac",
1106
+ // PCM variants
1107
+ pcm16: "pcm16",
1108
+ pcm24: "pcm24"
1109
+ };
1069
1110
  function getInputAudioData(part) {
1070
1111
  const fileData = getFileUrl({
1071
1112
  part,
@@ -1090,19 +1131,14 @@ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1090
1131
  }
1091
1132
  const data = getBase64FromDataUrl(fileData);
1092
1133
  const mediaType = part.mediaType || "audio/mpeg";
1093
- let format = mediaType.replace("audio/", "");
1094
- if (format === "mpeg" || format === "mp3") {
1095
- format = "mp3";
1096
- } else if (format === "x-wav" || format === "wave" || format === "wav") {
1097
- format = "wav";
1098
- }
1099
- if (format !== "mp3" && format !== "wav") {
1134
+ const rawFormat = mediaType.replace("audio/", "");
1135
+ const format = MIME_TO_FORMAT[rawFormat];
1136
+ if (format === void 0) {
1137
+ const supportedList = OPENROUTER_AUDIO_FORMATS.join(", ");
1100
1138
  throw new Error(
1101
1139
  `Unsupported audio format: "${mediaType}"
1102
1140
 
1103
- OpenRouter only supports MP3 and WAV audio formats.
1104
- \u2022 For MP3: use "audio/mpeg" or "audio/mp3"
1105
- \u2022 For WAV: use "audio/wav" or "audio/x-wav"
1141
+ OpenRouter supports the following audio formats: ${supportedList}
1106
1142
 
1107
1143
  Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1108
1144
  );