The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat: add v0 provider support (#12751)
Cole McIntoshbf046c9d5db8
diff --git a/docs/my-website/docs/providers/v0.md b/docs/my-website/docs/providers/v0.mdnew file mode 100644index 00000000000..74b6498ca88--- /dev/null+++ b/docs/my-website/docs/providers/v0.md@@ -0,0 +1,340 @@+import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++# v0++## Overview++| Property | Details |+|-------|-------|+| Description | v0 provides AI models optimized for code generation, particularly for creating Next.js applications, React components, and modern web development. |+| Provider Route on LiteLLM | `v0/` |+| Link to Provider Doc | [v0 API Documentation ↗](https://v0.dev/docs/v0-model-api) |+| Base URL | `https://api.v0.dev/v1` |+| Supported Operations | [`/chat/completions`](#sample-usage) |++<br />+<br />++https://v0.dev/docs/v0-model-api++**We support ALL v0 models, just set `v0/` as a prefix when sending completion requests**++## Available Models++| Model | Description | Context Window | Max Output |+|-------|-------------|----------------|------------|+| `v0/v0-1.5-lg` | Large model for advanced code generation and reasoning | 512,000 tokens | 512,000 tokens |+| `v0/v0-1.5-md` | Medium model for everyday code generation tasks | 128,000 tokens | 128,000 tokens |+| `v0/v0-1.0-md` | Legacy medium model | 128,000 tokens | 128,000 tokens |++## Required Variables++```python showLineNumbers title="Environment Variables"+os.environ["V0_API_KEY"] = "" # your v0 API key from v0.dev+```++Note: v0 API access requires a Premium or Team plan. Visit [v0.dev/chat/settings/billing](https://v0.dev/chat/settings/billing) to upgrade.++## Usage - LiteLLM Python SDK++### Non-streaming++```python showLineNumbers title="v0 Non-streaming Completion"+import os+import litellm+from litellm import completion++os.environ["V0_API_KEY"] = "" # your v0 API key++messages = [{"content": "Create a React button component with hover effects", "role": "user"}]++# v0 call+response = completion(+ model="v0/v0-1.5-md",+ messages=messages+)++print(response)+```++### Streaming++```python showLineNumbers title="v0 Streaming Completion"+import os+import litellm+from litellm import completion++os.environ["V0_API_KEY"] = "" # your v0 API key++messages = [{"content": "Create a React button component with hover effects", "role": "user"}]++# v0 call with streaming+response = completion(+ model="v0/v0-1.5-md",+ messages=messages,+ stream=True+)++for chunk in response:+ print(chunk)+```++### Vision/Multimodal Support++All v0 models support vision inputs, allowing you to send images along with text:++```python showLineNumbers title="v0 Vision/Multimodal"+import os+import litellm+from litellm import completion++os.environ["V0_API_KEY"] = "" # your v0 API key++messages = [{+ "role": "user",+ "content": [+ {+ "type": "text",+ "text": "Recreate this UI design in React"+ },+ {+ "type": "image_url",+ "image_url": {+ "url": "https://example.com/ui-design.png"+ }+ }+ ]+}]++response = completion(+ model="v0/v0-1.5-lg",+ messages=messages+)++print(response)+```++### Function Calling++v0 supports function calling for structured outputs:++```python showLineNumbers title="v0 Function Calling"+import os+import litellm+from litellm import completion++os.environ["V0_API_KEY"] = "" # your v0 API key++tools = [+ {+ "type": "function",+ "function": {+ "name": "create_component",+ "description": "Create a React component",+ "parameters": {+ "type": "object",+ "properties": {+ "component_name": {+ "type": "string",+ "description": "The name of the component"+ },+ "props": {+ "type": "array",+ "items": {"type": "string"},+ "description": "List of component props"+ }+ },+ "required": ["component_name"]+ }+ }+ }+]++response = completion(+ model="v0/v0-1.5-md",+ messages=[{"role": "user", "content": "Create a Button component with onClick and disabled props"}],+ tools=tools,+ tool_choice="auto"+)++print(response)+```++## Usage - LiteLLM Proxy++Add the following to your LiteLLM Proxy configuration file:++```yaml showLineNumbers title="config.yaml"+model_list:+ - model_name: v0-large+ litellm_params:+ model: v0/v0-1.5-lg+ api_key: os.environ/V0_API_KEY++ - model_name: v0-medium+ litellm_params:+ model: v0/v0-1.5-md+ api_key: os.environ/V0_API_KEY++ - model_name: v0-legacy+ litellm_params:+ model: v0/v0-1.0-md+ api_key: os.environ/V0_API_KEY+```++Start your LiteLLM Proxy server:++```bash showLineNumbers title="Start LiteLLM Proxy"+litellm --config config.yaml++# RUNNING on http://0.0.0.0:4000+```++<Tabs>+<TabItem value="openai-sdk" label="OpenAI SDK">++```python showLineNumbers title="v0 via Proxy - Non-streaming"+from openai import OpenAI++# Initialize client with your proxy URL+client = OpenAI(+ base_url="http://localhost:4000", # Your proxy URL+ api_key="your-proxy-api-key" # Your proxy API key+)++# Non-streaming response+response = client.chat.completions.create(+ model="v0-medium",+ messages=[{"role": "user", "content": "Create a React card component"}]+)++print(response.choices[0].message.content)+```++```python showLineNumbers title="v0 via Proxy - Streaming"+from openai import OpenAI++# Initialize client with your proxy URL+client = OpenAI(+ base_url="http://localhost:4000", # Your proxy URL+ api_key="your-proxy-api-key" # Your proxy API key+)++# Streaming response+response = client.chat.completions.create(+ model="v0-medium",+ messages=[{"role": "user", "content": "Create a React card component"}],+ stream=True+)++for chunk in response:+ if chunk.choices[0].delta.content is not None:+ print(chunk.choices[0].delta.content, end="")+```++</TabItem>++<TabItem value="litellm-sdk" label="LiteLLM SDK">++```python showLineNumbers title="v0 via Proxy - LiteLLM SDK"+import litellm++# Configure LiteLLM to use your proxy+response = litellm.completion(+ model="litellm_proxy/v0-medium",+ messages=[{"role": "user", "content": "Create a React card component"}],+ api_base="http://localhost:4000",+ api_key="your-proxy-api-key"+)++print(response.choices[0].message.content)+```++```python showLineNumbers title="v0 via Proxy - LiteLLM SDK Streaming"+import litellm++# Configure LiteLLM to use your proxy with streaming+response = litellm.completion(+ model="litellm_proxy/v0-medium",+ messages=[{"role": "user", "content": "Create a React card component"}],+ api_base="http://localhost:4000",+ api_key="your-proxy-api-key",+ stream=True+)++for chunk in response:+ if hasattr(chunk.choices[0], 'delta') and chunk.choices[0].delta.content is not None:+ print(chunk.choices[0].delta.content, end="")+```++</TabItem>++<TabItem value="curl" label="cURL">++```bash showLineNumbers title="v0 via Proxy - cURL"+curl http://localhost:4000/v1/chat/completions \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer your-proxy-api-key" \+ -d '{+ "model": "v0-medium",+ "messages": [{"role": "user", "content": "Create a React card component"}]+ }'+```++```bash showLineNumbers title="v0 via Proxy - cURL Streaming"+curl http://localhost:4000/v1/chat/completions \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer your-proxy-api-key" \+ -d '{+ "model": "v0-medium",+ "messages": [{"role": "user", "content": "Create a React card component"}],+ "stream": true+ }'+```++</TabItem>+</Tabs>++For more detailed information on using the LiteLLM Proxy, see the [LiteLLM Proxy documentation](../providers/litellm_proxy).++## Supported OpenAI Parameters++v0 supports the following OpenAI-compatible parameters:++| Parameter | Type | Description |+|-----------|------|-------------|+| `messages` | array | **Required**. Array of message objects with 'role' and 'content' |+| `model` | string | **Required**. Model ID (v0-1.5-lg, v0-1.5-md, v0-1.0-md) |+| `stream` | boolean | Optional. Enable streaming responses |+| `tools` | array | Optional. List of available tools/functions |+| `tool_choice` | string/object | Optional. Control tool/function calling |++Note: v0 has a limited set of supported parameters compared to the full OpenAI API. Parameters like `temperature`, `max_tokens`, `top_p`, etc. are not supported.++## Advanced Usage++### Custom API Base++If you're using a custom v0 deployment:++```python showLineNumbers title="Custom API Base"+import litellm++response = litellm.completion(+ model="v0/v0-1.5-md",+ messages=[{"role": "user", "content": "Hello"}],+ api_base="https://your-custom-v0-endpoint.com/v1",+ api_key="your-api-key"+)+```+++## Pricing++v0 models require a Premium or Team subscription. Visit [v0.dev/chat/settings/billing](https://v0.dev/chat/settings/billing) for current pricing information.++## Additional Resources++- [v0 Official Documentation](https://v0.dev/docs)+- [v0 Model API Reference](https://v0.dev/docs/v0-model-api)\ No newline at end of filediff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.jsindex 9c7eaf07f22..fb70bcc3695 100644--- a/docs/my-website/sidebars.js+++ b/docs/my-website/sidebars.js@@ -446,6 +446,7 @@ const sidebars = {"providers/nlp_cloud","providers/replicate","providers/togetherai",+ "providers/v0","providers/novita","providers/voyage","providers/jina_ai",diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 6c851ab8b73..424e6c31985 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -1151,6 +1151,7 @@ from .llms.github_copilot.chat.transformation import GithubCopilotConfigfrom .llms.nebius.chat.transformation import NebiusConfigfrom .llms.dashscope.chat.transformation import DashScopeChatConfigfrom .llms.moonshot.chat.transformation import MoonshotChatConfig+from .llms.v0.chat.transformation import V0ChatConfigfrom .main import * # type: ignorefrom .integrations import *from .llms.custom_httpx.async_client_cleanup import close_litellm_async_clientsdiff --git a/litellm/constants.py b/litellm/constants.pyindex 924e4869dbe..de62eafab94 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -278,6 +278,7 @@ LITELLM_CHAT_PROVIDERS = ["nebius","dashscope","moonshot",+ "v0",]LITELLM_EMBEDDING_PROVIDERS_SUPPORTING_INPUT_ARRAY_OF_TOKENS = [@@ -406,6 +407,7 @@ openai_compatible_endpoints: List = ["api.studio.nebius.ai/v1","https://dashscope-intl.aliyuncs.com/compatible-mode/v1","https://api.moonshot.ai/v1",+ "https://api.v0.dev/v1",]@@ -443,6 +445,7 @@ openai_compatible_providers: List = ["nebius","dashscope","moonshot",+ "v0",]openai_text_completion_compatible_providers: List = ([ # providers that support `/v1/completions`diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.pyindex 94c2a859e1f..84c25d49323 100644--- a/litellm/litellm_core_utils/get_llm_provider_logic.py+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py@@ -237,6 +237,9 @@ def get_llm_provider( # noqa: PLR0915elif endpoint == "api.moonshot.ai/v1":custom_llm_provider = "moonshot"dynamic_api_key = get_secret_str("MOONSHOT_API_KEY")+ elif endpoint == "https://api.v0.dev/v1":+ custom_llm_provider = "v0"+ dynamic_api_key = get_secret_str("V0_API_KEY")if api_base is not None and not isinstance(api_base, str):raise Exception(@@ -681,6 +684,13 @@ def _get_openai_compatible_provider_info( # noqa: PLR0915) = litellm.MoonshotChatConfig()._get_openai_compatible_provider_info(api_base, api_key)+ elif custom_llm_provider == "v0":+ (+ api_base,+ dynamic_api_key,+ ) = litellm.V0ChatConfig()._get_openai_compatible_provider_info(+ api_base, 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))diff --git a/litellm/llms/v0/__init__.py b/litellm/llms/v0/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/litellm/llms/v0/chat/__init__.py b/litellm/llms/v0/chat/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/litellm/llms/v0/chat/transformation.py b/litellm/llms/v0/chat/transformation.pynew file mode 100644index 00000000000..1417e5f5ae1--- /dev/null+++ b/litellm/llms/v0/chat/transformation.py@@ -0,0 +1,44 @@+"""+Translate from OpenAI's `/v1/chat/completions` to v0's `/v1/chat/completions`+"""++from typing import Optional, Tuple++from litellm.secret_managers.main import get_secret_str++from ...openai_like.chat.transformation import OpenAILikeChatConfig+++class V0ChatConfig(OpenAILikeChatConfig):+ """+ v0 is OpenAI-compatible with standard endpoints+ """++ @property+ def custom_llm_provider(self) -> Optional[str]:+ return "v0"++ def _get_openai_compatible_provider_info(+ self, api_base: Optional[str], api_key: Optional[str]+ ) -> Tuple[Optional[str], Optional[str]]:+ # v0 is openai compatible, we just need to set the api_base+ api_base = (+ api_base+ or get_secret_str("V0_API_BASE")+ or "https://api.v0.dev/v1" # Default v0 API base URL+ ) # type: ignore+ dynamic_api_key = api_key or get_secret_str("V0_API_KEY")+ return api_base, dynamic_api_key++ def get_supported_openai_params(self, model: str) -> list:+ """+ v0 supports a limited subset of OpenAI parameters+ Reference: https://v0.dev/docs/v0-model-api#request-body+ """+ return [+ "messages", # Required+ "model", # Required+ "stream", # Optional+ "tools", # Optional+ "tool_choice", # Optional+ ]\ No newline at end of filediff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex b49680e3001..0738f453b2d 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -14721,6 +14721,48 @@"litellm_provider": "cloudflare","mode": "chat"},+ "v0/v0-1.0-md": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 128000,+ "input_cost_per_token": 3e-06,+ "output_cost_per_token": 1.5e-05,+ "litellm_provider": "v0",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_parallel_function_calling": true,+ "supports_vision": true,+ "supports_system_messages": true,+ "supports_tool_choice": true+ },+ "v0/v0-1.5-md": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 128000,+ "input_cost_per_token": 3e-06,+ "output_cost_per_token": 1.5e-05,+ "litellm_provider": "v0",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_parallel_function_calling": true,+ "supports_vision": true,+ "supports_system_messages": true,+ "supports_tool_choice": true+ },+ "v0/v0-1.5-lg": {+ "max_tokens": 512000,+ "max_input_tokens": 512000,+ "max_output_tokens": 512000,+ "input_cost_per_token": 1.5e-05,+ "output_cost_per_token": 7.5e-05,+ "litellm_provider": "v0",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_parallel_function_calling": true,+ "supports_vision": true,+ "supports_system_messages": true,+ "supports_tool_choice": true+ },"voyage/voyage-01": {"max_tokens": 4096,"max_input_tokens": 4096,diff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 9ad3005dfdb..cafd75950d3 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -2273,6 +2273,7 @@ class LlmProviders(str, Enum):TEXT_COMPLETION_CODESTRAL = "text-completion-codestral"DASHSCOPE = "dashscope"MOONSHOT = "moonshot"+ V0 = "v0"DEEPSEEK = "deepseek"SAMBANOVA = "sambanova"MARITALK = "maritalk"diff --git a/litellm/utils.py b/litellm/utils.pyindex d37c4d741ea..ef26c8bd764 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -6827,6 +6827,8 @@ class ProviderConfigManager:return litellm.DashScopeChatConfig()elif litellm.LlmProviders.MOONSHOT == provider:return litellm.MoonshotChatConfig()+ elif litellm.LlmProviders.V0 == provider:+ return litellm.V0ChatConfig()elif litellm.LlmProviders.BEDROCK == provider:bedrock_route = BedrockModelInfo.get_bedrock_route(model)bedrock_invoke_provider = litellm.BedrockLLM.get_bedrock_invoke_provider(diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex b49680e3001..0738f453b2d 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -14721,6 +14721,48 @@"litellm_provider": "cloudflare","mode": "chat"},+ "v0/v0-1.0-md": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 128000,+ "input_cost_per_token": 3e-06,+ "output_cost_per_token": 1.5e-05,+ "litellm_provider": "v0",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_parallel_function_calling": true,+ "supports_vision": true,+ "supports_system_messages": true,+ "supports_tool_choice": true+ },+ "v0/v0-1.5-md": {+ "max_tokens": 128000,+ "max_input_tokens": 128000,+ "max_output_tokens": 128000,+ "input_cost_per_token": 3e-06,+ "output_cost_per_token": 1.5e-05,+ "litellm_provider": "v0",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_parallel_function_calling": true,+ "supports_vision": true,+ "supports_system_messages": true,+ "supports_tool_choice": true+ },+ "v0/v0-1.5-lg": {+ "max_tokens": 512000,+ "max_input_tokens": 512000,+ "max_output_tokens": 512000,+ "input_cost_per_token": 1.5e-05,+ "output_cost_per_token": 7.5e-05,+ "litellm_provider": "v0",+ "mode": "chat",+ "supports_function_calling": true,+ "supports_parallel_function_calling": true,+ "supports_vision": true,+ "supports_system_messages": true,+ "supports_tool_choice": true+ },"voyage/voyage-01": {"max_tokens": 4096,"max_input_tokens": 4096,diff --git a/tests/llm_translation/test_v0.py b/tests/llm_translation/test_v0.pynew file mode 100644index 00000000000..d9b6eae0681--- /dev/null+++ b/tests/llm_translation/test_v0.py@@ -0,0 +1,130 @@+"""+Tests for v0 provider integration+"""+import os+from unittest import mock++import pytest++import litellm+from litellm import completion+from litellm.llms.v0.chat.transformation import V0ChatConfig+++def test_v0_config_initialization():+ """Test V0ChatConfig initializes correctly"""+ config = V0ChatConfig()+ assert config.custom_llm_provider == "v0"+++def test_v0_get_openai_compatible_provider_info():+ """Test v0 provider info retrieval"""+ config = V0ChatConfig()++ # Test with default values (no env vars set)+ with mock.patch.dict(os.environ, {}, clear=True):+ api_base, api_key = config._get_openai_compatible_provider_info(None, None)+ assert api_base == "https://api.v0.dev/v1"+ assert api_key is None++ # Test with environment variables+ with mock.patch.dict(os.environ, {"V0_API_KEY": "test-key", "V0_API_BASE": "https://custom.v0.ai/v1"}):+ api_base, api_key = config._get_openai_compatible_provider_info(None, None)+ assert api_base == "https://custom.v0.ai/v1"+ assert api_key == "test-key"++ # Test with explicit parameters (should override env vars)+ with mock.patch.dict(os.environ, {"V0_API_KEY": "env-key", "V0_API_BASE": "https://env.v0.ai/v1"}):+ api_base, api_key = config._get_openai_compatible_provider_info(+ "https://param.v0.ai/v1", "param-key"+ )+ assert api_base == "https://param.v0.ai/v1"+ assert api_key == "param-key"+++def test_get_llm_provider_v0():+ """Test that get_llm_provider correctly identifies v0"""+ from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider++ # Test with v0/model-name format+ model, provider, api_key, api_base = get_llm_provider("v0/gpt-4-turbo")+ assert model == "gpt-4-turbo"+ assert provider == "v0"++ # Test with api_base containing v0 endpoint+ model, provider, api_key, api_base = get_llm_provider(+ "gpt-4-turbo", api_base="https://api.v0.dev/v1"+ )+ assert model == "gpt-4-turbo"+ assert provider == "v0"+ assert api_base == "https://api.v0.dev/v1"+++def test_v0_in_provider_lists():+ """Test that v0 is registered in all necessary provider lists"""+ assert "v0" in litellm.openai_compatible_providers+ assert "v0" in litellm.provider_list+ assert "https://api.v0.dev/v1" in litellm.openai_compatible_endpoints+++async def test_v0_completion_call():+ """Test completion call with v0 provider (requires V0_API_KEY)"""+ # Skip if no API key is available+ if not os.getenv("V0_API_KEY"):+ pytest.skip("V0_API_KEY not set")++ try:+ response = await litellm.acompletion(+ model="v0/gpt-4-turbo",+ messages=[{"role": "user", "content": "Hello, this is a test"}],+ max_tokens=10,+ )+ assert response.choices[0].message.content+ assert response.model+ assert response.usage+ except Exception as e:+ # If the API key is invalid or there's a network issue, that's okay+ # The important thing is that the provider was recognized+ if "v0" not in str(e) and "provider" not in str(e).lower():+ # Re-raise if it's not a provider-related error+ raise+++def test_v0_supported_params():+ """Test that v0 returns only the supported parameters"""+ config = V0ChatConfig()+ supported_params = config.get_supported_openai_params("v0/v0-1.5-md")++ # v0 only supports these specific params+ expected_params = [+ "messages",+ "model",+ "stream",+ "tools",+ "tool_choice",+ ]++ assert set(supported_params) == set(expected_params)+++def test_v0_models_configuration():+ """Test that v0 models are configured correctly"""+ from litellm import get_model_info++ # Reload model cost map to pick up local changes+ os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"+ litellm.model_cost = litellm.get_model_cost_map(url="")++ # All v0 models+ v0_models = ["v0/v0-1.0-md", "v0/v0-1.5-md", "v0/v0-1.5-lg"]++ for model in v0_models:+ model_info = get_model_info(model)+ assert model_info is not None, f"Model info not found for {model}"+ # All v0 models support vision (multimodal)+ assert model_info.get("supports_vision") is True, f"{model} should support vision"+ assert model_info.get("litellm_provider") == "v0", f"{model} should have v0 as provider"+ assert model_info.get("mode") == "chat", f"{model} should be in chat mode"+ assert model_info.get("supports_function_calling") is True, f"{model} should support function calling"+ assert model_info.get("supports_system_messages") is True, f"{model} should support system messages"\ No newline at end of file