fix(together_ai): let an explicit api_key beat the Together env key on api_base match

This commit is contained in:
mateo-berri 2026-08-25 10:39:10 -07:00
parent b46f17faf5
commit 5e6b6c6281
3 changed files with 14 additions and 2 deletions

View file

@ -274,7 +274,7 @@ def get_llm_provider(
dynamic_api_key = get_secret_str("DEEPSEEK_API_KEY")
elif endpoint == "api.together.ai/v1" or endpoint == "api.together.xyz/v1":
custom_llm_provider = "together_ai"
dynamic_api_key = (
dynamic_api_key = api_key or (
get_secret_str("TOGETHER_API_KEY")
or get_secret_str("TOGETHER_AI_API_KEY")
or get_secret_str("TOGETHERAI_API_KEY")

View file

@ -51,7 +51,7 @@ class TogetherAIRerank(BaseLLM):
raise ValueError("TogetherAI does not support max_chunks_per_doc")
if _is_async:
return self.async_rerank(request_data_dict, api_key, api_base) # Call async method
return self.async_rerank(request_data_dict, api_key, api_base)
response: Final = client.post(
_rerank_url(api_base),

View file

@ -165,6 +165,18 @@ class TestTogetherApiBaseResolvesProvider:
assert returned_api_base == api_base
assert model == "some-model"
def test_explicit_api_key_beats_together_env_key(self, monkeypatch):
monkeypatch.setenv("TOGETHER_API_KEY", "together-key-from-env")
_, provider, dynamic_api_key, _ = get_llm_provider(
model="some-model",
api_base="https://api.together.ai/v1",
api_key="explicit-caller-key",
)
assert provider == "together_ai"
assert dynamic_api_key == "explicit-caller-key"
def test_together_default_api_base_is_together_ai(self, monkeypatch):
monkeypatch.delenv("TOGETHER_AI_API_BASE", raising=False)