litellm/cookbook
Neel Harsola ce421df1ef
fix(azure): preserve content_policy_violation error details from Azure OpenAI (#20883)
* feat: add opus 4.5 and 4.6 to use outout_format param

* generate poetry lock with 2.3.2 poetry

* restore poetry lock

* e2e tests, key delete, update tpm rpm, and regenerate

* Split e2e ui testing for browser

* new login with sso button in login page

* option to hide usage indicator

* fix(cloudzero): update CBF field mappings per LIT-1907 (#20906)

* fix(cloudzero): update CBF field mappings per LIT-1907

Phase 1 field updates for CloudZero integration:

ADD/UPDATE:
- resource/account: Send concat(api_key_alias, '|', api_key_prefix)
- resource/service: Send model_group instead of service_type
- resource/usage_family: Send provider instead of hardcoded 'llm-usage'
- action/operation: NEW - Send team_id
- resource/id: Send model name instead of CZRN
- resource/tag:organization_alias: Add if exists
- resource/tag:project_alias: Add if exists
- resource/tag:user_alias: Add if exists

REMOVE:
- resource/tag:total_tokens: Removed
- resource/tag:team_id: Removed (team_id now in action/operation)

Fixes LIT-1907

* Update litellm/integrations/cloudzero/transform.py

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

* fix: define api_key_alias variable, update CBFRecord docstring

- Fix F821 lint error: api_key_alias was used but not defined
- Update CBFRecord docstring to reflect LIT-1907 field mappings
- Remove unused Optional import

---------

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

* Add banner notifying of breaking change

* Add semgrep & Fix OOMs (#20912)

* [Feat] Policies - Allow connecting Policies to Tags, Simulating Policies, Viewing how many keys, teams it applies on  (#20904)

* init schema with TAGS

* ui: add policy test

* resolvePoliciesCall

* add_policy_sources_to_metadata + headers

* types Policy

* preview Impact

* def _describe_match_reason(

* match based on TAGs

* TestTagBasedAttachments

* test fixes

* add policy_resolve_router

* add_guardrails_from_policy_engine

* TestMatchAttribution

* refactor

* fix

* fix: address Greptile review feedback on policy resolve endpoints

- Track unnamed keys/teams as separate counts instead of inflating
  affected_keys_count with duplicate "(unnamed key)" placeholders.
  Added unnamed_keys_count and unnamed_teams_count to response.
- Push alias pattern matching to DB via _build_alias_where() which
  converts exact patterns to Prisma "in" and suffix wildcards to
  "startsWith" filters.
- Gate sync_policies_from_db/sync_attachments_from_db behind
  force_sync query param (default false) to avoid 2 DB round-trips
  on every /policies/resolve request.
- Remove worktree-only conftest.py that cleared sys.modules at import
  time — no longer needed since code moved to main repo.
- Rename MAX_ESTIMATE_IMPACT_ROWS → MAX_POLICY_ESTIMATE_IMPACT_ROWS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: eliminate duplicate DB queries and fix header delimiter ambiguity

- Fetch teams table once in estimate_attachment_impact and reuse for
  both tag-based and alias-based lookups (was querying teams twice when
  both tag_patterns and team_patterns were provided).
- Convert tag/team filter functions from async DB queries to sync
  filters that operate on pre-fetched data (_filter_keys_by_tags,
  _filter_teams_by_tags).
- Fix comma ambiguity in x-litellm-policy-sources header: use '; '
  as entry delimiter since matched_via values can contain commas.
- Use '+' as the within-value separator in matched_via reason strings
  (e.g. "tag:healthcare+team:health-team") to avoid conflict with
  header delimiters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update litellm/proxy/policy_engine/policy_resolve_endpoints.py

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

---------

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

* fix: type error & better error handling (#20689)

* [Docs] Add docs guide for using policies  (#20914)

* init schema with TAGS

* ui: add policy test

* resolvePoliciesCall

* add_policy_sources_to_metadata + headers

* types Policy

* preview Impact

* def _describe_match_reason(

* match based on TAGs

* TestTagBasedAttachments

* test fixes

* add policy_resolve_router

* add_guardrails_from_policy_engine

* TestMatchAttribution

* refactor

* fix

* fix: address Greptile review feedback on policy resolve endpoints

- Track unnamed keys/teams as separate counts instead of inflating
  affected_keys_count with duplicate "(unnamed key)" placeholders.
  Added unnamed_keys_count and unnamed_teams_count to response.
- Push alias pattern matching to DB via _build_alias_where() which
  converts exact patterns to Prisma "in" and suffix wildcards to
  "startsWith" filters.
- Gate sync_policies_from_db/sync_attachments_from_db behind
  force_sync query param (default false) to avoid 2 DB round-trips
  on every /policies/resolve request.
- Remove worktree-only conftest.py that cleared sys.modules at import
  time — no longer needed since code moved to main repo.
- Rename MAX_ESTIMATE_IMPACT_ROWS → MAX_POLICY_ESTIMATE_IMPACT_ROWS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: eliminate duplicate DB queries and fix header delimiter ambiguity

- Fetch teams table once in estimate_attachment_impact and reuse for
  both tag-based and alias-based lookups (was querying teams twice when
  both tag_patterns and team_patterns were provided).
- Convert tag/team filter functions from async DB queries to sync
  filters that operate on pre-fetched data (_filter_keys_by_tags,
  _filter_teams_by_tags).
- Fix comma ambiguity in x-litellm-policy-sources header: use '; '
  as entry delimiter since matched_via values can contain commas.
- Use '+' as the within-value separator in matched_via reason strings
  (e.g. "tag:healthcare+team:health-team") to avoid conflict with
  header delimiters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs v1 guide with UI imgs

* docs fix

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add dashscope/qwen3-max model with tiered pricing (#20919)

Add support for Alibaba Cloud's Qwen3-Max model with:
- 258K input tokens, 65K output tokens
- Tiered pricing based on context window usage (0-32K, 32K-128K, 128K-252K)
- Function calling and tool choice support
- Reasoning capabilities enabled

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix linting

* docs: add Greptile review requirement to PR template (#20762)

* fix(azure): preserve content_policy_violation error details from Azure OpenAI

Closes #20811

Azure OpenAI returns rich error payloads for content policy violations
(inner_error with ResponsibleAIPolicyViolation, content_filter_results,
revised_prompt). Previously these details were lost when:

1. The top-level error code was not "content_policy_violation" but the
   inner_error.code was "ResponsibleAIPolicyViolation" -- the structured
   check only examined the top-level code.

2. The DALL-E image generation polling path stringified the error JSON
   into the message field instead of setting the structured body, making
   it impossible for exception_type() to extract error details.

3. The string-based fallback detector used "invalid_request_error" as a
   content-policy indicator, which is too broad and could misclassify
   regular bad-request errors.

Changes:
- exception_mapping_utils.py: Check inner_error.code for
  ResponsibleAIPolicyViolation when top-level code is not
  content_policy_violation. Replace overly broad "invalid_request_error"
  string match with specific Azure safety-system messages.
- azure.py: Set structured body on AzureOpenAIError in both async and
  sync DALL-E polling paths so exception_type() can inspect error details.
- test_azure_exception_mapping.py: Add regression tests covering the
  exact error payloads from issue #20811.
- Fix pre-existing lint: duplicate PerplexityResponsesConfig dict key,
  unused RouteChecks top-level import.

---------

Co-authored-by: Kelvin Tran <kelvin-tran@users.noreply.github.com>
Co-authored-by: yuneng-jiang <yuneng.jiang@gmail.com>
Co-authored-by: shin-bot-litellm <shin-bot-litellm@berri.ai>
Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Alexsander Hamir <alexsanderhamirgomesbaptista@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Harshit Jain <48647625+Harshit28j@users.noreply.github.com>
Co-authored-by: ken <122603020@qq.com>
Co-authored-by: Sameer Kankute <sameer@berri.ai>
2026-02-10 22:47:03 -08:00
..
ai_coding_tool_guides docs: update Claude Code integration guides (#19415) 2026-01-21 20:11:06 -08:00
anthropic_agent_sdk fix: working claude code with agent SDKs (#20081) 2026-01-30 11:58:05 -08:00
benchmark (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
codellama-server (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
community-resources (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
litellm-ollama-docker-image build(deps): bump litellm in /cookbook/litellm-ollama-docker-image 2025-03-20 21:03:29 +00:00
litellm_proxy_server Prompt Management - new API for integrating providers (#17829) 2025-12-11 15:43:40 -08:00
litellm_router (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
litellm_router_load_test fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00
livekit_agent_sdk [Feat] Add xAI /realtime API Support - works with LiveKitSDK (#20381) 2026-02-03 19:58:28 -08:00
logging_observability docs litellm x langfuse cookbook 2025-02-14 09:31:51 -08:00
misc 1.80.8 RC docs (#17605) 2025-12-06 10:40:00 -08:00
mock_guardrail_server Guardrails API - new structured_messages param (#17518) 2025-12-04 22:08:00 -08:00
Benchmarking_LLMs_by_use_case.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
Claude_(Anthropic)_with_Streaming_liteLLM_Examples.ipynb (docs) update how to use litellm streaming 2023-11-21 11:19:32 -08:00
Evaluating_LLMs.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
google_adk_litellm_tutorial.ipynb [Docs] Using litellm with Google ADK (#10777) 2025-05-12 16:41:49 -07:00
liteLLM_A121_Jurrasic_example.ipynb add AI21 tutorial 2023-08-22 20:34:18 -07:00
LiteLLM_Azure_and_OpenAI_example.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
liteLLM_Baseten.ipynb Update Baseten LiteLLM integration 2025-08-19 12:21:05 -07:00
LiteLLM_batch_completion.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
LiteLLM_Bedrock.ipynb (docs) bedrock cookbook 2023-11-06 18:00:52 -08:00
liteLLM_clarifai_Demo.ipynb Clarifai - Added streaming and async completion support 2024-05-03 14:03:38 +00:00
LiteLLM_CometAPI.ipynb bump openai 2.8.0 2025-11-19 17:47:18 -08:00
LiteLLM_Comparing_LLMs.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
LiteLLM_Completion_Cost.ipynb add completion costs notebook 2023-09-06 18:43:09 -07:00
liteLLM_function_calling.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
liteLLM_Getting_Started.ipynb getting started cookbook litellm 2023-09-23 10:38:59 -07:00
LiteLLM_HuggingFace.ipynb fix img URL for tests 2025-11-22 09:41:15 -08:00
liteLLM_IBM_Watsonx.ipynb (docs) updated watsonx cookbook 2024-04-24 17:19:02 +02:00
liteLLM_Langchain_Demo.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
litellm_model_fallback.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
LiteLLM_NovitaAI_Cookbook.ipynb Add new model provider Novita AI (#7582) (#9527) 2025-05-12 21:49:30 -07:00
liteLLM_Ollama.ipynb docs 2023-09-21 12:33:39 -07:00
LiteLLM_OpenRouter.ipynb Add new model provider Novita AI (#7582) (#9527) 2025-05-12 21:49:30 -07:00
LiteLLM_Petals.ipynb cookbook petals 2023-09-20 09:34:33 -07:00
LiteLLM_PromptLayer.ipynb Fix CI: Revert security scan changes and add GitGuardian ignore rules (#18358) 2025-12-22 17:03:53 -08:00
liteLLM_Replicate_Demo.ipynb fix replicate docs 2023-09-06 12:35:50 -07:00
liteLLM_Streaming_Demo.ipynb add streaming example cookbook 2023-08-09 14:29:23 -07:00
litellm_test_multiple_llm_demo.ipynb Rename Untitled155.ipynb to litellm_test_multiple_llm_demo.ipynb 2023-08-10 18:56:26 -07:00
litellm_Test_Multiple_Providers.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
LiteLLM_User_Based_Rate_Limits.ipynb add notebook on using litellm budget manager 2023-09-12 20:53:55 -07:00
liteLLM_VertextAI_Example.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
Migrating_to_LiteLLM_Proxy_from_OpenAI_Azure_OpenAI.ipynb Fix CI: Revert security scan changes and add GitGuardian ignore rules (#18358) 2025-12-22 17:03:53 -08:00
mlflow_langchain_tracing_litellm_proxy.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
nova_sonic_realtime.py fix(azure): preserve content_policy_violation error details from Azure OpenAI (#20883) 2026-02-10 22:47:03 -08:00
Parallel_function_calling.ipynb (docs) parallel function calling with Azure OpenAI 2023-11-18 14:36:56 -08:00
Proxy_Batch_Users.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
result.html (docs) add embedding() profile 2023-11-30 19:04:51 -08:00
TogetherAI_liteLLM.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
Using_Nemo_Guardrails_with_LiteLLM_Server.ipynb (code quality) run ruff rule to ban unused imports (#7313) 2024-12-19 12:33:42 -08:00
veo_video_generation.py [Feat] Allow using Veo Video Generation through LiteLLM Pass through routes (#14228) 2025-09-03 18:25:43 -07:00
VLLM_Model_Testing.ipynb Add files via upload 2023-09-06 19:27:06 -07:00