mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-21 00:21:49 +00:00
fix(xai): reject non-success stt responses before parsing
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
a124e079c3
commit
99d91d7205
2 changed files with 23 additions and 0 deletions
|
|
@ -130,6 +130,13 @@ class XAIAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
|
|||
self,
|
||||
raw_response: Response,
|
||||
) -> TranscriptionResponse:
|
||||
if raw_response.status_code >= 400:
|
||||
raise self.get_error_class(
|
||||
error_message=raw_response.text,
|
||||
status_code=raw_response.status_code,
|
||||
headers=raw_response.headers,
|
||||
)
|
||||
|
||||
try:
|
||||
payload: Final = _XAISttResponse.model_validate_json(raw_response.content)
|
||||
except ValidationError as e:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from litellm.llms.base_llm.audio_transcription.transformation import (
|
|||
from litellm.llms.custom_httpx.http_handler import HTTPHandler
|
||||
from litellm.llms.xai.audio_transcription.transformation import (
|
||||
XAIAudioTranscriptionConfig,
|
||||
XAIAudioTranscriptionError,
|
||||
)
|
||||
from litellm.types.utils import LlmProviders
|
||||
from litellm.utils import ProviderConfigManager
|
||||
|
|
@ -130,6 +131,21 @@ def test_transform_response_maps_xai_shape():
|
|||
assert response._hidden_params["audio_transcription_duration"] == 3.2
|
||||
|
||||
|
||||
def test_transform_response_raises_on_error_status():
|
||||
raw = httpx.Response(
|
||||
400,
|
||||
json={
|
||||
"code": "Client specified an invalid argument",
|
||||
"error": "Incorrect API key provided",
|
||||
},
|
||||
request=httpx.Request("POST", "https://api.x.ai/v1/stt"),
|
||||
)
|
||||
with pytest.raises(XAIAudioTranscriptionError) as exc:
|
||||
CONFIG.transform_audio_transcription_response(raw_response=raw)
|
||||
assert exc.value.status_code == 400
|
||||
assert "Incorrect API key provided" in exc.value.message
|
||||
|
||||
|
||||
def test_transcription_routes_to_xai_stt(monkeypatch):
|
||||
monkeypatch.delenv("XAI_API_KEY", raising=False)
|
||||
monkeypatch.setattr(litellm, "xai_key", None)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue