litellm/litellm/litellm_core_utils
devin-ai-integration[bot] 2c9b0e00ac
refactor(types): replace Any with proven types in 8 files (#43551)
* refactor(types): replace Any with proven types in 8 files

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(types): keep email logger untyped where its alert types differ

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-28 04:26:41 -07:00
..
audio_utils fix(audio_utils): validate MPEG frame headers before labeling sniffed audio 2026-08-29 14:20:40 -07:00
llm_cost_calc feat(sail): add Sail as a provider with service_tier mapped to its completion window (#42840) 2026-09-26 12:57:48 -07:00
llm_response_utils feat(lint): add LIT013 flagging *-ok suppressions that suppress nothing and remove the 240 stale ones (#42793) 2026-09-23 17:50:09 -07:00
prompt_templates fix(tools): salvage concatenated JSON tool call arguments (#43260) 2026-09-26 21:15:12 -07:00
specialty_caches feat(langfuse): migrate the sdk callback to langfuse v4 (#36741) 2026-09-24 23:22:56 -07:00
tokenizers Code Quality Improvement - remove tokenizers/ from /llms (#7163) 2024-12-10 23:50:15 -08:00
agentic_followup_kwargs.py refactor(agentic-loop): build follow-up kwargs in one place so no executor can repeat a request param (#42307) 2026-09-21 20:06:01 -07:00
agentic_loop_settings.py fix: keep accepting a loop ceiling that spells a whole number 2026-08-22 11:24:22 -07:00
api_route_to_call_types.py fix(guardrails): resolve generateContent routes and async-first passthrough call types 2026-08-29 21:35:19 -07:00
app_crypto.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
asyncify.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
aws_partition.py fix(aws): build every AWS endpoint and ARN from the region partition 2026-08-29 01:21:59 -07:00
bug_report.py feat(proxy): admin-only /debug/report sharing the bug report environment (#42440) 2026-09-22 12:05:23 -07:00
cached_imports.py refactor(lint): apply every safe ruff autofix and zero 28 strict-rule budgets 2026-08-01 15:43:29 -07:00
chat_completion_agentic_loop.py refactor(agentic-loop): build follow-up kwargs in one place so no executor can repeat a request param (#42307) 2026-09-21 20:06:01 -07:00
classifier_logging.py fix(router): merge staging and retain native classifier audits 2026-09-10 14:24:56 -07:00
cli_keyring.py fix(cli): stop asking a keychain that already stopped answering 2026-08-20 04:12:23 -07:00
cli_token_utils.py fix(cli): keep the refresh token in the OS keychain, not in token.json 2026-08-20 11:43:53 -07:00
cloud_storage_security.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
completion_timeout.py chore(lint): strip inert type: ignore comments and zero LIT009, LIT010, LIT011 headroom 2026-08-05 02:37:24 -07:00
core_helpers.py fix(logging): pass provider response headers to callbacks on every endpoint (#42824) 2026-09-24 13:01:12 -07:00
coroutine_checker.py Merge remote-tracking branch 'origin/main' into litellm_decrease_anys_opus5_r5 2026-09-21 12:57:38 -07:00
credential_accessor.py fix(proxy): load db credentials in the model reconcile so a worker never serves a model before its credential (#39876) 2026-09-08 10:08:24 -07:00
custom_logger_registry.py feat(otel): add SigNoz preset for OpenTelemetry v2 (#43296) 2026-09-26 18:15:45 -07:00
dd_tracing.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
default_encoding.py feat(tokenizer): preserve Python defaults with opt-in Rust dispatch (#42174) 2026-09-22 04:41:11 +00:00
dot_notation_indexing.py refactor(typing): replace Any with proven types in 89 more backend files 2026-09-02 23:08:42 +00:00
duration_parser.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
env_utils.py fix(token_counter): stop large token counts from blocking the proxy event loop (#37697) 2026-08-20 16:09:07 -07:00
error_normalization.py fix(passthrough): log upstream 4xx/5xx error bodies and carry them into the failure hook (#42695) 2026-09-23 23:42:24 -07:00
exception_mapping_utils.py fix(bedrock): keep the provider status code on unprocessable image errors (#43416) 2026-09-27 05:10:24 +00:00
fallback_generalizations.py refactor(model_info): drop types import from fallback_generalizations 2026-09-14 18:58:53 +00:00
fallback_utils.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
get_blog_posts.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
get_litellm_params.py fix(params): validate stream_chunk_size once, before any provider call (#43222) 2026-09-26 23:01:20 +00:00
get_llm_provider_logic.py feat(providers): add Nadir intelligent-router provider (nadir/auto) (#33227) 2026-09-24 22:03:30 -07:00
get_model_cost_map.py fix(proxy): drop cost-map metadata echoed back on model save (#41944) 2026-09-21 19:33:16 -07:00
get_provider_specific_headers.py fix(proxy): stop forwarding a client Anthropic OAuth token to Bedrock and Vertex 2026-08-21 18:02:40 -07:00
get_supported_openai_params.py feat(providers): add Nadir intelligent-router provider (nadir/auto) (#33227) 2026-09-24 22:03:30 -07:00
health_check_helpers.py feat(xai): add native xAI batches and files support (#42812) 2026-09-25 15:35:20 -07:00
health_check_utils.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
initialize_dynamic_callback_params.py feat(otel): add SigNoz preset for OpenTelemetry v2 (#43296) 2026-09-26 18:15:45 -07:00
internal_call_metadata.py fix(auto_router): bill the routing embedding to the caller's key and team (#39532) 2026-09-03 13:53:30 -07:00
json_fragment_accumulator.py feat(lint): add LIT013 flagging *-ok suppressions that suppress nothing and remove the 240 stale ones (#42793) 2026-09-23 17:50:09 -07:00
json_validation_rule.py refactor(typing): replace Any with proven types in 89 more backend files 2026-09-02 23:08:42 +00:00
litellm_logging.py refactor(types): replace Any with proven types in 8 files (#43551) 2026-09-28 04:26:41 -07:00
llm_judge.py fix(shadow_eval): refuse a judge model that also serves one of the arms it grades (#38589) 2026-08-27 18:44:44 -07:00
llm_request_utils.py fix(hosted_vllm): forward Omni media URLs instead of downloading them 2026-08-24 17:59:52 -04:00
logging_callback_manager.py fix(proxy): surface runtime-registered callbacks in UI Logging page (#38974) 2026-09-09 22:03:16 -07:00
logging_utils.py refactor(types): replace Any with proven types in 34 files 2026-09-20 10:16:48 +00:00
logging_worker.py fix(ci): stop stale CI reds, keep unit tests off the host env, retry CyberArk policy conflicts (#43294) 2026-09-26 09:25:13 -07:00
mock_functions.py refactor(lint): apply every safe ruff autofix and zero 28 strict-rule budgets 2026-08-01 15:43:29 -07:00
model_param_helper.py merge litellm_internal_staging into litellm_anthropic_messages_response_cache 2026-08-11 20:48:41 +00:00
model_response_utils.py chore(techdebt): clear fresh debt from the 2026-08-29 window 2026-08-30 07:57:16 +00:00
private_json.py feat(auto-router): show routed model and savings in Claude Code and Codex (#40330) 2026-09-11 12:52:42 -07:00
provider_affinity.py feat(lint): add LIT013 flagging *-ok suppressions that suppress nothing and remove the 240 stale ones (#42793) 2026-09-23 17:50:09 -07:00
ptu_pricing.py feat(spend-logs): record Azure spillover source deployment in spend log metadata 2026-09-17 05:48:51 +00:00
README.md feat(tokenizer): preserve Python defaults with opt-in Rust dispatch (#42174) 2026-09-22 04:41:11 +00:00
realtime_errors.py fix(realtime): surface an upstream handshake refusal as an error event and policy close (#42388) 2026-09-22 11:31:15 -07:00
realtime_streaming.py feat(vertex_ai): stream Chirp speech-to-text over /v1/realtime 2026-09-17 17:57:40 -07:00
reasoning_effort_utils.py fix(bedrock): normalize Messages system role and adaptive-thinking for Claude Invoke (#31364) 2026-06-27 11:35:36 -07:00
redact_messages.py fix(guardrails): store the masked output in spend logs when Presidio masks the response (#42441) 2026-09-22 01:19:22 -07:00
request_timeout_resolver.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -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 chore(lint): strip inert type: ignore comments and zero LIT009, LIT010, LIT011 headroom 2026-08-05 02:37:24 -07:00
safe_json_dumps.py refactor(types): replace Any with proven types in 32 files 2026-09-21 10:51:46 +00:00
safe_json_loads.py refactor(lint): apply every safe ruff autofix and zero 28 strict-rule budgets 2026-08-01 15:43:29 -07:00
secret_redaction.py feat(logger): dispatch Python logging through the Rust diagnostics processor (#42616) 2026-09-22 18:44:15 -07:00
sensitive_data_masker.py Merge remote-tracking branch 'origin/main' into litellm_decrease_anys_opus5_r5 2026-09-21 12:57:38 -07:00
sentry_scrubbing.py fix(sentry): scrub PII and secrets inside object reprs and nested locals, add SENTRY_SEND_DEFAULT_PII opt-in (#43123) 2026-09-25 14:52:35 -07:00
served_output_texts.py fix(guardrails): store the masked output in spend logs when Presidio masks the response (#42441) 2026-09-22 01:19:22 -07:00
service_tier_utils.py feat(lint): enforce Final on locals and freeze function parameters (LIT010, LIT011) 2026-08-04 12:54:39 -07:00
streaming_chunk_builder_utils.py fix(responses): emit the reasoning item on streaming /v1/responses for signature-only thinking (#43414) 2026-09-27 04:51:56 +00:00
streaming_handler.py fix(streaming): keep litellm Usage on text-completion usage chunks (#43047) 2026-09-27 01:53:12 +00:00
thread_pool_executor.py fix(logging): bound the shared logging executor backlog (#37694) 2026-08-20 16:04:43 -07:00
token_counter.py fix(token_counter): count Gemini function_declarations tools (#43417) 2026-09-26 22:28:31 -07:00
tokenizer.py feat(tokenizer): preserve Python defaults with opt-in Rust dispatch (#42174) 2026-09-22 04:41:11 +00:00
url_utils.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -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 Python tokenizer and bundled cache
  • 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])

Tokenizer factories return Python tokenizer objects by default. Set LITELLM_RUST=1 or call litellm.rust(True) before constructing tokenizers to select the Rust backend through Route.TOKENIZER in the Rust catalog. Missing native bindings or unsupported native features fall back to Python. Existing tokenizer objects keep their selected backend. Rust-backed tokenizer objects carry the read-only tiktoken.Encoding / tokenizers.Tokenizer surface and are immutable: enable_padding, enable_truncation and add_tokens stay on the Python tokenizer.