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
passing tests
Timothy Lowrimoreda6eac4aacd4
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 138a84493c0..c1fe040a371 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -501,6 +501,7 @@ nebius_models: List = []nebius_embedding_models: List = []deepgram_models: List = []elevenlabs_models: List = []+heroku_models: List = []dashscope_models: List = []moonshot_models: List = []v0_models: List = []@@ -681,6 +682,8 @@ def add_known_models():deepgram_models.append(key)elif value.get("litellm_provider") == "elevenlabs":elevenlabs_models.append(key)+ elif value.get("litellm_provider") == "heroku":+ heroku_models.append(key)elif value.get("litellm_provider") == "dashscope":dashscope_models.append(key)elif value.get("litellm_provider") == "moonshot":@@ -775,6 +778,7 @@ model_list = (+ nscale_models+ deepgram_models+ elevenlabs_models+ + heroku_models+ dashscope_models+ moonshot_models+ v0_models@@ -846,6 +850,7 @@ models_by_provider: dict = {"featherless_ai": featherless_ai_models,"deepgram": deepgram_models,"elevenlabs": elevenlabs_models,+ "heroku": heroku_models,"dashscope": dashscope_models,"moonshot": moonshot_models,"v0": v0_models,diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.pyindex e8f1477b90c..88db7f6dbcd 100644--- a/litellm/litellm_core_utils/get_llm_provider_logic.py+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py@@ -672,6 +672,13 @@ def _get_openai_compatible_provider_info( # noqa: PLR0915) = litellm.NscaleConfig()._get_openai_compatible_provider_info(api_base=api_base, api_key=api_key)+ elif custom_llm_provider == "heroku":+ (+ api_base,+ dynamic_api_key,+ ) = litellm.HerokuChatConfig()._get_openai_compatible_provider_info(+ api_base, api_key+ )elif custom_llm_provider == "dashscope":(api_base,diff --git a/litellm/llms/heroku/chat/transformation.py b/litellm/llms/heroku/chat/transformation.pyindex 6626de69009..a1c865af747 100644--- a/litellm/llms/heroku/chat/transformation.py+++ b/litellm/llms/heroku/chat/transformation.py@@ -5,7 +5,11 @@ this is OpenAI compatible - no translation needed / occurs"""import os-from typing import Optional, List, Union+from typing import Optional, List, Tuple, Union, Coroutine, Any, Literal, overload+from litellm.litellm_core_utils.prompt_templates.common_utils import (+ handle_messages_with_content_list_to_str_conversion,+)+from litellm.types.llms.openai import AllMessageValuesfrom litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig# Base error class for Heroku@@ -13,59 +17,53 @@ class HerokuError(Exception):passclass HerokuChatConfig(OpenAIGPTConfig):- max_tokens: Optional[int] = None- stop: Optional[List[str]] = None- stream: Optional[bool] = None- temperature: Optional[float] = None- tool_choice: Optional[str] = None- tools: Optional[list] = None- top_p: Optional[int] = None+ @overload+ def _transform_messages(+ self, messages: List[AllMessageValues], model: str, is_async: Literal[True]+ ) -> Coroutine[Any, Any, List[AllMessageValues]]:+ ...- def __init__(+ @overload+ def _transform_messages(self,- max_tokens: Optional[int] = None,- stop: Optional[List[str]] = None,- stream: Optional[bool] = None,- temperature: Optional[float] = None,- tool_choice: Optional[str] = None,- tools: Optional[list] = None,- top_p: Optional[int] = None,- ) -> None:- locals_ = locals().copy()- for key, value in locals_.items():- if key != "self" and value is not None:- setattr(self.__class__, key, value)-- def get_supported_openai_params(self, model: str) -> list:- return [- "max_tokens",- "stop",- "stream",- "temperature",- "tool_choice",- "top_p",- "tools",- ]-- def map_openai_params(- self,- non_default_params: dict,- optional_params: dict,+ messages: List[AllMessageValues],model: str,- drop_params: bool,- ) -> dict:- supported_openai_params = self.get_supported_openai_params(model=model)- for param, value in non_default_params.items():- if param in supported_openai_params:- optional_params[param] = value- return optional_params-- def get_complete_url(self, api_base: Optional[str], api_key: Optional[str], model: str, optional_params: dict, litellm_params: dict, stream: Optional[bool] = None) -> str:+ is_async: Literal[False] = False,+ ) -> List[AllMessageValues]:+ ...++ def _transform_messages(+ self, messages: List[AllMessageValues], model: str, is_async: bool = False+ ) -> Union[List[AllMessageValues], Coroutine[Any, Any, List[AllMessageValues]]]:+ """+ Heroku does not support content in list format.+ See: https://devcenter.heroku.com/articles/heroku-inference-api-v1-chat-completions#content-object+ """+ messages = handle_messages_with_content_list_to_str_conversion(messages)+ if is_async:+ return super()._transform_messages(+ messages=messages, model=model, is_async=True+ )+ else:+ return super()._transform_messages(+ messages=messages, model=model, is_async=False+ )++ def _get_openai_compatible_provider_info(self, api_base: Optional[str], api_key: Optional[str]) -> Tuple[Optional[str], Optional[str]]:api_base = api_base or os.getenv("HEROKU_API_BASE")if not api_base:raise HerokuError("No api base was set. Please provide an api_base, or set the HEROKU_API_BASE environment variable.")+ api_key = api_key or os.getenv("HEROKU_API_KEY")+ if not api_key:+ raise HerokuError("No api key was set. Please provide an api_key, or set the HEROKU_API_KEY environment variable.")++ return api_base, api_key++ def get_complete_url(self, api_base: Optional[str], api_key: Optional[str], model: str, optional_params: dict, litellm_params: dict, stream: Optional[bool] = None) -> str:+ api_base, _ = self._get_openai_compatible_provider_info(api_base, api_key)+if not api_base.endswith("/v1/chat/completions"):api_base = f"{api_base}/v1/chat/completions"-+return api_base\ 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 2ab758e722b..c68c1093a4b 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -16670,5 +16670,25 @@"supports_vision": false,"supports_system_messages": true,"supports_tool_choice": false+ },+ "heroku/claude-4-sonnet": {+ "max_tokens": 8192,+ "litellm_provider": "heroku",+ "mode": "chat"+ },+ "heroku/claude-3-7-sonnet": {+ "max_tokens": 8192,+ "litellm_provider": "heroku",+ "mode": "chat"+ },+ "heroku/claude-3-5-sonnet-latest": {+ "max_tokens": 8192,+ "litellm_provider": "heroku",+ "mode": "chat"+ },+ "heroku/claude-3-5-haiku": {+ "max_tokens": 4096,+ "litellm_provider": "heroku",+ "mode": "chat"}}diff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 88d58582d0c..899b15a78fb 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -2314,6 +2314,7 @@ class LlmProviders(str, Enum):NSCALE = "nscale"PG_VECTOR = "pg_vector"RECRAFT = "recraft"+ HEROKU = "heroku"# Create a set of all provider values for quick lookupdiff --git a/litellm/utils.py b/litellm/utils.pyindex 676e40f6b2d..9f8b2dcc587 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -6880,6 +6880,8 @@ class ProviderConfigManager:return litellm.OpenAIGPTConfig()elif litellm.LlmProviders.NSCALE == provider:return litellm.NscaleConfig()+ elif litellm.LlmProviders.HEROKU == provider:+ return litellm.HerokuChatConfig()return None@staticmethoddiff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex 2ab758e722b..c68c1093a4b 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -16670,5 +16670,25 @@"supports_vision": false,"supports_system_messages": true,"supports_tool_choice": false+ },+ "heroku/claude-4-sonnet": {+ "max_tokens": 8192,+ "litellm_provider": "heroku",+ "mode": "chat"+ },+ "heroku/claude-3-7-sonnet": {+ "max_tokens": 8192,+ "litellm_provider": "heroku",+ "mode": "chat"+ },+ "heroku/claude-3-5-sonnet-latest": {+ "max_tokens": 8192,+ "litellm_provider": "heroku",+ "mode": "chat"+ },+ "heroku/claude-3-5-haiku": {+ "max_tokens": 4096,+ "litellm_provider": "heroku",+ "mode": "chat"}}diff --git a/tests/test_litellm/llms/heroku/test_heroku_chat_transformation.py b/tests/test_litellm/llms/heroku/test_heroku_chat_transformation.pyindex 140105c2a26..4359bce3f70 100644--- a/tests/test_litellm/llms/heroku/test_heroku_chat_transformation.py+++ b/tests/test_litellm/llms/heroku/test_heroku_chat_transformation.py@@ -1,9 +1,14 @@import osimport pytest+import litellm+from litellm import completionfrom litellm.llms.custom_httpx.http_handler import HTTPHandlerfrom unittest.mock import patchfrom litellm.llms.heroku.chat.transformation import HerokuChatConfig+os.environ["HEROKU_API_BASE"] = "https://us.inference.heroku.com"+os.environ["HEROKU_API_KEY"] = "fake-heroku-key"+class TestHerokuChatConfig:def test_default_api_base(self):"""Test that default API base is used when none is provided"""@@ -22,12 +27,57 @@ class TestHerokuChatConfig:api_base=None, # Not providing api_base)- # set env var for api_base- os.environ["HEROKU_API_BASE"] = "https://mia.heroku.com"-- print('****************************************')- print(config.get_complete_url(api_base=None, api_key=api_key, model="claude-3-5-haiku", optional_params={}, litellm_params={}, stream=False))- print('****************************************')# Verify headers are still set correctlyassert result["Authorization"] == f"Bearer {api_key}"- assert result["Content-Type"] == "application/json"\ No newline at end of file+ assert result["Content-Type"] == "application/json"++ @pytest.mark.respx()+ def test_heroku_chat_mock(self, respx_mock):+ """Test that the Heroku chat API is called correctly"""++ litellm.disable_aiohttp_transport = True++ model = "heroku/claude-3-5-haiku"+ model_name = "claude-3-5-haiku"++ respx_mock.post("https://us.inference.heroku.com/v1/chat/completions").respond(+ json={+ "id": "chatcmpl-123",+ "object": "chat.completion",+ "created": 1677652288,+ "model": model_name,+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "It's me, Mia! How are you?",+ },+ "finish_reason": "stop",+ }+ ],+ "usage": {+ "prompt_tokens": 9,+ "completion_tokens": 12,+ "total_tokens": 21,+ },+ },+ status_code=200,+ )++ response = completion(+ model=model,+ messages=[+ {"role": "user", "content": "write code for saying hey from LiteLLM"}+ ],+ extended_thinking={ "enabled": True, "include_reasoning":True }+ )++ # Verify the request was made with correct headers+ assert len(respx_mock.calls) == 1+ request = respx_mock.calls[0].request++ assert request.headers["Authorization"] == f"Bearer {os.environ['HEROKU_API_KEY']}"+ assert request.headers["Content-Type"] == "application/json"++ assert response.choices[0].message.content == "It's me, Mia! How are you?"\ No newline at end of file