mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
feat(wavespeed): add WaveSpeedAI as an OpenAI-compatible LLM provider
This commit is contained in:
parent
b9b27c2beb
commit
c0dec0344c
8 changed files with 3205 additions and 0 deletions
|
|
@ -728,6 +728,7 @@ openai_compatible_endpoints: List = [
|
|||
"https://api.libertai.io/v1",
|
||||
"https://pinstripes.io/v1",
|
||||
"https://api.meta.ai/v1",
|
||||
"https://llm.wavespeed.ai/v1",
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -795,6 +796,7 @@ openai_compatible_providers: List = [
|
|||
"pinstripes", # Pinstripes - JSON-configured provider
|
||||
"darkbloom",
|
||||
"meta", # Meta Model API (Muse Spark) - JSON-configured provider
|
||||
"wavespeed", # WaveSpeedAI - JSON-configured provider
|
||||
]
|
||||
openai_text_completion_compatible_providers: List = [ # providers that support `/v1/completions`
|
||||
"together_ai",
|
||||
|
|
|
|||
|
|
@ -349,6 +349,9 @@ def get_llm_provider(
|
|||
elif endpoint == "https://api.meta.ai/v1":
|
||||
custom_llm_provider = "meta"
|
||||
dynamic_api_key = get_secret_str("META_API_KEY")
|
||||
elif endpoint == "https://llm.wavespeed.ai/v1":
|
||||
custom_llm_provider = "wavespeed"
|
||||
dynamic_api_key = get_secret_str("WAVESPEED_API_KEY")
|
||||
|
||||
if api_base is not None and not isinstance(api_base, str):
|
||||
raise Exception("api base needs to be a string. api_base={}".format(api_base))
|
||||
|
|
|
|||
|
|
@ -183,5 +183,12 @@
|
|||
"max_completion_tokens": "max_tokens"
|
||||
},
|
||||
"supported_endpoints": ["/v1/chat/completions", "/v1/responses", "/v1/embeddings"]
|
||||
},
|
||||
"wavespeed": {
|
||||
"base_url": "https://llm.wavespeed.ai/v1",
|
||||
"api_key_env": "WAVESPEED_API_KEY",
|
||||
"api_base_env": "WAVESPEED_API_BASE",
|
||||
"base_class": "openai_gpt",
|
||||
"supported_endpoints": ["/v1/chat/completions", "/v1/responses", "/v1/messages"]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -3510,6 +3510,7 @@ class LlmProviders(str, Enum):
|
|||
PINSTRIPES = "pinstripes"
|
||||
DARKBLOOM = "darkbloom"
|
||||
META = "meta"
|
||||
WAVESPEED = "wavespeed"
|
||||
LITELLM_AGENT = "litellm_agent"
|
||||
CURSOR = "cursor"
|
||||
BEDROCK_MANTLE = "bedrock_mantle"
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -2548,6 +2548,23 @@
|
|||
"interactions": true
|
||||
}
|
||||
},
|
||||
"wavespeed": {
|
||||
"display_name": "WaveSpeedAI (`wavespeed`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/wavespeed",
|
||||
"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
|
||||
}
|
||||
},
|
||||
"watsonx_text": {
|
||||
"display_name": "Watsonx Text (`watsonx_text`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/watsonx",
|
||||
|
|
|
|||
165
tests/test_litellm/llms/openai_like/test_wavespeed_provider.py
Normal file
165
tests/test_litellm/llms/openai_like/test_wavespeed_provider.py
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
"""
|
||||
Tests for the WaveSpeedAI LLM provider configuration and integration.
|
||||
"""
|
||||
|
||||
import litellm
|
||||
|
||||
|
||||
class TestWavespeedProviderConfig:
|
||||
def test_wavespeed_in_provider_list(self):
|
||||
from litellm import LlmProviders
|
||||
|
||||
assert LlmProviders.WAVESPEED.value == "wavespeed"
|
||||
assert "wavespeed" in litellm.provider_list
|
||||
|
||||
def test_wavespeed_json_config(self):
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
|
||||
provider = JSONProviderRegistry.get("wavespeed")
|
||||
assert provider is not None
|
||||
assert provider.base_url == "https://llm.wavespeed.ai/v1"
|
||||
assert provider.api_key_env == "WAVESPEED_API_KEY"
|
||||
assert provider.api_base_env == "WAVESPEED_API_BASE"
|
||||
assert JSONProviderRegistry.supports_responses_api("wavespeed")
|
||||
|
||||
def test_wavespeed_in_openai_compatible_providers(self):
|
||||
from litellm.constants import openai_compatible_providers
|
||||
|
||||
assert "wavespeed" in openai_compatible_providers
|
||||
|
||||
def test_provider_prefixed_model_keeps_upstream_prefix(self):
|
||||
"""WaveSpeed model ids are themselves `{provider}/{model}`, so only the routing prefix may be stripped."""
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
model, provider, api_key, api_base = get_llm_provider(
|
||||
model="wavespeed/anthropic/claude-opus-4.8",
|
||||
custom_llm_provider=None,
|
||||
api_base=None,
|
||||
api_key="sk-test",
|
||||
)
|
||||
|
||||
assert model == "anthropic/claude-opus-4.8"
|
||||
assert provider == "wavespeed"
|
||||
assert api_key == "sk-test"
|
||||
assert api_base == "https://llm.wavespeed.ai/v1"
|
||||
|
||||
def test_api_key_and_base_resolved_from_env(self, monkeypatch):
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
monkeypatch.setenv("WAVESPEED_API_KEY", "sk-env-key")
|
||||
monkeypatch.setenv("WAVESPEED_API_BASE", "https://proxy.internal/v1")
|
||||
|
||||
_, provider, api_key, api_base = get_llm_provider(
|
||||
model="wavespeed/deepseek/deepseek-v4-flash",
|
||||
custom_llm_provider=None,
|
||||
api_base=None,
|
||||
api_key=None,
|
||||
)
|
||||
|
||||
assert provider == "wavespeed"
|
||||
assert api_key == "sk-env-key"
|
||||
assert api_base == "https://proxy.internal/v1"
|
||||
|
||||
def test_url_autodetection_from_api_base(self, monkeypatch):
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
|
||||
monkeypatch.setenv("WAVESPEED_API_KEY", "sk-env-key")
|
||||
|
||||
_, provider, api_key, api_base = get_llm_provider(
|
||||
model="glm-5",
|
||||
custom_llm_provider=None,
|
||||
api_base="https://llm.wavespeed.ai/v1",
|
||||
api_key=None,
|
||||
)
|
||||
|
||||
assert provider == "wavespeed"
|
||||
assert api_key == "sk-env-key"
|
||||
|
||||
def test_chat_completions_url(self):
|
||||
config = litellm.ProviderConfigManager.get_provider_chat_config(
|
||||
model="anthropic/claude-opus-4.8", provider=litellm.LlmProviders.WAVESPEED
|
||||
)
|
||||
assert config is not None
|
||||
assert (
|
||||
config.get_complete_url(
|
||||
api_base=None,
|
||||
api_key="sk-test",
|
||||
model="anthropic/claude-opus-4.8",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
== "https://llm.wavespeed.ai/v1/chat/completions"
|
||||
)
|
||||
|
||||
def test_anthropic_messages_passthrough(self):
|
||||
from litellm.llms.openai_like.messages.transformation import (
|
||||
JSONProviderAnthropicMessagesConfig,
|
||||
)
|
||||
|
||||
config = litellm.ProviderConfigManager.get_provider_anthropic_messages_config(
|
||||
model="anthropic/claude-opus-4.8", provider=litellm.LlmProviders.WAVESPEED
|
||||
)
|
||||
assert isinstance(config, JSONProviderAnthropicMessagesConfig)
|
||||
assert (
|
||||
config.get_complete_url(
|
||||
api_base=None,
|
||||
api_key="sk-test",
|
||||
model="anthropic/claude-opus-4.8",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
== "https://llm.wavespeed.ai/v1/messages"
|
||||
)
|
||||
|
||||
|
||||
class TestWavespeedModelInfo:
|
||||
def test_claude_opus_pricing_and_capabilities(self):
|
||||
info = litellm.get_model_info("wavespeed/anthropic/claude-opus-4.8")
|
||||
|
||||
assert info["litellm_provider"] == "wavespeed"
|
||||
assert info["input_cost_per_token"] == 5e-06
|
||||
assert info["output_cost_per_token"] == 2.5e-05
|
||||
assert info["cache_read_input_token_cost"] == 5e-07
|
||||
assert info["cache_creation_input_token_cost"] == 6.25e-06
|
||||
assert info["max_input_tokens"] == 872000
|
||||
assert info["max_output_tokens"] == 128000
|
||||
assert info["supports_function_calling"] is True
|
||||
assert info["supports_prompt_caching"] is True
|
||||
|
||||
def test_non_tool_model_does_not_advertise_function_calling(self):
|
||||
info = litellm.get_model_info("wavespeed/aion-labs/aion-2.0")
|
||||
|
||||
assert info["supports_function_calling"] is False
|
||||
assert info["supports_reasoning"] is True
|
||||
|
||||
def test_cost_calculation(self):
|
||||
from litellm import completion_cost
|
||||
from litellm.types.utils import ModelResponse, Usage
|
||||
|
||||
response = ModelResponse(
|
||||
model="anthropic/claude-opus-4.8",
|
||||
usage=Usage(prompt_tokens=1000, completion_tokens=500, total_tokens=1500),
|
||||
)
|
||||
cost = completion_cost(
|
||||
completion_response=response,
|
||||
model="wavespeed/anthropic/claude-opus-4.8",
|
||||
custom_llm_provider="wavespeed",
|
||||
)
|
||||
|
||||
assert abs(cost - (1000 * 5e-06 + 500 * 2.5e-05)) < 1e-12
|
||||
|
||||
def test_long_context_tier_pricing(self):
|
||||
from litellm import completion_cost
|
||||
from litellm.types.utils import ModelResponse, Usage
|
||||
|
||||
response = ModelResponse(
|
||||
model="qwen/qwen3.6-flash",
|
||||
usage=Usage(prompt_tokens=300_000, completion_tokens=1_000, total_tokens=301_000),
|
||||
)
|
||||
cost = completion_cost(
|
||||
completion_response=response,
|
||||
model="wavespeed/qwen/qwen3.6-flash",
|
||||
custom_llm_provider="wavespeed",
|
||||
)
|
||||
|
||||
assert abs(cost - (300_000 * 1e-06 + 1_000 * 4e-06)) < 1e-9
|
||||
Loading…
Add table
Reference in a new issue