The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(together_ai): select the live model from the cost map
Yuneng Jiangb4781317012c
diff --git a/tests/_live_test_helpers.py b/tests/_live_test_helpers.pyindex a79b81e82c1..6b39f37921d 100644--- a/tests/_live_test_helpers.py+++ b/tests/_live_test_helpers.py@@ -1,4 +1,7 @@import os+from collections.abc import Mapping+from datetime import date+from typing import Anyimport pytest@@ -8,3 +11,36 @@ def _skip_live_prompt_caching_test():pytest.skip("Live prompt-caching E2E tests are opt-in")if os.environ.get("CASSETTE_REDIS_URL"):pytest.skip("Live prompt-caching E2E tests cannot run under VCR replay")+++def cheapest_together_chat_model(*capability_flags: str) -> str:+ import litellm++ today = date.today().isoformat()++ def qualifies(name: str, entry: Mapping[str, Any]) -> bool:+ deprecation_date = entry.get("deprecation_date")+ return (+ name.startswith("together_ai/")+ and entry.get("litellm_provider") == "together_ai"+ and entry.get("mode") == "chat"+ and (deprecation_date is None or deprecation_date > today)+ and (entry.get("input_cost_per_token") or 0.0) > 0+ and (entry.get("output_cost_per_token") or 0.0) > 0+ and all(bool(entry.get(flag)) for flag in capability_flags)+ )++ candidates = sorted(+ (+ name+ for name, entry in litellm.model_cost.items()+ if isinstance(entry, Mapping) and qualifies(name, entry)+ ),+ key=lambda name: (+ litellm.model_cost[name].get("input_cost_per_token") or 0.0,+ litellm.model_cost[name].get("output_cost_per_token") or 0.0,+ name,+ ),+ )+ assert candidates, f"no live together_ai chat model in the cost map satisfies {capability_flags}"+ return candidates[0]diff --git a/tests/llm_translation/test_together_ai.py b/tests/llm_translation/test_together_ai.pyindex fd7ad40ed11..7a49d46b528 100644--- a/tests/llm_translation/test_together_ai.py+++ b/tests/llm_translation/test_together_ai.py@@ -3,6 +3,7 @@ Test TogetherAI LLM"""from base_llm_unit_tests import BaseLLMChatTest+from tests._live_test_helpers import cheapest_together_chat_modelimport jsonimport osfrom datetime import datetime@@ -16,7 +17,11 @@ import pytestclass TestTogetherAI(BaseLLMChatTest):def get_base_completion_call_args(self) -> dict:litellm.set_verbose = True- return {"model": "together_ai/openai/gpt-oss-20b"}+ return {+ "model": cheapest_together_chat_model(+ "supports_function_calling", "supports_response_schema"+ )+ }def test_tool_call_no_arguments(self, tool_call_no_arguments):"""Test that tool calls with no arguments is translated correctly. Relevant issue: https://github.com/BerriAI/litellm/issues/6833"""diff --git a/tests/local_testing/test_text_completion.py b/tests/local_testing/test_text_completion.pyindex a814ce6d303..b15037a2fcd 100644--- a/tests/local_testing/test_text_completion.py+++ b/tests/local_testing/test_text_completion.py@@ -1,7 +1,11 @@import asyncioimport json+import os+import sysimport traceback+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))+from dotenv import load_dotenvload_dotenv()@@ -12,6 +16,7 @@ from unittest.mock import MagicMock, patchimport pytestimport litellm+from tests._live_test_helpers import cheapest_together_chat_modelfrom litellm import (RateLimitError,TextCompletionResponse,@@ -4030,7 +4035,7 @@ def test_async_text_completion_together_ai():async def test_get_response():try:response = await litellm.atext_completion(- model="together_ai/openai/gpt-oss-20b",+ model=cheapest_together_chat_model(),prompt="good morning",max_tokens=10,)