Skip to content

[BUG CLIENT]: Context bias is ignored if no audio files are uploaded #338

@mjscriba

Description

@mjscriba

Python -VV

Python 3.12.3 (main, Jan 22 2026, 20:57:42) [GCC 13.3.0]

Pip Freeze

mistralai                                1.12.0

Reproduction Steps

  1. Make a request via the SDK for a transcription using an online URL, rather than an uploaded file. Include context bias for unusual words
  2. Request will return successfully, but without context bias being applied.

Expected Behavior

Context bias should be applied

When calling client.audio.transcriptions.complete() with file_url (rather than uploading a file), the context_bias parameter is silently ignored. This is because the SDK sends the request as application/x-www-form-urlencoded instead of multipart/form-data.

Root Cause:

In basesdk.py, the _build_request_with_client method passes both data= and files= to httpx's build_request(). When files is an empty list (which happens when using file_url instead of uploading a file), httpx defaults to application/x-www-form-urlencoded encoding instead of multipart/form-data.

# basesdk.py line ~97
return client.build_request(
    method,
    url,
    params=query_params,
    content=serialized_request_body.content,
    data=serialized_request_body.data,
    files=serialized_request_body.files,  # Empty list causes httpx to use urlencoded
    headers=headers,
    timeout=timeout,
)

Reproduction:

from mistralai import Mistral

client = Mistral(api_key="...")
result = client.audio.transcriptions.complete(
    model="voxtral-mini-latest",
    file_url="https://example.com/audio.mp3",
    diarize=True,
    context_bias=["Scriba", "Mistral", "diarization"],
)
# context_bias words are not applied to transcription

Workaround:

Direct curl request with -F flags works correctly:

curl 'https://api.mistral.ai/v1/audio/transcriptions' \
  -H "Authorization: Bearer $API_KEY" \
  -F 'model=voxtral-mini-latest' \
  -F 'file_url=https://example.com/audio.mp3' \
  -F 'diarize=true' \
  -F 'context_bias=Scriba' \
  -F 'context_bias=Mistral'

Suggested Fix:

When serialized_request_body.media_type is multipart/form-data but files is empty, either:

  1. Pass files=None instead of files=[] and explicitly set the Content-Type header, or
  2. Add a dummy empty file to force multipart encoding, or
  3. Use httpx's content= parameter with manually-encoded multipart data

Additional Context

No response

Suggested Solutions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions