BerriAI/litellm · error · MistralAudioTranscriptionException

raw_response.text

Error message

raw_response.text

What it means

Raised by litellm's Mistral audio transcription transformer when raw_response.json() fails: the Mistral transcription endpoint returned a non-JSON body. The exception message is the raw response text, and the upstream status code and headers are propagated, so an auth failure (401) keeps its real status.

Source

Thrown at litellm/llms/mistral/audio_transcription/transformation.py:135

        files: Final = {
            "file": (
                processed_audio.filename,
                processed_audio.file_content,
                processed_audio.content_type,
            )
        }

        return AudioTranscriptionRequestData(data=form_fields, files=files)

    def transform_audio_transcription_response(
        self,
        raw_response: httpx.Response,
    ) -> TranscriptionResponse:
        try:
            response_json: Final = raw_response.json()
        except Exception:
            raise MistralAudioTranscriptionException(
                message=raw_response.text,
                status_code=raw_response.status_code,
                headers=raw_response.headers,
            )

        text: Final = response_json.get("text") or ""
        response: Final = TranscriptionResponse(text=text)

        # Preserve Mistral-specific fields (e.g. diarization segments)
        if "segments" in response_json:
            response["segments"] = response_json["segments"]
        if "language" in response_json:
            response["language"] = response_json["language"]

        response._hidden_params = response_json
        return response

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Check the exception's status_code and message — the message is the literal upstream body and pinpoints the cause.
  2. Validate MISTRAL_API_KEY is set and active for the Mistral transcription product.
  3. Convert audio to a supported format (flac/mp3/mp4/wav/webm/m4a) and confirm the file extension matches the content.
  4. Reduce file size or chunk long audio if upstream rejects large payloads.
  5. If using a custom api_base, confirm it points at Mistral's transcription route, not the chat completions route.

Example fix

# before
result = litellm.transcription(model="mistral/mistral-large", file=open(f, "rb"))

# after — pre-validate the file and catch with status context
from litellm.exceptions import APIError
try:
    with open(path, "rb") as f:
        result = litellm.transcription(model="mistral/mistral-large", file=f)
except APIError as e:
    if "401" in str(getattr(e, "status_code", "")):
        raise RuntimeError("Bad MISTRAL_API_KEY") from e
    raise
Defensive patterns

Strategy: try-catch

Validate before calling

import os, pathlib
assert os.getenv("MISTRAL_API_KEY"), "MISTRAL_API_KEY not set"
assert pathlib.Path(audio_path).stat().st_size > 0, "audio file is empty"

Try / catch

from litellm.exceptions import APIError
try:
    result = litellm.transcription(model="mistral/mistral-large", file=f)
except APIError as e:
    status = getattr(e, "status_code", None)
    if status == 401:
        raise RuntimeError("Invalid MISTRAL_API_KEY") from e
    if status and 502 <= status <= 504:
        return retry_later()  # transient gateway
    raise

Prevention

When it happens

Trigger: Calling litellm.transcription() with a mistral/* audio model when the API returns an error body (plain text or HTML) instead of JSON: invalid MISTRAL_API_KEY, unsupported audio format, file too large, or a gateway 502/504 page.

Common situations: Missing/rotated MISTRAL_API_KEY, sending an audio codec Mistral's transcription endpoint does not accept, exceeding file size limits, or routing through a proxy that returns HTML error pages.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/a487549364b955bc. Report an issue: GitHub.