mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-14 04:09:09 +00:00
Merge 16ae87c2b5 into e2971e0af4
This commit is contained in:
commit
18287a7ae1
7 changed files with 298 additions and 0 deletions
|
|
@ -971,6 +971,7 @@ openai_compatible_endpoints: Final[list] = [
|
|||
"https://api.scx.ai/v1",
|
||||
"https://api.prisminference.com/v1",
|
||||
"https://api.reka.ai/v1",
|
||||
"https://api.apimodels.app/v1",
|
||||
"https://gigachat.devices.sberbank.ru/api/v1",
|
||||
]
|
||||
|
||||
|
|
@ -1048,6 +1049,7 @@ openai_compatible_providers: Final[list] = [
|
|||
"prism",
|
||||
"sail",
|
||||
"reka",
|
||||
"apimodels",
|
||||
]
|
||||
|
||||
OPENAI_AUDIO_TRANSCRIPTION_PROVIDERS: Final = frozenset({"openai"} | frozenset(openai_compatible_providers))
|
||||
|
|
|
|||
|
|
@ -223,5 +223,10 @@
|
|||
"base_url": "https://api.reka.ai/v1",
|
||||
"api_key_env": "REKA_API_KEY",
|
||||
"api_base_env": "REKA_API_BASE"
|
||||
},
|
||||
"apimodels": {
|
||||
"base_url": "https://api.apimodels.app/v1",
|
||||
"api_key_env": "APIMODELS_API_KEY",
|
||||
"api_base_env": "APIMODELS_API_BASE"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,6 +193,24 @@
|
|||
"a2a": false
|
||||
}
|
||||
},
|
||||
"apimodels": {
|
||||
"display_name": "apimodels.app (`apimodels`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/apimodels",
|
||||
"endpoints": {
|
||||
"chat_completions": true,
|
||||
"messages": true,
|
||||
"responses": true,
|
||||
"embeddings": false,
|
||||
"image_generations": false,
|
||||
"audio_transcriptions": false,
|
||||
"audio_speech": false,
|
||||
"moderations": false,
|
||||
"batches": false,
|
||||
"rerank": false,
|
||||
"a2a": false,
|
||||
"interactions": false
|
||||
}
|
||||
},
|
||||
"assemblyai": {
|
||||
"display_name": "AssemblyAI (`assemblyai`)",
|
||||
"url": "https://docs.litellm.ai/docs/pass_through/assembly_ai",
|
||||
|
|
|
|||
|
|
@ -3143,6 +3143,34 @@
|
|||
],
|
||||
"default_model_placeholder": "scx-ai/GLM-5.2"
|
||||
},
|
||||
{
|
||||
"provider": "APIMODELS",
|
||||
"provider_display_name": "apimodels.app",
|
||||
"litellm_provider": "apimodels",
|
||||
"credential_fields": [
|
||||
{
|
||||
"key": "api_base",
|
||||
"label": "API Base",
|
||||
"placeholder": "https://api.apimodels.app/v1",
|
||||
"tooltip": null,
|
||||
"required": false,
|
||||
"field_type": "text",
|
||||
"options": null,
|
||||
"default_value": null
|
||||
},
|
||||
{
|
||||
"key": "api_key",
|
||||
"label": "API Key",
|
||||
"placeholder": null,
|
||||
"tooltip": null,
|
||||
"required": true,
|
||||
"field_type": "password",
|
||||
"options": null,
|
||||
"default_value": null
|
||||
}
|
||||
],
|
||||
"default_model_placeholder": "apimodels/claude-opus-5-5"
|
||||
},
|
||||
{
|
||||
"provider": "Snowflake",
|
||||
"provider_display_name": "Snowflake",
|
||||
|
|
|
|||
|
|
@ -4250,6 +4250,7 @@ class LlmProviders(str, Enum):
|
|||
META = "meta"
|
||||
SAIL = "sail"
|
||||
REKA = "reka"
|
||||
APIMODELS = "apimodels"
|
||||
LITELLM_AGENT = "litellm_agent"
|
||||
CURSOR = "cursor"
|
||||
BEDROCK_MANTLE = "bedrock_mantle"
|
||||
|
|
|
|||
|
|
@ -194,6 +194,24 @@
|
|||
"a2a": false
|
||||
}
|
||||
},
|
||||
"apimodels": {
|
||||
"display_name": "apimodels.app (`apimodels`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/apimodels",
|
||||
"endpoints": {
|
||||
"chat_completions": true,
|
||||
"messages": true,
|
||||
"responses": true,
|
||||
"embeddings": false,
|
||||
"image_generations": false,
|
||||
"audio_transcriptions": false,
|
||||
"audio_speech": false,
|
||||
"moderations": false,
|
||||
"batches": false,
|
||||
"rerank": false,
|
||||
"a2a": false,
|
||||
"interactions": false
|
||||
}
|
||||
},
|
||||
"aihubmix": {
|
||||
"display_name": "AIHubMix (`aihubmix`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/aihubmix",
|
||||
|
|
|
|||
226
tests/unit/llms/openai_like/test_apimodels_provider.py
Normal file
226
tests/unit/llms/openai_like/test_apimodels_provider.py
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
|
||||
import litellm
|
||||
from litellm.caching.llm_caching_handler import LLMClientCache
|
||||
|
||||
|
||||
def _chat_completion(model: str) -> dict:
|
||||
return {
|
||||
"id": "chatcmpl_apimodels",
|
||||
"object": "chat.completion",
|
||||
"created": 1_790_000_000,
|
||||
"model": model,
|
||||
"choices": [
|
||||
{
|
||||
"index": 0,
|
||||
"message": {"role": "assistant", "content": "Hello from APIMODELS"},
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
"usage": {"prompt_tokens": 4, "completion_tokens": 3, "total_tokens": 7},
|
||||
}
|
||||
|
||||
|
||||
def test_apimodels_is_a_registered_provider():
|
||||
assert litellm.LlmProviders.APIMODELS.value == "apimodels"
|
||||
assert "apimodels" in litellm.provider_list
|
||||
assert "apimodels" in litellm.constants.openai_compatible_providers
|
||||
|
||||
|
||||
def test_apimodels_provider_resolution(monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
monkeypatch.setenv("APIMODELS_API_KEY", "apimodels-test-key")
|
||||
monkeypatch.delenv("APIMODELS_API_BASE", raising=False)
|
||||
|
||||
model, provider, api_key, api_base = get_llm_provider(
|
||||
model="apimodels/gpt-5.6-luna",
|
||||
custom_llm_provider=None,
|
||||
api_base=None,
|
||||
api_key=None,
|
||||
)
|
||||
|
||||
assert model == "gpt-5.6-luna"
|
||||
assert provider == "apimodels"
|
||||
assert api_key == "apimodels-test-key"
|
||||
assert api_base == "https://api.apimodels.app/v1"
|
||||
|
||||
|
||||
def test_apimodels_provider_keeps_explicit_credentials(monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
monkeypatch.setenv("APIMODELS_API_KEY", "apimodels-env-key")
|
||||
monkeypatch.setenv("APIMODELS_API_BASE", "https://apimodels.env.example/v1")
|
||||
|
||||
_, provider, api_key, api_base = get_llm_provider(
|
||||
model="apimodels/gpt-5.6-luna",
|
||||
custom_llm_provider=None,
|
||||
api_base="https://apimodels.internal.example/v1",
|
||||
api_key="apimodels-explicit-key",
|
||||
)
|
||||
|
||||
assert provider == "apimodels"
|
||||
assert api_key == "apimodels-explicit-key"
|
||||
assert api_base == "https://apimodels.internal.example/v1"
|
||||
|
||||
|
||||
def test_apimodels_api_base_env_overrides_default(monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
monkeypatch.setenv("APIMODELS_API_KEY", "apimodels-env-key")
|
||||
monkeypatch.setenv("APIMODELS_API_BASE", "https://apimodels.env.example/v1")
|
||||
|
||||
_, provider, _, api_base = get_llm_provider(
|
||||
model="apimodels/gpt-5.6-luna",
|
||||
custom_llm_provider=None,
|
||||
api_base=None,
|
||||
api_key=None,
|
||||
)
|
||||
|
||||
assert provider == "apimodels"
|
||||
assert api_base == "https://apimodels.env.example/v1"
|
||||
|
||||
|
||||
def test_apimodels_api_base_autodetects_provider(monkeypatch: pytest.MonkeyPatch):
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
monkeypatch.setenv("APIMODELS_API_KEY", "apimodels-env-key")
|
||||
|
||||
model, provider, api_key, api_base = get_llm_provider(
|
||||
model="gpt-5.6-luna",
|
||||
custom_llm_provider=None,
|
||||
api_base="https://api.apimodels.app/v1",
|
||||
api_key=None,
|
||||
)
|
||||
|
||||
assert model == "gpt-5.6-luna"
|
||||
assert provider == "apimodels"
|
||||
assert api_key == "apimodels-env-key"
|
||||
assert api_base == "https://api.apimodels.app/v1"
|
||||
|
||||
|
||||
def test_apimodels_is_available_in_add_model_form():
|
||||
fields_path = Path(litellm.__file__).parent / "proxy" / "public_endpoints" / "provider_create_fields.json"
|
||||
providers = json.loads(fields_path.read_text())
|
||||
apimodels = next(provider for provider in providers if provider["litellm_provider"] == "apimodels")
|
||||
|
||||
assert apimodels["provider"] == "APIMODELS"
|
||||
assert apimodels["provider_display_name"] == "apimodels.app"
|
||||
assert apimodels["default_model_placeholder"] == "apimodels/claude-opus-5-5"
|
||||
assert {field["key"]: field["required"] for field in apimodels["credential_fields"]} == {
|
||||
"api_base": False,
|
||||
"api_key": True,
|
||||
}
|
||||
|
||||
|
||||
def test_apimodels_supported_endpoints():
|
||||
expected: Final = {
|
||||
"chat_completions": True,
|
||||
"messages": True,
|
||||
"responses": True,
|
||||
"embeddings": False,
|
||||
"image_generations": False,
|
||||
"audio_transcriptions": False,
|
||||
"audio_speech": False,
|
||||
"moderations": False,
|
||||
"batches": False,
|
||||
"rerank": False,
|
||||
"a2a": False,
|
||||
"interactions": False,
|
||||
}
|
||||
backup_path = Path(litellm.__file__).parent / "provider_endpoints_support_backup.json"
|
||||
root_path = Path(litellm.__file__).parent.parent / "provider_endpoints_support.json"
|
||||
|
||||
assert json.loads(backup_path.read_text())["providers"]["apimodels"]["endpoints"] == expected
|
||||
assert json.loads(root_path.read_text())["providers"]["apimodels"]["endpoints"] == expected
|
||||
|
||||
|
||||
def test_apimodels_chat_completion_request_uses_env_api_key(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setenv("APIMODELS_API_KEY", "apimodels-env-key")
|
||||
monkeypatch.delenv("APIMODELS_API_BASE", raising=False)
|
||||
with respx.mock() as upstream:
|
||||
route: Final = upstream.post("https://api.apimodels.app/v1/chat/completions").respond(
|
||||
200, json=_chat_completion("gpt-5.6-luna")
|
||||
)
|
||||
response: Final = litellm.completion(
|
||||
model="apimodels/gpt-5.6-luna",
|
||||
messages=[{"role": "user", "content": "Say hello"}],
|
||||
)
|
||||
|
||||
request: Final = route.calls.last.request
|
||||
body: Final = json.loads(request.content)
|
||||
assert route.call_count == 1
|
||||
assert str(request.url) == "https://api.apimodels.app/v1/chat/completions"
|
||||
assert request.headers["authorization"] == "Bearer apimodels-env-key"
|
||||
assert body["model"] == "gpt-5.6-luna"
|
||||
assert body["messages"] == [{"role": "user", "content": "Say hello"}]
|
||||
assert response.choices[0].message.content == "Hello from APIMODELS"
|
||||
|
||||
|
||||
def test_apimodels_chat_completion_request_honours_api_base_override():
|
||||
with respx.mock() as upstream:
|
||||
route: Final = upstream.post("https://apimodels.internal.example/v1/chat/completions").respond(
|
||||
200, json=_chat_completion("gpt-5.6-luna")
|
||||
)
|
||||
response: Final = litellm.completion(
|
||||
model="apimodels/gpt-5.6-luna",
|
||||
messages=[{"role": "user", "content": "Say hello"}],
|
||||
api_base="https://apimodels.internal.example/v1",
|
||||
api_key="apimodels-explicit-key",
|
||||
)
|
||||
|
||||
request: Final = route.calls.last.request
|
||||
assert route.call_count == 1
|
||||
assert str(request.url) == "https://apimodels.internal.example/v1/chat/completions"
|
||||
assert request.headers["authorization"] == "Bearer apimodels-explicit-key"
|
||||
assert response.choices[0].message.content == "Hello from APIMODELS"
|
||||
|
||||
|
||||
def test_apimodels_responses_request_is_bridged_to_chat_completions():
|
||||
with respx.mock() as upstream:
|
||||
route: Final = upstream.post("https://api.apimodels.app/v1/chat/completions").respond(
|
||||
200, json=_chat_completion("claude-opus-5-5")
|
||||
)
|
||||
response: Final = litellm.responses(
|
||||
model="apimodels/claude-opus-5-5",
|
||||
input="Say hello",
|
||||
api_key="apimodels-test-key",
|
||||
)
|
||||
|
||||
request: Final = route.calls.last.request
|
||||
body: Final = json.loads(request.content)
|
||||
assert route.call_count == 1
|
||||
assert request.headers["authorization"] == "Bearer apimodels-test-key"
|
||||
assert body["model"] == "claude-opus-5-5"
|
||||
assert body["messages"] == [{"role": "user", "content": "Say hello"}]
|
||||
assert response.output[0].content[0].text == "Hello from APIMODELS"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_apimodels_anthropic_messages_request_is_bridged_to_chat_completions(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)
|
||||
monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache())
|
||||
with respx.mock() as upstream:
|
||||
route: Final = upstream.post("https://api.apimodels.app/v1/chat/completions").respond(
|
||||
200, json=_chat_completion("gpt-5.6-luna")
|
||||
)
|
||||
response: Final = await litellm.anthropic.messages.acreate(
|
||||
model="apimodels/gpt-5.6-luna",
|
||||
messages=[{"role": "user", "content": "Say hello"}],
|
||||
max_tokens=32,
|
||||
api_key="apimodels-test-key",
|
||||
)
|
||||
|
||||
request: Final = route.calls.last.request
|
||||
body: Final = json.loads(request.content)
|
||||
assert route.call_count == 1
|
||||
assert request.headers["authorization"] == "Bearer apimodels-test-key"
|
||||
assert body["model"] == "gpt-5.6-luna"
|
||||
assert body["messages"] == [{"role": "user", "content": "Say hello"}]
|
||||
assert body["max_tokens"] == 32
|
||||
assert response["content"][0]["text"] == "Hello from APIMODELS"
|
||||
Loading…
Add table
Reference in a new issue