diff --git a/litellm/constants.py b/litellm/constants.py index 665ab771726..88a324a9d70 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1023,6 +1023,7 @@ openai_compatible_endpoints: Final[list[str]] = [ "https://api.scx.ai/v1", "https://api.prisminference.com/v1", "https://api.reka.ai/v1", + "https://api.inworld.ai/v1", "https://gigachat.devices.sberbank.ru/api/v1", ] @@ -1101,6 +1102,7 @@ openai_compatible_providers: Final[list] = [ "prism", "sail", "reka", + "inworld", ] OPENAI_AUDIO_TRANSCRIPTION_PROVIDERS: Final = frozenset({"openai"} | frozenset(openai_compatible_providers)) diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index aa8a17c3824..70db04c3d94 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -239,5 +239,10 @@ "/v1/responses", "/v1/messages" ] + }, + "inworld": { + "base_url": "https://api.inworld.ai/v1", + "api_key_env": "INWORLD_API_KEY", + "api_base_env": "INWORLD_API_BASE" } } diff --git a/litellm/main.py b/litellm/main.py index d8e62ebcdad..59cc68e4059 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -8465,7 +8465,8 @@ def speech( # set API KEY api_key = ( api_key - or litellm.api_key # for deepinfra/perplexity/anyscale we check in get_llm_provider and pass in the api key from there + or dynamic_api_key # key resolved by get_llm_provider, e.g. INWORLD_API_KEY for JSON-configured providers + or litellm.api_key or litellm.openai_key or get_secret("OPENAI_API_KEY") ) diff --git a/litellm/provider_endpoints_support_backup.json b/litellm/provider_endpoints_support_backup.json index a10f2f93d48..a2812dbab70 100644 --- a/litellm/provider_endpoints_support_backup.json +++ b/litellm/provider_endpoints_support_backup.json @@ -2154,6 +2154,24 @@ "interactions": false } }, + "inworld": { + "display_name": "Inworld (`inworld`)", + "url": "https://docs.litellm.ai/docs/providers/inworld", + "endpoints": { + "chat_completions": true, + "messages": true, + "responses": false, + "embeddings": false, + "image_generations": false, + "audio_transcriptions": true, + "audio_speech": true, + "moderations": false, + "batches": false, + "rerank": false, + "a2a": false, + "interactions": false + } + }, "scaleway": { "display_name": "Scaleway (`scaleway`)", "url": "https://docs.litellm.ai/docs/providers/scaleway", diff --git a/litellm/proxy/public_endpoints/provider_create_fields.json b/litellm/proxy/public_endpoints/provider_create_fields.json index 4a6a88f9a86..da0cec6564a 100644 --- a/litellm/proxy/public_endpoints/provider_create_fields.json +++ b/litellm/proxy/public_endpoints/provider_create_fields.json @@ -3231,6 +3231,34 @@ ], "default_model_placeholder": "reka/reka-flash" }, + { + "provider": "INWORLD", + "provider_display_name": "Inworld", + "litellm_provider": "inworld", + "credential_fields": [ + { + "key": "api_base", + "label": "API Base", + "placeholder": "https://api.inworld.ai/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": "inworld/inworld/models/gemma-4-31b-it" + }, { "provider": "Sail", "provider_display_name": "Sail", diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 0bcb732a0f5..5401a64adf9 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4389,6 +4389,7 @@ class LlmProviders(str, Enum): META = "meta" SAIL = "sail" REKA = "reka" + INWORLD = "inworld" LITELLM_AGENT = "litellm_agent" CURSOR = "cursor" BEDROCK_MANTLE = "bedrock_mantle" diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index 45104d40018..b1d6c57ad29 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -3214,6 +3214,24 @@ "interactions": false } }, + "inworld": { + "display_name": "Inworld (`inworld`)", + "url": "https://docs.litellm.ai/docs/providers/inworld", + "endpoints": { + "chat_completions": true, + "messages": true, + "responses": false, + "embeddings": false, + "image_generations": false, + "audio_transcriptions": true, + "audio_speech": true, + "moderations": false, + "batches": false, + "rerank": false, + "a2a": false, + "interactions": false + } + }, "charity_engine": { "display_name": "Charity Engine (`charity_engine`)", "url": "https://docs.litellm.ai/docs/providers/charity_engine", diff --git a/tests/unit/llms/openai_like/test_inworld_provider.py b/tests/unit/llms/openai_like/test_inworld_provider.py new file mode 100644 index 00000000000..4f03a01e12b --- /dev/null +++ b/tests/unit/llms/openai_like/test_inworld_provider.py @@ -0,0 +1,234 @@ +import json +from pathlib import Path +from typing import Final + +import pytest +import respx + +import litellm +from litellm.caching.llm_caching_handler import LLMClientCache + +_CHAT_COMPLETION: Final = { + "id": "chatcmpl_inworld", + "object": "chat.completion", + "created": 1_790_000_000, + "model": "inworld/gemma-4-31b-it", + "choices": [ + { + "index": 0, + "message": {"role": "assistant", "content": "Hello from Inworld"}, + "finish_reason": "stop", + } + ], + "usage": {"prompt_tokens": 4, "completion_tokens": 3, "total_tokens": 7}, +} + + +def test_inworld_is_a_registered_provider(): + assert litellm.LlmProviders.INWORLD.value == "inworld" + assert "inworld" in litellm.provider_list + assert "inworld" in litellm.constants.openai_compatible_providers + + +def test_inworld_provider_resolution(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("INWORLD_API_KEY", "inworld-test-key") + + model, provider, api_key, api_base = get_llm_provider( + model="inworld/inworld/models/gemma-4-31b-it", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert model == "inworld/models/gemma-4-31b-it" + assert provider == "inworld" + assert api_key == "inworld-test-key" + assert api_base == "https://api.inworld.ai/v1" + + +def test_inworld_provider_keeps_explicit_credentials(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("INWORLD_API_KEY", "inworld-env-key") + monkeypatch.setenv("INWORLD_API_BASE", "https://inworld.env.example/v1") + + _, provider, api_key, api_base = get_llm_provider( + model="inworld/inworld/models/gemma-4-31b-it", + custom_llm_provider=None, + api_base="https://inworld.internal.example/v1", + api_key="inworld-explicit-key", + ) + + assert provider == "inworld" + assert api_key == "inworld-explicit-key" + assert api_base == "https://inworld.internal.example/v1" + + +def test_inworld_api_base_env_overrides_default(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("INWORLD_API_KEY", "inworld-env-key") + monkeypatch.setenv("INWORLD_API_BASE", "https://api.eu.inworld.ai/v1") + + _, provider, _, api_base = get_llm_provider( + model="inworld/inworld/models/gemma-4-31b-it", + custom_llm_provider=None, + api_base=None, + api_key=None, + ) + + assert provider == "inworld" + assert api_base == "https://api.eu.inworld.ai/v1" + + +def test_inworld_api_base_autodetects_provider(monkeypatch: pytest.MonkeyPatch): + from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider + + monkeypatch.setenv("INWORLD_API_KEY", "inworld-env-key") + + model, provider, api_key, api_base = get_llm_provider( + model="gemma-4-31b-it", + custom_llm_provider=None, + api_base="https://api.inworld.ai/v1", + api_key=None, + ) + + assert model == "gemma-4-31b-it" + assert provider == "inworld" + assert api_key == "inworld-env-key" + assert api_base == "https://api.inworld.ai/v1" + + +def test_inworld_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()) + inworld = next(provider for provider in providers if provider["litellm_provider"] == "inworld") + + assert inworld["provider"] == "INWORLD" + assert inworld["provider_display_name"] == "Inworld" + assert inworld["default_model_placeholder"] == "inworld/inworld/models/gemma-4-31b-it" + assert {field["key"]: field["required"] for field in inworld["credential_fields"]} == { + "api_base": False, + "api_key": True, + } + + +def test_inworld_supported_endpoints(): + expected: Final = { + "chat_completions": True, + "messages": True, + "responses": False, + "embeddings": False, + "image_generations": False, + "audio_transcriptions": True, + "audio_speech": True, + "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"]["inworld"]["endpoints"] == expected + assert json.loads(root_path.read_text())["providers"]["inworld"]["endpoints"] == expected + + +def test_inworld_chat_completion_request(): + with respx.mock() as upstream: + route: Final = upstream.post("https://api.inworld.ai/v1/chat/completions").respond(200, json=_CHAT_COMPLETION) + response: Final = litellm.completion( + model="inworld/inworld/models/gemma-4-31b-it", + messages=[{"role": "user", "content": "Say hello"}], + api_key="inworld-test-key", + ) + + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert route.call_count == 1 + assert str(request.url) == "https://api.inworld.ai/v1/chat/completions" + assert request.headers["authorization"] == "Bearer inworld-test-key" + # Inworld-hosted model IDs live under the "inworld/" namespace upstream; only LiteLLM's routing prefix is removed. + assert body["model"] == "inworld/models/gemma-4-31b-it" + assert body["messages"] == [{"role": "user", "content": "Say hello"}] + assert response.choices[0].message.content == "Hello from Inworld" + + +def test_inworld_routes_third_party_model_ids_unchanged(): + with respx.mock() as upstream: + route: Final = upstream.post("https://api.inworld.ai/v1/chat/completions").respond(200, json=_CHAT_COMPLETION) + litellm.completion( + model="inworld/openai/gpt-5-mini", + messages=[{"role": "user", "content": "Say hello"}], + api_key="inworld-test-key", + ) + + assert json.loads(route.calls.last.request.content)["model"] == "openai/gpt-5-mini" + + +@pytest.mark.asyncio +async def test_inworld_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.inworld.ai/v1/chat/completions").respond(200, json=_CHAT_COMPLETION) + response: Final = await litellm.anthropic.messages.acreate( + model="inworld/inworld/models/gemma-4-31b-it", + messages=[{"role": "user", "content": "Say hello"}], + max_tokens=32, + api_key="inworld-test-key", + ) + + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert route.call_count == 1 + assert request.headers["authorization"] == "Bearer inworld-test-key" + assert body["model"] == "inworld/models/gemma-4-31b-it" + assert body["max_tokens"] == 32 + assert response["content"][0]["text"] == "Hello from Inworld" + + +def test_inworld_speech_uses_provider_api_key_from_env(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("INWORLD_API_KEY", "inworld-env-key") + monkeypatch.delenv("OPENAI_API_KEY", raising=False) + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache()) + with respx.mock() as upstream: + route: Final = upstream.post("https://api.inworld.ai/v1/audio/speech").respond( + 200, content=b"ID3-audio", headers={"Content-Type": "audio/mpeg"} + ) + response: Final = litellm.speech( + model="inworld/inworld-tts-2", + voice="Dennis", + input="Hello from Inworld", + ) + + request: Final = route.calls.last.request + body: Final = json.loads(request.content) + assert route.call_count == 1 + assert request.headers["authorization"] == "Bearer inworld-env-key" + assert body["model"] == "inworld-tts-2" + assert body["voice"] == "Dennis" + assert body["input"] == "Hello from Inworld" + assert response.content == b"ID3-audio" + + +def test_inworld_transcription_request(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv("INWORLD_API_KEY", "inworld-env-key") + monkeypatch.setattr(litellm, "in_memory_llm_clients_cache", LLMClientCache()) + with respx.mock() as upstream: + route: Final = upstream.post("https://api.inworld.ai/v1/audio/transcriptions").respond( + 200, json={"text": "Hello from Inworld"} + ) + response: Final = litellm.transcription( + model="inworld/inworld/inworld-stt-1", + file=("hello.mp3", b"ID3-audio", "audio/mpeg"), + ) + + request: Final = route.calls.last.request + assert route.call_count == 1 + assert request.headers["authorization"] == "Bearer inworld-env-key" + assert b'name="model"\r\n\r\ninworld/inworld-stt-1' in request.content + assert response.text == "Hello from Inworld"