feat(providers): add Tsubasa inference provider

This commit is contained in:
cenab 2026-09-27 02:52:05 -06:00
parent b94f5bdbed
commit 82bcc602c3
7 changed files with 198 additions and 0 deletions

View file

@ -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

View file

@ -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",

View file

@ -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"
}
}
}

View file

@ -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
}
}

View file

@ -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"

View file

@ -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
}
}

View file

@ -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