From ce53adb0c648cb5b12085718ca43fb43474a8d2d Mon Sep 17 00:00:00 2001 From: pylrn Date: Thu, 24 Sep 2026 09:38:59 +0530 Subject: [PATCH 1/2] feat(types): expose language_code in SyncTranscriptResponse The sync transcription server already returns a language_code field in every response, but SyncTranscriptResponse did not declare it, so the value was silently discarded by Pydantic. Add language_code: Optional[str] = None to surface the ISO 639-1 code the model used (e.g. "en", "es"). The field is Optional to stay backwards-compatible with server responses that predate the field. This is especially useful when language_codes is not set and the caller wants to confirm which language the model automatically detected. Add two unit tests following the existing request_time_ms pattern: - test_transcribe_parses_language_code (field present in server JSON) - test_transcribe_parses_response_without_language_code (field absent) --- assemblyai/types.py | 7 +++++++ tests/unit/test_sync.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/assemblyai/types.py b/assemblyai/types.py index 92377f68..49ce7d95 100644 --- a/assemblyai/types.py +++ b/assemblyai/types.py @@ -2908,6 +2908,13 @@ class SyncTranscriptResponse(BaseModel): session_id: str "Server-generated UUID for this request. Record it to correlate with support." + language_code: Optional[str] = None + """ISO 639-1 language code the model used for this transcript (e.g. ``"en"`` + for English, ``"es"`` for Spanish). Populated when the server detects or is + told the language; ``None`` for responses from servers that predate the field. + Useful when ``language_codes`` was not set and you need to know which language + the model chose.""" + request_time_ms: Optional[float] = None """End-to-end server-side request time in milliseconds: queue wait, auth, multipart parse, decode, inference, and serialization. ``None`` when the diff --git a/tests/unit/test_sync.py b/tests/unit/test_sync.py index 054101cc..00d3db4d 100644 --- a/tests/unit/test_sync.py +++ b/tests/unit/test_sync.py @@ -71,6 +71,40 @@ def test_transcribe_parses_response_without_request_time(httpx_mock: HTTPXMock): assert result.request_time_ms is None +def test_transcribe_parses_language_code(httpx_mock: HTTPXMock): + # Given a server response that includes the language_code field + response = {**_OK_RESPONSE, "language_code": "es"} + httpx_mock.add_response( + url=TRANSCRIBE_URL, + method="POST", + status_code=httpx.codes.OK, + json=response, + ) + + # When transcribing + result = aai.SyncTranscriber().transcribe(b"RIFFfake-wav-bytes") + + # Then language_code is surfaced on the response + assert result.language_code == "es" + + +def test_transcribe_parses_response_without_language_code(httpx_mock: HTTPXMock): + # Given a server response that predates the language_code field + response = {k: v for k, v in _OK_RESPONSE.items() if k != "language_code"} + httpx_mock.add_response( + url=TRANSCRIBE_URL, + method="POST", + status_code=httpx.codes.OK, + json=response, + ) + + # When transcribing + result = aai.SyncTranscriber().transcribe(b"RIFFfake-wav-bytes") + + # Then language_code is None instead of a parse failure + assert result.language_code is None + + def test_transcribe_sends_model_header_and_wav_part(httpx_mock: HTTPXMock): # Given a mocked sync endpoint _mock_ok(httpx_mock) From 3162496041178b64d0144b20e3c3702bef457732 Mon Sep 17 00:00:00 2001 From: pylrn Date: Fri, 25 Sep 2026 10:26:43 +0530 Subject: [PATCH 2/2] chore: bump version to 1.6.2 --- assemblyai/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assemblyai/__version__.py b/assemblyai/__version__.py index f49459c7..51bbb3f2 100644 --- a/assemblyai/__version__.py +++ b/assemblyai/__version__.py @@ -1 +1 @@ -__version__ = "1.6.1" +__version__ = "1.6.2"