mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-03 01:38:46 +00:00
* feat: update EmpirioLabs models in model_prices_and_context_window.json * chore(endpoints): regenerate provider endpoint support for the EmpirioLabs cost map rows * fix(empiriolabs): drop the retired max_tokens field, route embeddings and remove the unrouted rerank row The cost map test rejects any row carrying max_tokens, so every EmpirioLabs row keeps max_input_tokens and max_output_tokens only. The provider JSON now lists /v1/embeddings so embedding(model="empiriolabs/text-embedding-v4") reaches the OpenAI-compatible embeddings route instead of failing provider lookup. The qwen3-rerank row goes away because no rerank route exists for the provider. Endpoint support regenerated from the cost map * fix(empiriolabs): mark audio input and image embedding input on the rows the provider lists as multimodal The three vision embedding rows get supports_embedding_image_input and the eleven chat rows whose input_modalities on GET https://api.empiriolabs.ai/v1/models include audio get supports_audio_input, so capability checks stop treating them as text only * fix(empiriolabs): carry the long-context price tiers on the 24 rows the provider bills in bands EmpirioLabs bills 24 of these models at a higher rate once the prompt passes 32K, 128K, 256K, 272K or 512K tokens, and the rows carried only the first band, so a 300K-token qwen3-7-plus request was priced at a third of the real cost. Each of those rows now carries input_cost_per_token_above_<N>k_tokens, output_cost_per_token_above_<N>k_tokens and, where the row already has cache_read_input_token_cost, cache_read_input_token_cost_above_<N>k_tokens for every band, taken from pricing[].min_context on GET https://api.empiriolabs.ai/v1/models for the base rows and from the Variants rate card on docs.empiriolabs.ai/models/<id> for the six variant rows * feat(empiriolabs): bill the per-call web search fee reported in usage.tool_usage EmpirioLabs charges a flat fee per invoked web_search, web_search_image or image_search call and reports the counts in usage.tool_usage on the chat response. The JSON provider config now carries that count as usage.server_tool_use.web_search_requests when providers.json sets special_handling.web_search_requests_from_tool_usage, the per-call web search cost path bills the usage-reported count instead of flooring to one call, and the 39 EmpirioLabs rows the provider lists a per-call search price for carry it as search_context_cost_per_query, from unit_pricing on GET /v1/models for base rows and the Variants rate card on docs.empiriolabs.ai for variant rows * fix(openai_like): mark the dict signature of transform_parsed_response_dict as matching BaseConfig for LIT001 * fix(openai_like): mark both dict annotations of transform_parsed_response_dict for LIT001 --------- Co-authored-by: Adam Dalloul <47503782+Adam-Dalloul@users.noreply.github.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
162 lines
7.1 KiB
Python
162 lines
7.1 KiB
Python
import pytest
|
|
|
|
from litellm.llms.openai_like import dynamic_config
|
|
from litellm.llms.openai_like.dynamic_config import create_responses_config_class
|
|
from litellm.llms.openai_like.json_loader import SimpleProviderConfig
|
|
from litellm.types.router import GenericLiteLLMParams
|
|
|
|
_BASE = {"base_url": "https://api.example.com/v1", "api_key_env": "EXAMPLE_API_KEY"}
|
|
|
|
|
|
def _provider(slug, **overrides):
|
|
return SimpleProviderConfig(slug=slug, data={**_BASE, **overrides})
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate_generated_class_cache():
|
|
dynamic_config._responses_config_cache.clear()
|
|
yield
|
|
dynamic_config._responses_config_cache.clear()
|
|
|
|
|
|
class TestClassCaching:
|
|
|
|
def test_cache_is_keyed_on_slug_not_on_the_provider_instance(self):
|
|
first = create_responses_config_class(_provider("cache_by_slug"))
|
|
second = create_responses_config_class(_provider("cache_by_slug"))
|
|
assert first is second
|
|
|
|
def test_different_slugs_get_different_classes(self):
|
|
assert create_responses_config_class(_provider("cache_slug_a")) is not (
|
|
create_responses_config_class(_provider("cache_slug_b"))
|
|
)
|
|
|
|
def test_returns_a_class_not_an_instance(self):
|
|
assert isinstance(create_responses_config_class(_provider("returns_class")), type)
|
|
|
|
|
|
class TestCustomLlmProvider:
|
|
def test_provider_property_reports_the_slug(self):
|
|
config = create_responses_config_class(_provider("provider_prop"))()
|
|
assert config.custom_llm_provider == "provider_prop"
|
|
|
|
|
|
class TestValidateEnvironment:
|
|
def test_explicit_api_key_becomes_a_bearer_header(self):
|
|
config = create_responses_config_class(_provider("ve_explicit"))()
|
|
headers = config.validate_environment(
|
|
headers={}, model="m", litellm_params=GenericLiteLLMParams(api_key="sk-explicit")
|
|
)
|
|
assert headers["Authorization"] == "Bearer sk-explicit"
|
|
|
|
def test_api_key_falls_back_to_the_configured_env_var(self, monkeypatch):
|
|
monkeypatch.setenv("VE_ENV_KEY", "sk-from-env")
|
|
config = create_responses_config_class(_provider("ve_env", api_key_env="VE_ENV_KEY"))()
|
|
headers = config.validate_environment(headers={}, model="m", litellm_params=None)
|
|
assert headers["Authorization"] == "Bearer sk-from-env"
|
|
|
|
def test_explicit_key_wins_over_the_env_var(self, monkeypatch):
|
|
monkeypatch.setenv("VE_LOSER_KEY", "sk-from-env")
|
|
config = create_responses_config_class(_provider("ve_precedence", api_key_env="VE_LOSER_KEY"))()
|
|
headers = config.validate_environment(
|
|
headers={}, model="m", litellm_params=GenericLiteLLMParams(api_key="sk-wins")
|
|
)
|
|
assert headers["Authorization"] == "Bearer sk-wins"
|
|
|
|
def test_no_key_anywhere_leaves_the_header_unset(self, monkeypatch):
|
|
monkeypatch.delenv("VE_MISSING_KEY", raising=False)
|
|
config = create_responses_config_class(_provider("ve_missing", api_key_env="VE_MISSING_KEY"))()
|
|
assert config.validate_environment(headers={}, model="m", litellm_params=None) == {}
|
|
|
|
def test_existing_headers_are_preserved(self):
|
|
config = create_responses_config_class(_provider("ve_preserve"))()
|
|
headers = config.validate_environment(
|
|
headers={"X-Trace": "abc"},
|
|
model="m",
|
|
litellm_params=GenericLiteLLMParams(api_key="sk-1"),
|
|
)
|
|
assert headers["X-Trace"] == "abc"
|
|
|
|
|
|
class TestGetCompleteUrl:
|
|
def test_explicit_api_base_gets_the_responses_suffix(self):
|
|
config = create_responses_config_class(_provider("url_explicit"))()
|
|
assert config.get_complete_url(api_base="https://host/v1", litellm_params={}) == "https://host/v1/responses"
|
|
|
|
def test_trailing_slash_is_stripped_before_appending(self):
|
|
config = create_responses_config_class(_provider("url_slash"))()
|
|
assert config.get_complete_url(api_base="https://host/v1/", litellm_params={}) == "https://host/v1/responses"
|
|
|
|
def test_falls_back_to_the_api_base_env_var(self, monkeypatch):
|
|
monkeypatch.setenv("URL_BASE_ENV", "https://from-env/v1")
|
|
config = create_responses_config_class(_provider("url_env", api_base_env="URL_BASE_ENV"))()
|
|
assert config.get_complete_url(api_base=None, litellm_params={}) == "https://from-env/v1/responses"
|
|
|
|
def test_falls_back_to_the_configured_base_url_last(self, monkeypatch):
|
|
monkeypatch.delenv("URL_UNSET_ENV", raising=False)
|
|
config = create_responses_config_class(_provider("url_base_url", api_base_env="URL_UNSET_ENV"))()
|
|
assert config.get_complete_url(api_base=None, litellm_params={}) == "https://api.example.com/v1/responses"
|
|
|
|
def test_explicit_api_base_wins_over_the_env_var(self, monkeypatch):
|
|
monkeypatch.setenv("URL_LOSER_ENV", "https://from-env/v1")
|
|
config = create_responses_config_class(_provider("url_precedence", api_base_env="URL_LOSER_ENV"))()
|
|
assert (
|
|
config.get_complete_url(api_base="https://explicit/v1", litellm_params={})
|
|
== "https://explicit/v1/responses"
|
|
)
|
|
|
|
def test_no_base_anywhere_raises_naming_the_provider(self):
|
|
provider = _provider("url_none")
|
|
provider.base_url = None
|
|
config = create_responses_config_class(provider)()
|
|
with pytest.raises(ValueError, match="url_none"):
|
|
config.get_complete_url(api_base=None, litellm_params={})
|
|
|
|
|
|
class TestForceStoreFalse:
|
|
def test_force_store_false_overrides_the_caller(self):
|
|
config = create_responses_config_class(
|
|
_provider("store_forced", special_handling={"force_store_false": True})
|
|
)()
|
|
params = {"store": True}
|
|
config.transform_responses_api_request(
|
|
model="m",
|
|
input="hi",
|
|
response_api_optional_request_params=params,
|
|
litellm_params=GenericLiteLLMParams(),
|
|
headers={},
|
|
)
|
|
assert params["store"] is False
|
|
|
|
def test_without_the_flag_the_callers_store_value_is_left_alone(self):
|
|
config = create_responses_config_class(_provider("store_untouched"))()
|
|
params = {"store": True}
|
|
config.transform_responses_api_request(
|
|
model="m",
|
|
input="hi",
|
|
response_api_optional_request_params=params,
|
|
litellm_params=GenericLiteLLMParams(),
|
|
headers={},
|
|
)
|
|
assert params["store"] is True
|
|
|
|
|
|
class TestWebSearchRequestsFromToolUsage:
|
|
def test_counts_only_paid_search_tools(self):
|
|
payload = {"usage": {"tool_usage": {"web_search": 2, "image_search": 1, "code_interpreter": 3, "web_extractor": 1}}}
|
|
assert dynamic_config.web_search_requests_from_tool_usage(payload) == 3
|
|
|
|
@pytest.mark.parametrize(
|
|
"payload",
|
|
[
|
|
{"usage": {"prompt_tokens": 1}},
|
|
{"usage": {"tool_usage": {"code_interpreter": 2}}},
|
|
{"usage": {"tool_usage": {"web_search": "2"}}},
|
|
{"usage": {"tool_usage": {"web_search": True}}},
|
|
{"usage": {"tool_usage": []}},
|
|
{"usage": None},
|
|
"not a mapping",
|
|
],
|
|
)
|
|
def test_anything_but_a_positive_search_count_is_none(self, payload):
|
|
assert dynamic_config.web_search_requests_from_tool_usage(payload) is None
|