litellm/litellm/litellm_core_utils
Sameer Kankute e912e6d4ff
feat(audio_transcription): add NVIDIA Riva STT provider (#27185)
* feat(audio_transcription): add NVIDIA Riva STT provider

Adds nvidia_riva as a new audio transcription provider, supporting both
NVCF-hosted and self-hosted Riva ASR deployments via gRPC streaming.

- Auto-resamples input audio to 16 kHz mono LINEAR_PCM (soundfile + numpy,
  audioread fallback) so callers can send any common format.
- Maps OpenAI params: language (en -> en-US), response_format (text/json/
  verbose_json), timestamp_granularities=["word"] -> enable_word_time_offsets,
  word offsets converted ms -> s for verbose_json.
- Auth: NVCF when nvcf_function_id is set (SSL on by default), self-hosted
  otherwise (SSL off by default), with explicit use_ssl override.
- gRPC errors wrapped via NvidiaRivaException -> litellm exception classes.
- Optional deps gated behind [stt-nvidia-riva] extra (nvidia-riva-client,
  soundfile, audioread, numpy).

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(nvidia_riva): address PR review feedback

- handler: forward call-level `timeout` to streaming_response_generator
  (kwarg-detected via inspect for older riva-client compat) so a stalled
  Riva server cannot block the caller indefinitely.
- audio_utils: spill bytes to a tempfile before audioread.audio_open;
  most audioread backends (FFmpeg, GStreamer) require a real filesystem
  path and previously raised TypeError on BytesIO, breaking the mp3/m4a
  fallback path.
- audio_utils: prefer soxr / scipy.signal.resample_poly for resampling
  (anti-aliased polyphase) when installed, falling back to linear only
  as a last resort. Avoids aliasing on 44.1/48 kHz -> 16 kHz downsamples.
- transformation: bare `es` now maps to es-ES (Castilian) instead of
  es-US, matching BCP-47 conventions.

Co-authored-by: Cursor <cursoragent@cursor.com>

* chore: trigger CI re-run [stabilize loop 1/3]

* Update litellm/llms/nvidia_riva/audio_transcription/transformation.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* chore: trigger CI re-run [stabilize loop 1/3]

* fix code qa

* fix lint

* fix mypy

* fix mypy

* Fix NVIDIA Riva ASR service lookup

* Fix NVIDIA Riva transcription payload logging

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: oss-pr-review-agent-shin[bot] <281797381+oss-pr-review-agent-shin[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-05-05 17:17:51 -07:00
..
audio_utils style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
llm_cost_calc Add gpt-image-2 support (#26644) (#26705) 2026-04-28 20:10:42 -07:00
llm_response_utils fix: drop sensitive locals from re-raised error messages 2026-04-29 15:11:29 -07:00
prompt_templates fix(anthropic, mcp): sanitize tool names to match Anthropic's [a-zA-Z0-9_-]{1,128} pattern (#26788) 2026-05-06 00:00:36 +00:00
specialty_caches style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
tokenizers Code Quality Improvement - remove tokenizers/ from /llms (#7163) 2024-12-10 23:50:15 -08:00
api_route_to_call_types.py Agent Guardrails - on streaming output (#21206) 2026-02-14 11:36:52 -08:00
app_crypto.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
asyncify.py (core sdk fix) - fix fallbacks stuck in infinite loop (#7751) 2025-01-13 19:34:34 -08:00
cached_imports.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
cli_token_utils.py fix: scope CLI stored token to base_url to prevent cross-domain credential leakage (#26945) 2026-05-01 12:11:32 -07:00
cloud_storage_security.py trust only server legacy file flag 2026-05-01 18:32:26 -07:00
completion_timeout.py Litellm ishaan april15 2 (#25828) 2026-04-15 18:42:23 -07:00
core_helpers.py Merge pull request #26283 from BerriAI/litellm_internal_staging 2026-04-22 19:55:27 -03:00
coroutine_checker.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
credential_accessor.py fix(router.py): support reusable credentials via passthrough router (#9758) 2025-04-04 18:40:14 -07:00
custom_logger_registry.py Add Vantage integration for FOCUS CSV export 2026-03-11 13:51:36 +05:30
dd_tracing.py _add_dd_apm_tags_for_litellm_call_id (#22219) 2026-02-26 16:42:23 -08:00
default_encoding.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
dot_notation_indexing.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
duration_parser.py Reapply "feat: add model_cost aliases expansion support" 2026-03-12 13:36:57 -03:00
env_utils.py fix(callbacks): allow MAX_CALLBACKS override via env var (#20781) 2026-02-09 12:11:32 -08:00
exception_mapping_utils.py Fix ruff errors 2026-05-01 17:27:34 +05:30
fallback_utils.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
get_blog_posts.py fix: remove unused Any import from get_blog_posts 2026-03-16 16:23:06 -07:00
get_litellm_params.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
get_llm_provider_logic.py feat(audio_transcription): add NVIDIA Riva STT provider (#27185) 2026-05-05 17:17:51 -07:00
get_model_cost_map.py style: run black formatter on 52 non-enterprise files 2026-03-12 14:23:50 -03:00
get_provider_specific_headers.py [Fix] Forward anthropic-beta headers to Bedrock, VertexAI (#15700) 2025-10-18 16:26:32 -07:00
get_supported_openai_params.py Feature/add audio support for scaleway (#26110) 2026-04-20 14:49:41 -07:00
health_check_helpers.py add docs and formatting 2026-02-28 14:08:09 +05:30
health_check_utils.py (Refactor) - Re use litellm.completion/litellm.embedding etc for health checks (#7455) 2024-12-28 18:38:54 -08:00
initialize_dynamic_callback_params.py thread trusted params through vertex file content 2026-05-01 18:24:22 -07:00
json_validation_rule.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
litellm_logging.py Merge branch 'litellm_yj_may1' into codex/integration-host-credential-guard 2026-05-01 14:42:23 -07:00
llm_request_utils.py style: reformat to pass ci 2026-04-30 17:01:44 -07:00
logging_callback_manager.py feat(logging): add retry settings for generic API logger (#26645) 2026-04-28 08:38:17 -07:00
logging_utils.py fix(types): resolve MyPy assignment type errors in logging_utils and vertex transformation 2026-02-20 13:46:51 -03:00
logging_worker.py fix: make LoggingWorker.flush() wait for in-flight callbacks 2026-04-23 15:06:33 -07:00
mock_functions.py Support returning virtual key in custom auth + Handle provider-specific optional params for embedding calls (#11346) 2025-06-03 07:24:13 -07:00
model_param_helper.py style: black format model_param_helper.py 2026-04-15 18:18:45 -07:00
model_response_utils.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
README.md Guardrails API - add streaming support (#17400) 2025-12-02 22:52:09 -08:00
realtime_streaming.py feat(realtime): OpenAI Realtime GA support and beta compatibility (#27110) 2026-05-05 16:49:20 -07:00
redact_messages.py fix(logging): redact standard logging choice metadata 2026-04-30 00:35:29 -07:00
response_header_helpers.py fix(utils.py): guarantee openai-compatible headers always exist in response 2024-09-28 21:08:15 -07:00
rules.py fix: remove slow string operation (#14955) 2025-09-26 13:25:59 -07:00
safe_json_dumps.py fix: shared health check serialization (#21119) 2026-02-13 09:15:43 -08:00
safe_json_loads.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
secret_redaction.py Unify secret redaction patterns 2026-05-01 17:24:21 +00:00
sensitive_data_masker.py chore(vector-stores): also gate /vector_store/update; upstream credentials plural in masker 2026-04-29 18:56:09 +00:00
streaming_chunk_builder_utils.py style: apply black formatting 2026-04-22 20:09:53 -03:00
streaming_handler.py Fix: trigger fallbacks on mid-stream httpx.TimeoutException 2026-05-01 11:46:17 -07:00
thread_pool_executor.py (Fixes) OpenAI Streaming Token Counting + Fixes usage track when litellm.turn_off_message_logging=True (#8156) 2025-01-31 15:06:37 -08:00
token_counter.py fix: correct image size limit enforcement and vertex_location None passthrough 2026-04-23 11:20:20 -07:00
url_utils.py Merge pull request #26861 from BerriAI/litellm_fix_scim_virtual_key_deactivation 2026-05-04 19:03:55 -07:00

Folder Contents

This folder contains general-purpose utilities that are used in multiple places in the codebase.

Core files:

  • streaming_handler.py: The core streaming logic + streaming related helper utils
  • core_helpers.py: code used in types/ - e.g. map_finish_reason.
  • exception_mapping_utils.py: utils for mapping exceptions to openai-compatible error types.
  • default_encoding.py: code for loading the default encoding (tiktoken)
  • get_llm_provider_logic.py: code for inferring the LLM provider from a given model name.
  • duration_parser.py: code for parsing durations - e.g. "1d", "1mo", "10s"
  • api_route_to_call_types.py: mapping of API routes to their corresponding CallTypes (e.g., /chat/completions -> [acompletion, completion])