From 82bcc602c386c66f1d3f1a2d251f589d10ffff9e Mon Sep 17 00:00:00 2001 From: cenab Date: Sun, 27 Sep 2026 02:52:05 -0600 Subject: [PATCH] feat(providers): add Tsubasa inference provider --- docs/my-website/docs/providers/tsubasa.md | 46 ++++++++++ litellm/constants.py | 1 + litellm/llms/openai_like/providers.json | 7 ++ ...odel_prices_and_context_window_backup.json | 28 ++++++ litellm/types/utils.py | 1 + model_prices_and_context_window.json | 28 ++++++ .../llms/openai_like/test_tsubasa_provider.py | 87 +++++++++++++++++++ 7 files changed, 198 insertions(+) create mode 100644 docs/my-website/docs/providers/tsubasa.md create mode 100644 tests/unit/llms/openai_like/test_tsubasa_provider.py diff --git a/docs/my-website/docs/providers/tsubasa.md b/docs/my-website/docs/providers/tsubasa.md new file mode 100644 index 00000000000..3eb8369d501 --- /dev/null +++ b/docs/my-website/docs/providers/tsubasa.md @@ -0,0 +1,46 @@ +# Tsubasa + +Tsubasa uses LiteLLM's existing OpenAI-compatible Chat Completions transport + +Tsubasa is currently in website-only mode. API access is unavailable, and live +tool-calling and structured-output qualification is pending. These examples are +for use after the service is enabled + +## API key + +Set `TSUBASA_API_KEY` in the process environment. LiteLLM resolves the public +endpoint automatically; no `api_base` override is required + +## Completion + +Select a public model with the `tsubasa/` provider prefix + +```python +from litellm import completion + +response = completion( + model="tsubasa/tsubasa-pro", + messages=[{"role": "user", "content": "Explain binary search."}], + max_tokens=256, +) +``` + +Use `tsubasa/tsubasa-fast` for the other public model. Both use +`https://api.tsubasa.sh/v1/chat/completions` + +## Streaming + +Set `stream=True` to receive Chat Completions chunks + +```python +stream = completion( + model="tsubasa/tsubasa-fast", + messages=[{"role": "user", "content": "Explain a stack."}], + stream=True, +) +for chunk in stream: + print(chunk.choices[0].delta.content or "", end="") +``` + +The integration does not declare Responses, embeddings, image, or audio support. +See [Tsubasa's API documentation](https://tsubasa.sh/docs) for availability diff --git a/litellm/constants.py b/litellm/constants.py index a292b654778..c9ac96599bc 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1019,6 +1019,7 @@ openai_compatible_providers: Final[list] = [ "ragflow", "pinstripes", # Pinstripes - JSON-configured provider "darkbloom", + "tsubasa", "meta", # Meta Model API (Muse Spark) - JSON-configured provider "cognition", "scx-ai", diff --git a/litellm/llms/openai_like/providers.json b/litellm/llms/openai_like/providers.json index ae09b48bd1e..54bed3ba00a 100644 --- a/litellm/llms/openai_like/providers.json +++ b/litellm/llms/openai_like/providers.json @@ -206,5 +206,12 @@ "api_key_env": "SAIL_API_KEY", "api_base_env": "SAIL_API_BASE", "supported_endpoints": ["/v1/chat/completions", "/v1/responses", "/v1/messages"] + }, + "tsubasa": { + "base_url": "https://api.tsubasa.sh/v1", + "api_key_env": "TSUBASA_API_KEY", + "param_mappings": { + "max_completion_tokens": "max_tokens" + } } } diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index b36d84ea027..d9c91b36eb3 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -77910,5 +77910,33 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true + }, + "tsubasa/tsubasa-fast": { + "max_input_tokens": 32768, + "max_output_tokens": 8192, + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 1e-06, + "litellm_provider": "tsubasa", + "mode": "chat", + "supports_system_messages": true, + "supports_function_calling": false, + "supports_parallel_function_calling": false, + "supports_response_schema": false, + "supports_vision": false, + "supports_reasoning": false + }, + "tsubasa/tsubasa-pro": { + "max_input_tokens": 32768, + "max_output_tokens": 16384, + "input_cost_per_token": 5e-07, + "output_cost_per_token": 4e-06, + "litellm_provider": "tsubasa", + "mode": "chat", + "supports_system_messages": true, + "supports_function_calling": false, + "supports_parallel_function_calling": false, + "supports_response_schema": false, + "supports_vision": false, + "supports_reasoning": false } } diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 8862df9dc22..b8f8dc94ddd 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -4140,6 +4140,7 @@ class LlmProviders(str, Enum): COGNITION = "cognition" SCX_AI = "scx-ai" DARKBLOOM = "darkbloom" + TSUBASA = "tsubasa" META = "meta" SAIL = "sail" LITELLM_AGENT = "litellm_agent" diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index b36d84ea027..d9c91b36eb3 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -77910,5 +77910,33 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true + }, + "tsubasa/tsubasa-fast": { + "max_input_tokens": 32768, + "max_output_tokens": 8192, + "input_cost_per_token": 2.0000000000000002e-07, + "output_cost_per_token": 1e-06, + "litellm_provider": "tsubasa", + "mode": "chat", + "supports_system_messages": true, + "supports_function_calling": false, + "supports_parallel_function_calling": false, + "supports_response_schema": false, + "supports_vision": false, + "supports_reasoning": false + }, + "tsubasa/tsubasa-pro": { + "max_input_tokens": 32768, + "max_output_tokens": 16384, + "input_cost_per_token": 5e-07, + "output_cost_per_token": 4e-06, + "litellm_provider": "tsubasa", + "mode": "chat", + "supports_system_messages": true, + "supports_function_calling": false, + "supports_parallel_function_calling": false, + "supports_response_schema": false, + "supports_vision": false, + "supports_reasoning": false } } diff --git a/tests/unit/llms/openai_like/test_tsubasa_provider.py b/tests/unit/llms/openai_like/test_tsubasa_provider.py new file mode 100644 index 00000000000..efb62ff97bc --- /dev/null +++ b/tests/unit/llms/openai_like/test_tsubasa_provider.py @@ -0,0 +1,87 @@ +import json +from typing import Final + +import httpx +import pytest + +from litellm import LlmProviders, completion +from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider +from litellm.llms.openai_like.json_loader import JSONProviderRegistry +from litellm.utils import ProviderConfigManager, get_model_info + + +@pytest.mark.parametrize("model_id", ("tsubasa-fast", "tsubasa-pro")) +def test_tsubasa_routes_named_models_and_resolves_credentials(model_id: str, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("TSUBASA_API_KEY", "test-credential") + registration: Final = JSONProviderRegistry.get("tsubasa") + assert registration is not None + model, provider, api_key, api_base = get_llm_provider(model=f"tsubasa/{model_id}") + assert (model, provider, api_key, api_base) == ( + model_id, + registration.slug, + "test-credential", + registration.base_url, + ) + config: Final = ProviderConfigManager.get_provider_chat_config(model=model_id, provider=LlmProviders.TSUBASA) + assert config is not None + assert ( + config.get_complete_url(api_base, api_key, model_id, {}, {}, stream=True) + == f"{registration.base_url}/chat/completions" + ) + assert config._get_openai_compatible_provider_info(None, "explicit-credential") == ( + registration.base_url, + "explicit-credential", + ) + assert config.map_openai_params({"max_completion_tokens": 64}, {}, model_id, False) == {"max_tokens": 64} + info: Final = get_model_info(model=f"tsubasa/{model_id}") + assert info["max_output_tokens"] <= info["max_input_tokens"] + assert info["litellm_provider"] == registration.slug + + +@pytest.mark.parametrize("model_id", ("tsubasa-fast", "tsubasa-pro")) +@pytest.mark.parametrize("stream", (False, True)) +def test_tsubasa_chat_transport(model_id: str, stream: bool, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("TSUBASA_API_KEY", "test-credential") + registration = JSONProviderRegistry.get("tsubasa") + assert registration is not None + + def send(_client: httpx.Client, request: httpx.Request, **_kwargs: object) -> httpx.Response: + assert str(request.url) == f"{registration.base_url}/chat/completions" + assert request.headers["authorization"] == "Bearer test-credential" + body = json.loads(request.content) + assert body["model"] == model_id + assert body["messages"] == [{"role": "user", "content": "Hello"}] + assert body["max_tokens"] == 32 + assert set(body) <= {"model", "messages", "max_tokens", "stream", "stream_options"} + result = { + "id": "chatcmpl-contract", + "created": 1, + "model": model_id, + "object": "chat.completion.chunk" if stream else "chat.completion", + "choices": [ + { + "index": 0, + "finish_reason": "stop", + "delta" if stream else "message": {"role": "assistant", "content": "Hello"}, + } + ], + "usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2}, + } + if stream: + return httpx.Response( + 200, + request=request, + headers={"content-type": "text/event-stream"}, + content=f"data: {json.dumps(result)}\n\ndata: [DONE]\n\n", + ) + return httpx.Response(200, request=request, json=result) + + monkeypatch.setattr(httpx.Client, "send", send) + result = completion( + model=f"tsubasa/{model_id}", messages=[{"role": "user", "content": "Hello"}], max_tokens=32, stream=stream + ) + if stream: + assert "".join(chunk.choices[0].delta.content or "" for chunk in result if chunk.choices) == "Hello" + else: + assert result.choices[0].message.content == "Hello" + assert result.usage.total_tokens == 2