Commit Graph

1758 Commits

Author SHA1 Message Date
Krish Dholakia 3a73309006 Add bedrock llama4 pricing + handle llama4 templating on bedrock invoke route (#10582)
* build(model_prices_and_context_window.json): add bedrock llama4 models to model cost map

* fix template conversion for Llama 4 models in Bedrock (#10557)

* test: add testing to repro https://github.com/BerriAI/litellm/pull/10557

* test: add unit testing

* test(test_main.py): refactor where test is kept

---------

Co-authored-by: aswny <87371411+aswny@users.noreply.github.com>
2025-05-06 16:06:24 -07:00
Ishaan Jaff 7d73ab5d88 Add litellm-proxy CLI (#10478) (#10578)
* Add `litellm-proxy` CLI (#10478)

* First cut at a Python client module for proxy

* Add UnauthorizedError + add_model method

* Add delete_model method

* Add example model_id to delete_model docstring

* Make delete_model raise NotFoundError

* Add get_model

* Add get_all_model_info

* Rename models.list_models to models.list

* Rename models.get_all_model_info to models.info

* Move ModelsManagementClient.get_all_model_group_info to ModelGroupsManagementClient.info

* Rename get_model to get

* Rename add_model to new

* Rename delete_model to delete

* In client classes, rename base_url attribute to _base_url and api_key attribute to _api_key

* Add ModelsManagementClient.updae method

* Add client.chat.completions (ChatClient)

* ruff format litellm/proxy/client

* ruff format tests/litellm/proxy/client/*.py

* Add latest changes

* Rename KeysManagementClient.create to KeysManagementClient.generate

* Add new parameters to KeysManagementClient.generate

* Add CredentialsManagementClient

* Remove api_key parameter from KeysManagementClient.generate

* Fix lint errors

* Add litellm/proxy/client/README.md

* README.md: Remove api_key param to client.keys.generate

* Fix mypy errors

* First cut at litellm-proxy cli

* Add test for `litellm-proxy models list`

* Nicer get_models_info

* get_models_info: --columns option

* Use format_timestamp in list_models

* ruff format litellm/proxy/client

* Simpler JSON printing with rich.print_json

* Move models-related commands to separate file

From `cli.py` to `groups/models.py`

* Improve directory structure

* Cleanup cli/groups/models.py - esp. usage of rich

* Refactoring

* Refactor mocking in cli/test_main.py

* Dedup models commands tests

* Update poetry.lock

* Fix mypy errors

* ruff format litellm/proxy/client/cli

* ruff format tests/litellm/proxy/client/*.py

* Fix timezone issue in test_models_list_table_format

* Add cli/README.md

* Small README.md tweaks

* README.md enhancements

* Add credentials commands

* Add chat commands

* Add http commands

* ruff format litellm/proxy/client/cli

* Fix lint errors in credentials and http commands

* json => json_lib

* test-key => sk-test-key

* Mock HTTP responses so http command tests pass

* Fix mypy error in credentials.py

* bump: version 1.67.5 → 1.67.6

* build: update litellm version

* cli/main.py: show_envvar=True

* Increase test job timeout to 8 minutes

because it looks like maybe the job is getting canceled because it takes
too long with the additional tests?

This probably could be reverted once #10484 is merged, since that speeds
up pytest runs greatly.

* Add keys functionality to library/CLI

* Add info about keys commands to litellm/proxy/client/cli/README.md

* Move Model Information section in CLI README

* Make Model Information a level 4 heading

* Move rich to extras

as suggested by @ishaan-jaff

---------

Co-authored-by: Krrish Dholakia <krrishdholakia@gmail.com>

* pin rich=13.7.1

---------

Co-authored-by: Marc Abramowitz <abramowi@adobe.com>
Co-authored-by: Krrish Dholakia <krrishdholakia@gmail.com>
2025-05-05 21:29:57 -07:00
Ishaan Jaff cd48ffb6c4 [Bug fix] JSON logs - Ensure only 1 log is emitted (previously duplicate json logs were getting emitted) (#10580)
* fix logging with JSON logs

* test: test_initialize_loggers_with_handler_sets_propagate_false
2025-05-05 20:25:47 -07:00
Ishaan Jaff ddc24da2a7 Revert "fix logging with JSON logs"
This reverts commit 1109a6ea6e.
2025-05-05 18:13:39 -07:00
Ishaan Jaff 1109a6ea6e fix logging with JSON logs 2025-05-05 18:13:15 -07:00
Ishaan Jaff 489f1a6c25 [Feat] v2 Custom Logger API Endpoints (#10575)
* fixes for generic api logger

* tests for generic api logger

* test_generic_api_callback_multiple_logs

* allow health checking generic api endpoints

* docs generic api endpoint for logging

* allow setting headers for generic api  callback

* fix for test_init_custom_logger_compatible_class_as_callback

* fix linting
2025-05-05 16:57:55 -07:00
Krish Dholakia 522e334fbd fix(converse_transformation.py): handle meta llama tool call response (#10541)
* fix(converse_transformation.py): handle meta llama tool call response

Fixes issue where bedrock meta llama would return tool call response as content str

* test(test_converse_transformation.py): add unit testing for new function

* fix: fix linting error

* fix: fix linting error
2025-05-03 21:31:14 -07:00
Ishaan Jaff 7c4fae477a [Bug Fix] UnicodeDecodeError: 'charmap' on Windows during litellm import (#10542)
* test using litellm on windows

* fix using litellm on windows

* test using litellm on windows

* fix change on ci/cd

* fix test on ci/cd
2025-05-03 21:31:05 -07:00
Ishaan Jaff 3f45200802 test_openai_responses_api_web_search_cost_tracking 2025-05-03 20:22:42 -07:00
Krish Dholakia 880c2a736b fix(model_management_endpoints.py): allow team admin to update model … (#10539)
* fix(model_management_endpoints.py): allow team admin to update model via `/model/{model_id}/update` route

Fixes ui regression where team admin could not modify their own models

* fix(provider_specific_fields.tsx): style fix

* fix(table.tsx): allow expanding multiple rows

* fix(organization_endpoints.py): more robust check if user can give org model access

handle when user has models=["all-proxy-models"]

* fix(organization_endpoints.py): enable proxy admin with 'all-proxy-model' access to create new org with specific models

Fixes LIT-135

* fix: fix linting error

* fix: fix ui linting error

* fix(index.tsx): fix linting errors
2025-05-03 19:34:35 -07:00
Krrish Dholakia 42a91bae6b test: comment out new ui test - needs more investigation 2025-05-03 19:32:36 -07:00
Krrish Dholakia 7581a0e3e0 test: reduce timeout 2025-05-03 19:16:54 -07:00
Krrish Dholakia 3ad108cb63 test: add timeout on keys page 2025-05-03 19:08:04 -07:00
Ishaan Jaff 8faa7dbc39 fixes for web search tests 2025-05-03 18:10:30 -07:00
Ishaan Jaff f52593486c [Contributor PR] Support Llama-api as an LLM provider (#10451) (#10538)
* Support Llama-api as an LLM provider (#10451)

* init: support llama-api as a llm provider

* docs: fix endpoint url

* fix: rename meta dir to meta-llama

* docs: add meta-llama info

* fix: mv LlamaAPIConfig under chat directory

* feat: add LlamaAPIConfig in ProviderConfigManager

* fix: provider_config from ProviderConfigManager

* feat: add supports_tool_choice param

* fix: remove optional_params using model_info

* fix: rename meta-llama to meta_llama

* init: test for meta_llama

* fix: model names

---------

Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>

* fix file naming convention

* fix file naming convention for meta_llama

* docs meta llama api litellm

---------

Co-authored-by: Young Han <110819238+seyeong-han@users.noreply.github.com>
Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
2025-05-03 16:29:03 -07:00
Ishaan Jaff 299f8f18a0 text fix redis cache 2025-05-03 16:28:43 -07:00
Ishaan Jaff 85d843ab4d text fix vertex deprecated a model 2025-05-03 16:22:24 -07:00
Ishaan Jaff a37e4cb0b8 fix typo (#10535) 2025-05-03 11:39:40 -07:00
Krish Dholakia 552b7e4013 Add customer + model per key level multi-instance tpm/rpm limiting (#10518)
* fix(redis_cache.py): handle multiple event loops

* fix(parallel_request_limiter_v2.py): add customer tpm limiting

* fix(parallel_request_limiter.py): add customer rpm limiting

* fix(parallel_request_limiter_v2.py): add model per key + customer tpm/rpm limiting

* fix(parallel_request_limiter_v2.py): make error more informative

* fix: fix ruff error

* fix: generate new poetry lock
2025-05-03 10:28:55 -07:00
Ishaan Jaff 931c0c760c fix test_anthropic_messages_litellm_router_streaming_with_logging 2025-05-03 09:34:32 -07:00
Krish Dholakia 7273bb442a UI - allow reassigning team to other org (#10527)
* feat(team_info.tsx): allow user to reassign team to another org

* style(team_info.tsx): fix org id styling

* feat(team_endpoints.py): add validation check before migrating team to another org

ensure model access, budgets and membership is respected

* fix(team_endpoints.py): update model migration validation to check if org has 'all-proxy-models' access

* fix(organization_view.tsx): show teams belonging to org

* feat(team_endpoints.py): handle wildcard model check on org migration

* fix(team_endpoints.py): nest router check

* test: update testing - use model with higher quota

* build: update poetry lock
2025-05-03 08:44:43 -07:00
Ishaan Jaff 988e20aa36 [QA] Bedrock Vector Stores Integration - Allow using with registry + in OpenAI API spec with tools (#10516)
* refactor KB implementation to use central registry

* allow passing tools when making KB calls

* test fixes

* linting fix

* fix kb tests

* QA for KB stored in DB

* fix, use litellm_credential_name when adding KB on litellm UI

* QA list endpoint vector stores

* allow using UI creds with KBs
2025-05-03 08:30:38 -07:00
Krish Dholakia 6d5f396b59 Playwright test for team admin (#10366) (#10470)
* Playwright test for team admin (#10366)

* Create team_admin.spec.ts

* add todo

* modify test and timeout (#10525)

---------

Co-authored-by: tanjiro <56165694+NANDINI-star@users.noreply.github.com>
2025-05-03 08:20:00 -07:00
Krish Dholakia b412d70232 UI - fix adding vertex models with reusable credentials + fix pagination on keys table + fix showing org budgets on table (#10528)
* feat(provider_specific_fields.tsx): Use correct form instance

Fixes https://github.com/BerriAI/litellm/issues/10115

* Fix broken pagination by correctly passing page and pageSize to keyListCall (#10498)

* [Organization] Include litellm_budget_table in /organization/list response (#10488)

* join litellm_budget_table in /organization/list endpoint

* update test

---------

Co-authored-by: tanjiro <56165694+NANDINI-star@users.noreply.github.com>
2025-05-03 08:16:53 -07:00
Ishaan Jaff e013d7e529 [Feat] Show Vector Store / KB Request on LiteLLM Logs Page (#10514)
* ensure vector store results are logged in SLP

* fix tests

* fix tests with vector_store_request_metadata

* fix linting

* track duration of vector store, only log content when user opts into it

* working vector store viewer

* fix custom llm provider - Vector Store Requests

* fix vector store viewer

* fix logging redacted vector searches

* testing for storing KB queries in DB
2025-05-02 16:14:09 -07:00
Ishaan Jaff 28cb7cc0ed [Feat] KnowledgeBase/Vector Store - Log StandardLoggingVectorStoreRequest for requests made when a vector store is used (#10509)
* ensure vector store results are logged in SLP

* fix tests

* fix tests with vector_store_request_metadata

* fix linting
2025-05-02 13:43:20 -07:00
Krrish Dholakia 2791b1be1a test: bump limit on flaky load test 2025-05-02 12:10:22 -07:00
Prathamesh Saraf ac7b1efe5c Refactor budget assertions in tests to improve clarity and accuracy. Updated remaining hours check to ensure positive values and adjusted budget reset time validation for better range checks. (#10500) 2025-05-02 09:02:02 -07:00
Krrish Dholakia 33814917fe fix(token_counter.py): handle empty lists 2025-05-02 08:07:08 -07:00
Ishaan Jaff 04e6ad7cee test_get_cost_for_built_in_tools_file_search 2025-05-02 07:17:26 -07:00
Ishaan Jaff 96e75628d6 [Fix + Refactor] Trigger Soft Budget Webhooks When Key Crosses Threshold (#10491)
* fix slack alerting with webhooks

* emit correct event group/entity on webhooks

* refactor to use a common class of alerts with abc methods

* fixes for tests

* refactor to use a common class of alerts with abc methods

* Send a budget alert on slack or webhook

* unit test slack alerting

* fix code qa
2025-05-02 07:06:07 -07:00
Carlos Freund cb177dbd7a Fix and rewrite of token_counter (#10409)
* added tests

messages_with_counts: Made tolerance explicit for each test. But they match the new implementation(which beats the old)

* new token counter impl

* compare old and new implementation in test

* delete old token counter

* moved tests to /tests/litellm/litellm_core_utils

* use existing types

* docstrings

* warn about using default params on unknown model.

* created type for the token_counter_function

* check key == "content"

* throw error on invalid detail-type, ignore type-warning.

* fix imports
2025-05-01 23:34:37 -07:00
Krish Dholakia 9cc39af131 Add vertex ai meta llama 4 support + handle tool call result in content for vertex ai (#10492)
* refactor(vertex_ai/llama): handle response transformation within config

Allows us to handle https://github.com/BerriAI/litellm/issues/10441#issuecomment-2844975599

* fix(vertex_ai/llama): handle tool call in content

Fixes https://github.com/BerriAI/litellm/issues/10441

* fix(vertex_ai/llama): return 'tool_calls' as finish reason if tool call returned

vertex ai returns stop

* feat(vertex_ai/): cost tracking for vertex_ai/meta/llama-4

* ci(test-linting.yml): pin openai version

* build: reorder pinning

* ci(pyproject.toml): limit openai version

temporary patch as new version has linting errors

* ci(pyproject.toml): limit openai version

temporary patch around linting errors

* ci(limit-openai-version): temporary patch

* fix: fix linting errors

* fix: fix linting error

* fix(parallel_request_limiter_v2.py): add team based multi-instance rate limiting

* fix: fix linting errors

* build(pyproject.toml): modify pin

* ci: bump pin
2025-05-01 22:47:06 -07:00
Krish Dholakia 132bdb1380 Add user + team based multi-instance rate limiting (#10497)
* fix(parallel_request_limiter_v2.py): add user multi-instance rate limiting

* fix(parallel_request_limiter_v2.py): add user multi-instance rpm limiting

* fix(parallel_request_limiter_v2.py): add team based multi-instance rate limiting
2025-05-01 22:09:26 -07:00
Krish Dholakia a4c96d5224 Fix return finish_reason = "tool_calls" for gemini tool calling (#10485)
* fix(vertex_and_google_ai_studio.py): fix finish reason to be 'tool_calls' when tool call returned

Vertex returns 'Stop', openai format is 'tool calls'

* test(base_llm_unit_tests.py): bump test to assert tool calls in finish reason
2025-05-01 22:02:56 -07:00
Ishaan Jaff de7870cb54 Add llamafile as a provider (#10203) (#10482)
* Update docs for OpenAI compatible providers, add Llamafile docs, include Llamafile in the sidebar

* Add Llamafile as an LlmProviders enum

* Add llamafile as a OpenAI compatible provider (in the list of compatible providers)

* Add Llamafile chat config and tests

* Wire up Llamafile

Co-authored-by: Peter Wilson <peter@mozilla.ai>
2025-05-01 18:36:55 -07:00
Krrish Dholakia 66cf75cd5d test: handle internal server errors 2025-05-01 16:47:30 -07:00
Krrish Dholakia cec138c47e test: remove redundant tests 2025-05-01 16:46:21 -07:00
Krrish Dholakia 4ab0ee0b65 test: more testing fixes 2025-05-01 15:36:13 -07:00
Ruperto A. Martinez 298a3574f4 Add supports_pdf_input: true to Claude 3.7 bedrock models (#9917)
* Add supports_pdf_input: true to Claude 3.7 bedrock models

* update unit test

---------

Co-authored-by: RupertoXTI <rmartinez@xtillion.com>
2025-05-01 14:56:54 -07:00
Ishaan Jaff eebb725416 [Fixes] Azure OpenAI OIDC - allow using litellm defined params for OIDC Auth (#10394)
* fixes for azure OIDC ad token auth

* fixes for test_azure_common_utils.py

* get_azure_ad_token_from_oidc
2025-05-01 14:46:56 -07:00
Ishaan Jaff ba67ca1f84 fix ensure mcp tools are llm api routes (#10473) 2025-05-01 14:37:30 -07:00
Krish Dholakia 6ad483dde7 Litellm dev 04 30 2025 p1 (#10462)
* fix(exception_mapping_utils.py): correctly pass through 504 status code

openai also raises a 504 status code

* build(model_prices_and_context_window.json): add gpt-4o-mini-tts to model cost map

Fixes https://github.com/BerriAI/litellm/issues/9591

* fix(cost_calculator.py): fix input cost calculation for gpt-4o-mini-tts

Fixes https://github.com/BerriAI/litellm/issues/9591

* test: testing updates
2025-04-30 22:11:12 -07:00
Marc Abramowitz 596c71c360 Add low-level HTTP client (#10452)
The client provides access to a low-level HTTP client for making direct
requests to the LiteLLM proxy server. This is useful when you need more
control or when working with endpoints that don't yet have a high-level
interface.

```python
In [2]: client.http.request(
   ...:     method="POST",
   ...:     uri="/health/test_connection",
   ...:     json={
   ...:         "litellm_params": {
   ...:             "model": "gpt-4",
   ...:             "custom_llm_provider": "azure_ai",
   ...:             "litellm_credential_name": None,
   ...:             "api_key": "6xxxxxxx",
   ...:             "api_base": "https://litellm8397336933...",
   ...:         },
   ...:         "mode": "chat",
   ...:     },
   ...: )
Out[2]:
{'status': 'error',
 'result': {'model': 'gpt-4',
  'custom_llm_provider': 'azure_ai',
  'litellm_credential_name': None,
  'api_base': 'https://litellm8397336933...',
  ...
```
2025-04-30 21:57:06 -07:00
Ishaan Jaff be885e4a17 [Feat] Vector Stores/KnowledgeBases - Allow defining Vector Store Configs (#10448)
* init vector store configs

* working kb init

* add vector store endpoints

* use litellm_credential_name

* working CRUD vector stores litellm

* working creds with vector DB

* ui cleanup

* clean up vector store id

* fix delete button

* refactored vector store component

* working selector for KBs

* ui vector stores

* add vector store tool calls usage on chat ui

* fixes for vector stores litellm

* test fix

* docs Knowledge Bases

* fixes for vector stores litellm

* fix linting

* add managed vectorstores

* fix orjson ci/cd test

* fix linting

* add types.tsx file
2025-04-30 21:49:59 -07:00
Krish Dholakia 711601e22a Add key-level multi-instance tpm/rpm/max parallel request limiting (#10458)
* fix: initial commit of v2 parallel request limiter hook

enables multi-instance rate limiting to work

* fix: subsequent commit with additional refactors

* fix(parallel_request_limiter_v2.py): cleanup initial call hook

simplify it

* fix(parallel_request_limiter_v2.py): working v2 parallel request limiter

* fix: more updates - still not passing testing

* fix(test_parallel_request_limiter_v2.py): update test + add conftest

* fix: fix ruff checks

* fix(parallel_request_limiter_v2.py): use pull via pattern method to load in keys instance wouldn't have seen yet

Fixes issue where redis syncing was not pulling key until instance had seen it

* test: update testing to cover tpm and rpm

* fix(parallel_request_limiter_v2.py): fix ruff errors

* fix(proxy/hooks/__init__.py): feature flag export

* fix(proxy/hooks/__init_.py): fix linting error

* ci(config.yml): add tests/enterprise to ci/cd

* fix: fix ruff check

* test: update testing
2025-04-30 21:32:31 -07:00
Marc Abramowitz 1e8674b611 New feature: Add Python client library for LiteLLM Proxy (#10445)
* First cut at a Python client module for proxy

* Add UnauthorizedError + add_model method

* Add delete_model method

* Add example model_id to delete_model docstring

* Make delete_model raise NotFoundError

* Add get_model

* Add get_all_model_info

* Rename models.list_models to models.list

* Rename models.get_all_model_info to models.info

* Move ModelsManagementClient.get_all_model_group_info to ModelGroupsManagementClient.info

* Rename get_model to get

* Rename add_model to new

* Rename delete_model to delete

* In client classes, rename base_url attribute to _base_url and api_key attribute to _api_key

* Add ModelsManagementClient.updae method

* Add client.chat.completions (ChatClient)

* ruff format litellm/proxy/client

* ruff format tests/litellm/proxy/client/*.py

* Add latest changes

* Rename KeysManagementClient.create to KeysManagementClient.generate

* Add new parameters to KeysManagementClient.generate

* Add CredentialsManagementClient

* Remove api_key parameter from KeysManagementClient.generate

* Fix lint errors

* Add litellm/proxy/client/README.md

* README.md: Remove api_key param to client.keys.generate

* Fix mypy errors

* Add requests-mock to tool.poetry.group.dev.dependencies

* Update poetry.lock
2025-04-30 16:27:17 -07:00
Ishaan Jaff 669566a05f Contributor PR - Support OPENAI_BASE_URL in addition to OPENAI_API_BASE (#9995) (#10423)
* Support OPENAI_BASE_URL in addition to OPENAI_API_BASE (#9995)

* Support OPENAI_BASE_URL in addition to OPENAI_API_BASE

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>

* exact

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>

* feedback

* less change

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>

---------

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>

* doc fix OPENAI_API_BASE

---------

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
Co-authored-by: Adrian Cole <64215+codefromthecrypt@users.noreply.github.com>
2025-04-29 21:27:37 -07:00
Krish Dholakia 9e35ca2010 Embedding caching fixes - handle str -> list cache, set usage tokens for cache hits, combine usage tokens on partial cache hits (#10424)
* build(model_prices_and_context_window.json): add fireworks ai new 0-4b pricing tier

* build(model_prices_and_context_window.json): add more fireworks ai models

* test: update testing

* fix(caching_handler.py): handle str + list cache

Fixes issue on cache hits for embedding when initial cached input was str

* test(test_caching.py): add e2e test on caching with individual item and then list

* fix(caching_handler.py): set usage tokens for cache hits

enables token counting to work

* fix(caching_handler.py): combine usage between cached result and embedding response

Handles case of new input to embedding response

* fix: cleanup

* test: move to gpt-4o-new-test

* test: update test
2025-04-29 21:21:28 -07:00
Krish Dholakia 290e2528cd Schedule budget resets at expectable times (#10331) (#10333)
* Schedule budget resets at expectable times (#10331)

* Enhance budget reset functionality with timezone support and standardized reset times

- Added `get_next_standardized_reset_time` function to calculate budget reset times based on specified durations and timezones.
- Introduced `timezone_utils.py` to manage timezone retrieval and budget reset time calculations.
- Updated budget reset logic in `reset_budget_job.py`, `internal_user_endpoints.py`, `key_management_endpoints.py`, and `team_endpoints.py` to utilize the new timezone-aware reset time calculations.
- Added unit tests for the new reset time functionality in `test_duration_parser.py`.
- Updated `.gitignore` to include `test.py` and made minor formatting adjustments in `docker-compose.yml` for consistency.

* Fixed linting

* Fix for mypy

* Fixed testcase for reset

* fix(duration_parser.py): move off zoneinfo - doesn't work with python 3.8

* test: update test

* refactor: improve budget reset time calculation and update related tests for accuracy

* clean up imports in team_endpoints.py

* test: update budget remaining hours assertions to reflect new reset time logic

* build(model_prices_and_context_window.json): update model

---------

Co-authored-by: Prathamesh Saraf <pratamesh1867@gmail.com>
2025-04-29 20:59:44 -07:00