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] New LLM API - AI/ML API for Image Gen (#13893)
Ishaan Jaff9750374081d1
diff --git a/docs/my-website/docs/providers/aiml.md b/docs/my-website/docs/providers/aiml.mdindex 1343cbf8d8e..9d763daf7d7 100644--- a/docs/my-website/docs/providers/aiml.md+++ b/docs/my-website/docs/providers/aiml.md@@ -1,5 +1,23 @@# AI/ML API+https://aimlapi.com/+## Overview++| Property | Details |+|-------|-------|+| Description | AI/ML API provides access to state-of-the-art AI models including flux-pro/v1.1 for high-quality image generation. |+| Provider Route on LiteLLM | `aiml/` |+| Link to Provider Doc | [AI/ML API ↗](https://docs.aimlapi.com/) |+| Supported Operations | [`/chat/completions`], [`/images/generations`](#image-generation) |++LiteLLM supports AI/ML API Image Generation calls.++## API Base, Key+```python+# env variable+os.environ['AIML_API_KEY'] = "your-api-key"+os.environ['AIML_API_BASE'] = "https://api.aimlapi.com" # [optional]+```Getting started with the AI/ML API is simple. Follow these steps to set up your integration:### 1. Get Your API Key@@ -24,7 +42,7 @@ You can choose from LLama, Qwen, Flux, and 200+ other open and closed-source modimport litellmresponse = litellm.completion(- model="openai/meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo", # The model name must include prefix "openai" + the model name from ai/ml api+ model="aiml/meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo", # The model name must include prefix "openai" + the model name from ai/ml apiapi_key="", # your aiml api-keyapi_base="https://api.aimlapi.com/v2",messages=[@@ -42,7 +60,7 @@ response = litellm.completion(import litellmresponse = litellm.completion(- model="openai/Qwen/Qwen2-72B-Instruct", # The model name must include prefix "openai" + the model name from ai/ml api+ model="aiml/Qwen/Qwen2-72B-Instruct", # The model name must include prefix "openai" + the model name from ai/ml apiapi_key="", # your aiml api-keyapi_base="https://api.aimlapi.com/v2",messages=[@@ -67,7 +85,7 @@ import litellmasync def main():response = await litellm.acompletion(- model="openai/anthropic/claude-3-5-haiku", # The model name must include prefix "openai" + the model name from ai/ml api+ model="aiml/anthropic/claude-3-5-haiku", # The model name must include prefix "openai" + the model name from ai/ml apiapi_key="", # your aiml api-keyapi_base="https://api.aimlapi.com/v2",messages=[@@ -97,7 +115,7 @@ async def main():try:print("test acompletion + streaming")response = await litellm.acompletion(- model="openai/nvidia/Llama-3.1-Nemotron-70B-Instruct-HF", # The model name must include prefix "openai" + the model name from ai/ml api+ model="aiml/nvidia/Llama-3.1-Nemotron-70B-Instruct-HF", # The model name must include prefix "openai" + the model name from ai/ml apiapi_key="", # your aiml api-keyapi_base="https://api.aimlapi.com/v2",messages=[{"content": "Hey, how's it going?", "role": "user"}],@@ -125,7 +143,7 @@ import litellmasync def main():response = await litellm.aembedding(- model="openai/text-embedding-3-small", # The model name must include prefix "openai" + the model name from ai/ml api+ model="aiml/text-embedding-3-small", # The model name must include prefix "openai" + the model name from ai/ml apiapi_key="", # your aiml api-keyapi_base="https://api.aimlapi.com/v1", # 👈 the URL has changed from v2 to v1input="Your text string",@@ -147,7 +165,7 @@ import litellmasync def main():response = await litellm.aimage_generation(- model="openai/dall-e-3", # The model name must include prefix "openai" + the model name from ai/ml api+ model="aiml/dall-e-3", # The model name must include prefix "openai" + the model name from ai/ml apiapi_key="", # your aiml api-keyapi_base="https://api.aimlapi.com/v1", # 👈 the URL has changed from v2 to v1prompt="A cute baby sea otter",diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 9ac442cb3d2..c405d3cdeb2 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -530,6 +530,7 @@ llama_models: Set = set()nscale_models: Set = set()nebius_models: Set = set()nebius_embedding_models: Set = set()+aiml_models: Set = set()deepgram_models: Set = set()elevenlabs_models: Set = set()dashscope_models: Set = set()@@ -709,6 +710,8 @@ def add_known_models():nebius_models.add(key)elif value.get("litellm_provider") == "nebius-embedding-models":nebius_embedding_models.add(key)+ elif value.get("litellm_provider") == "aiml":+ aiml_models.add(key)elif value.get("litellm_provider") == "assemblyai":assemblyai_models.add(key)elif value.get("litellm_provider") == "jina_ai":@@ -886,6 +889,7 @@ models_by_provider: dict = {"sambanova": sambanova_models | sambanova_embedding_models,"novita": novita_models,"nebius": nebius_models | nebius_embedding_models,+ "aiml": aiml_models,"assemblyai": assemblyai_models,"jina_ai": jina_ai_models,"snowflake": snowflake_models,@@ -1210,6 +1214,7 @@ from .llms.friendliai.chat.transformation import FriendliaiChatConfigfrom .llms.jina_ai.embedding.transformation import JinaAIEmbeddingConfigfrom .llms.xai.chat.transformation import XAIChatConfigfrom .llms.xai.common_utils import XAIModelInfo+from .llms.aiml.chat.transformation import AIMLChatConfigfrom .llms.volcengine import VolcEngineConfigfrom .llms.codestral.completion.transformation import CodestralTextCompletionConfigfrom .llms.azure.azure import (diff --git a/litellm/constants.py b/litellm/constants.pyindex 365dfa84510..72cc52fdf21 100644--- a/litellm/constants.py+++ b/litellm/constants.py@@ -462,6 +462,7 @@ openai_compatible_providers: List = ["morph","lambda_ai","hyperbolic",+ "aiml",]openai_text_completion_compatible_providers: List = ([ # providers that support `/v1/completions`diff --git a/litellm/images/main.py b/litellm/images/main.pyindex 70d9eb41ddd..b75a536beb4 100644--- a/litellm/images/main.py+++ b/litellm/images/main.py@@ -444,6 +444,7 @@ def image_generation( # noqa: PLR0915#########################################################elif custom_llm_provider in (litellm.LlmProviders.RECRAFT,+ litellm.LlmProviders.AIML,litellm.LlmProviders.GEMINI,):if image_generation_config is None:diff --git a/litellm/litellm_core_utils/get_llm_provider_logic.py b/litellm/litellm_core_utils/get_llm_provider_logic.pyindex 02b542ed165..2d511741ec6 100644--- a/litellm/litellm_core_utils/get_llm_provider_logic.py+++ b/litellm/litellm_core_utils/get_llm_provider_logic.py@@ -486,7 +486,7 @@ def _get_openai_compatible_provider_info( # noqa: PLR0915if api_base is None:api_base = litellm.BasetenConfig.get_api_base_for_model(model)else:- api_base = api_base or get_secret("BASETEN_API_BASE") or "https://inference.baseten.co/v1"+ api_base = api_base or get_secret_str("BASETEN_API_BASE") or "https://inference.baseten.co/v1"dynamic_api_key = api_key or get_secret_str("BASETEN_API_KEY")elif custom_llm_provider == "sambanova":api_base = (@@ -742,6 +742,13 @@ def _get_openai_compatible_provider_info( # noqa: PLR0915) = litellm.HyperbolicChatConfig()._get_openai_compatible_provider_info(api_base, api_key)+ elif custom_llm_provider == "aiml":+ (+ api_base,+ dynamic_api_key,+ ) = litellm.AIMLChatConfig()._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/litellm_core_utils/llm_cost_calc/utils.py b/litellm/litellm_core_utils/llm_cost_calc/utils.pyindex fe747788243..c851ec06a6b 100644--- a/litellm/litellm_core_utils/llm_cost_calc/utils.py+++ b/litellm/litellm_core_utils/llm_cost_calc/utils.py@@ -454,6 +454,15 @@ class CostCalculatorUtils:model=model,image_response=completion_response,)+ elif custom_llm_provider == litellm.LlmProviders.AIML.value:+ from litellm.llms.aiml.image_generation.cost_calculator import (+ cost_calculator as aiml_image_cost_calculator,+ )++ return aiml_image_cost_calculator(+ model=model,+ image_response=completion_response,+ )elif custom_llm_provider == litellm.LlmProviders.GEMINI.value:from litellm.llms.gemini.image_generation.cost_calculator import (cost_calculator as gemini_image_cost_calculator,diff --git a/litellm/llms/aiml/__init__.py b/litellm/llms/aiml/__init__.pynew file mode 100644index 00000000000..42482760cda--- /dev/null+++ b/litellm/llms/aiml/__init__.py@@ -0,0 +1,5 @@+from .image_generation import get_aiml_image_generation_config++__all__ = [+ "get_aiml_image_generation_config",+]diff --git a/litellm/llms/aiml/chat/transformation.py b/litellm/llms/aiml/chat/transformation.pynew file mode 100644index 00000000000..0f3e333343d--- /dev/null+++ b/litellm/llms/aiml/chat/transformation.py@@ -0,0 +1,23 @@+from typing import Optional, Tuple++from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig+from litellm.secret_managers.main import get_secret_str+++class AIMLChatConfig(OpenAIGPTConfig):+ @property+ def custom_llm_provider(self) -> Optional[str]:+ return "aiml"++ def _get_openai_compatible_provider_info(+ self, api_base: Optional[str], api_key: Optional[str]+ ) -> Tuple[Optional[str], Optional[str]]:+ # AIML is openai compatible, we just need to set the api_base+ api_base = (+ api_base+ or get_secret_str("AIML_API_BASE")+ or "https://api.aimlapi.com/v1" # Default AIML API base URL+ ) # type: ignore+ dynamic_api_key = api_key or get_secret_str("AIML_API_KEY")+ return api_base, dynamic_api_key+ pass\ No newline at end of filediff --git a/litellm/llms/aiml/image_generation/__init__.py b/litellm/llms/aiml/image_generation/__init__.pynew file mode 100644index 00000000000..4548bd1b3f8--- /dev/null+++ b/litellm/llms/aiml/image_generation/__init__.py@@ -0,0 +1,13 @@+from litellm.llms.base_llm.image_generation.transformation import (+ BaseImageGenerationConfig,+)++from .transformation import AimlImageGenerationConfig++__all__ = [+ "AimlImageGenerationConfig",+]+++def get_aiml_image_generation_config(model: str) -> BaseImageGenerationConfig:+ return AimlImageGenerationConfig()diff --git a/litellm/llms/aiml/image_generation/cost_calculator.py b/litellm/llms/aiml/image_generation/cost_calculator.pynew file mode 100644index 00000000000..1fecfb6a9a5--- /dev/null+++ b/litellm/llms/aiml/image_generation/cost_calculator.py@@ -0,0 +1,25 @@+from typing import Any++import litellm+from litellm.types.utils import ImageResponse+++def cost_calculator(+ model: str,+ image_response: Any,+) -> float:+ """+ AI/ML flux image generation cost calculator+ """+ _model_info = litellm.get_model_info(+ model=model,+ custom_llm_provider=litellm.LlmProviders.AIML.value,+ )+ output_cost_per_image: float = _model_info.get("output_cost_per_image") or 0.0+ num_images: int = 0+ if isinstance(image_response, ImageResponse):+ if image_response.data:+ num_images = len(image_response.data)+ return output_cost_per_image * num_images+ else:+ raise ValueError(f"image_response must be of type ImageResponse got type={type(image_response)}")diff --git a/litellm/llms/aiml/image_generation/transformation.py b/litellm/llms/aiml/image_generation/transformation.pynew file mode 100644index 00000000000..2686f7a267c--- /dev/null+++ b/litellm/llms/aiml/image_generation/transformation.py@@ -0,0 +1,184 @@+from typing import TYPE_CHECKING, Any, List, Optional++import httpx++from litellm.llms.base_llm.image_generation.transformation import (+ BaseImageGenerationConfig,+)+from litellm.secret_managers.main import get_secret_str+from litellm.types.llms.aiml import AimlImageGenerationRequestParams+from litellm.types.llms.openai import (+ AllMessageValues,+ OpenAIImageGenerationOptionalParams,+)+from litellm.types.utils import ImageObject, ImageResponse++if TYPE_CHECKING:+ from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj++ LiteLLMLoggingObj = _LiteLLMLoggingObj+else:+ LiteLLMLoggingObj = Any+++class AimlImageGenerationConfig(BaseImageGenerationConfig):+ DEFAULT_BASE_URL: str = "https://api.aimlapi.com"+ IMAGE_GENERATION_ENDPOINT: str = "v1/images/generations"++ def get_supported_openai_params(+ self, model: str+ ) -> List[OpenAIImageGenerationOptionalParams]:+ """+ https://api.aimlapi.com/v1/images/generations+ """+ return [+ "n",+ "response_format",+ "size"+ ]++ def map_openai_params(+ self,+ non_default_params: dict,+ optional_params: dict,+ model: str,+ drop_params: bool,+ ) -> dict:+ supported_params = self.get_supported_openai_params(model)++ for k in non_default_params.keys():+ if k not in optional_params.keys():+ if k in supported_params:+ # Map OpenAI params to AI/ML params+ if k == "n":+ optional_params["num_images"] = non_default_params[k]+ elif k == "response_format":+ optional_params["output_format"] = non_default_params[k]+ elif k == "size":+ # Map OpenAI size format to AI/ML image_size+ size_value = non_default_params[k]+ if isinstance(size_value, str):+ # Handle standard OpenAI sizes like "1024x1024"+ if "x" in size_value:+ width, height = map(int, size_value.split("x"))+ optional_params["image_size"] = {"width": width, "height": height}+ else:+ # Pass through predefined sizes+ optional_params["image_size"] = size_value+ else:+ optional_params["image_size"] = size_value+ else:+ optional_params[k] = non_default_params[k]+ elif drop_params:+ pass+ else:+ raise ValueError(+ f"Parameter {k} is not supported for model {model}. Supported parameters are {supported_params}. Set drop_params=True to drop unsupported parameters."+ )++ 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:+ """+ Get the complete url for the request+ """+ complete_url: str = (+ api_base+ or get_secret_str("AIML_API_BASE")+ or self.DEFAULT_BASE_URL+ )++ complete_url = complete_url.rstrip("/")+ complete_url = f"{complete_url}/{self.IMAGE_GENERATION_ENDPOINT}"+ return complete_url++ def validate_environment(+ self,+ headers: dict,+ model: str,+ messages: List[AllMessageValues],+ optional_params: dict,+ litellm_params: dict,+ api_key: Optional[str] = None,+ api_base: Optional[str] = None,+ ) -> dict:+ final_api_key: Optional[str] = (+ api_key or+ get_secret_str("AIML_API_KEY") or+ get_secret_str("AIMLAPI_KEY") # Alternative name+ )+ if not final_api_key:+ raise ValueError("AIML_API_KEY or AIMLAPI_KEY is not set")++ headers["Authorization"] = f"Bearer {final_api_key}"+ headers["Content-Type"] = "application/json"+ return headers++ def transform_image_generation_request(+ self,+ model: str,+ prompt: str,+ optional_params: dict,+ litellm_params: dict,+ headers: dict,+ ) -> dict:+ """+ Transform the image generation request to the AI/ML flux image generation request body++ https://api.aimlapi.com/v1/images/generations+ """+ aiml_image_generation_request_body: AimlImageGenerationRequestParams = AimlImageGenerationRequestParams(+ prompt=prompt,+ model=model,+ **optional_params,+ )+ return dict(aiml_image_generation_request_body)++ def transform_image_generation_response(+ self,+ model: str,+ raw_response: httpx.Response,+ model_response: ImageResponse,+ logging_obj: LiteLLMLoggingObj,+ request_data: dict,+ optional_params: dict,+ litellm_params: dict,+ encoding: Any,+ api_key: Optional[str] = None,+ json_mode: Optional[bool] = None,+ ) -> ImageResponse:+ """+ Transform the image generation response to the litellm image response++ https://api.aimlapi.com/v1/images/generations+ """+ try:+ response_data = raw_response.json()+ except Exception as e:+ raise self.get_error_class(+ error_message=f"Error transforming image generation response: {e}",+ status_code=raw_response.status_code,+ headers=raw_response.headers,+ )++ if not model_response.data:+ model_response.data = []++ # AI/ML API returns images in output.choices array with image_base64+ if "output" in response_data and "choices" in response_data["output"]:+ for choice in response_data["output"]["choices"]:+ if "image_base64" in choice:+ model_response.data.append(ImageObject(+ b64_json=choice["image_base64"],+ url=None, # AI/ML API returns base64, not URLs+ ))++ return model_responsediff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex 202e7f0759f..a29d03f2c6c 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -19633,5 +19633,118 @@"supports_function_calling": true,"supports_response_schema": false,"source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing"+ },+ "aiml/flux/kontext-pro/text-to-image":{+ "output_cost_per_image": 0.042,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Pro v1.1 - Enhanced version with improved capabilities and 6x faster inference speed"+ }++ },+ "aiml/flux/kontext-max/text-to-image": {+ "output_cost_per_image": 0.084,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Pro v1.1 - Enhanced version with improved capabilities and 6x faster inference speed"+ }+ },+ "aiml/flux-pro/v1.1-ultra": {+ "output_cost_per_image": 0.063,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ]+ },+ "aiml/flux-pro/v1.1": {+ "output_cost_per_image": 0.042,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ]+ },+ "aiml/flux-realism": {+ "output_cost_per_image": 0.037,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Pro - Professional-grade image generation model"+ }+ },+ "aiml/flux/schnell": {+ "output_cost_per_image": 0.003,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Schnell - Fast generation model optimized for speed"+ }+ },+ "aiml/flux/dev": {+ "output_cost_per_image": 0.026,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Dev - Development version optimized for experimentation"+ }+ },+ "aiml/flux-pro": {+ "output_cost_per_image": 0.053,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Dev - Development version optimized for experimentation"+ }+ },+ "aiml/dall-e-3": {+ "output_cost_per_image": 0.042,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "DALL-E 3 via AI/ML API - High-quality text-to-image generation"+ }+ },+ "aiml/dall-e-2": {+ "output_cost_per_image": 0.021,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "DALL-E 2 via AI/ML API - Reliable text-to-image generation"+ }}}diff --git a/litellm/proxy/_experimental/out/assets/logos/aiml_api.svg b/litellm/proxy/_experimental/out/assets/logos/aiml_api.svgnew file mode 100644index 00000000000..660ab920ec0--- /dev/null+++ b/litellm/proxy/_experimental/out/assets/logos/aiml_api.svg@@ -0,0 +1 @@+<svg width='115' height='24' viewBox='0 0 115 24' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M54.7197 20.2415H52.5254L56.4717 5.57938H58.666L54.7197 20.2415ZM47.1865 18.3997H44.4121L43.5059 15.6077H39.083L38.1748 18.3997H35.4004L39.6279 6.15359H42.9648L47.1865 18.3997ZM51.25 18.3997H48.6611V6.15359H51.25V18.3997ZM66.5068 14.3821H66.6504L70.0234 6.15359H73.2168V18.3997H70.7051V10.429H70.6035L67.4346 18.3401H65.7236L62.5547 10.3987H62.4531V18.3997H59.9414V6.15359H63.1348L66.5068 14.3821ZM77.9395 16.2649H83.1895V18.3997H75.3496V6.15359H77.9395V16.2649ZM99.9238 18.3997H97.1494L96.2432 15.6077H91.8203L90.9121 18.3997H88.1377L92.3652 6.15359H95.7021L99.9238 18.3997ZM106.229 6.15359C107.158 6.15359 107.95 6.33102 108.604 6.68582C109.257 7.03664 109.756 7.52478 110.099 8.15067C110.445 8.77246 110.619 9.48993 110.619 10.303C110.619 11.1163 110.444 11.8344 110.093 12.4563C109.742 13.0782 109.233 13.5626 108.567 13.9095C107.906 14.2561 107.105 14.4299 106.164 14.43H103.987V18.3997H101.398V6.15359H106.229ZM114.89 18.3997H112.301V6.15359H114.89V18.3997ZM39.7412 13.5862H42.8496L41.3447 8.95242H41.249L39.7412 13.5862ZM92.4785 13.5862H95.5869L94.082 8.95242H93.9863L92.4785 13.5862ZM103.987 12.3548H105.745C106.243 12.3548 106.655 12.2684 106.978 12.097C107.304 11.9216 107.548 11.681 107.707 11.3743C107.87 11.0633 107.952 10.7056 107.952 10.303C107.952 9.89656 107.87 9.54143 107.707 9.23856C107.548 8.93183 107.304 8.695 106.978 8.52762C106.651 8.35621 106.236 8.26982 105.733 8.26981H103.987V12.3548Z' fill='#01091C'/><path d='M26.5263 10.5744C27.0371 11.4566 27.0371 12.5434 26.5263 13.4256L21.2288 22.5744C20.718 23.4566 19.774 24 18.7523 24H8.15737C7.13573 24 6.1917 23.4566 5.68088 22.5744L0.383412 13.4256C-0.127407 12.5434 -0.127404 11.4566 0.383415 10.5744L5.68088 1.42563C6.1917 0.543447 7.13574 -4.4527e-08 8.15737 0L18.7523 4.61769e-07C19.774 5.06296e-07 20.718 0.543448 21.2288 1.42563L26.5263 10.5744Z' fill='#090F1D'/><path fill-rule='evenodd' clip-rule='evenodd' d='M7.59441 15.9891C7.39517 15.9891 7.19469 15.9257 7.02533 15.7966C6.61689 15.4825 6.53968 14.8977 6.85473 14.4904L10.5818 9.6605C10.7337 9.46308 10.9591 9.33519 11.2057 9.30415C11.4572 9.27187 11.7038 9.3414 11.8993 9.49661L15.4109 12.2468L18.483 8.29471C18.7992 7.88622 19.3845 7.81048 19.793 8.12833C20.2014 8.44371 20.2761 9.02851 19.9598 9.43452L16.3112 14.1279C16.1593 14.3241 15.9352 14.4519 15.6886 14.4817C15.4395 14.5153 15.193 14.4432 14.9962 14.2905L11.4871 11.5416L8.33534 15.6253C8.15105 15.8637 7.8746 15.9891 7.59441 15.9891Z' fill='white'/></svg>\ No newline at end of filediff --git a/litellm/types/llms/aiml.py b/litellm/types/llms/aiml.pynew file mode 100644index 00000000000..3d42518b8b1--- /dev/null+++ b/litellm/types/llms/aiml.py@@ -0,0 +1,25 @@+from typing import Dict, Optional, Union++from typing_extensions import TypedDict+++class AimlImageSize(TypedDict, total=False):+ """Custom image size specification for AI/ML API"""+ width: int # Must be multiple of 32, min 256, max 1440+ height: int # Must be multiple of 32, min 256, max 1440+++class AimlImageGenerationRequestParams(TypedDict, total=False):+ """+ TypedDict for AI/ML flux image generation request parameters.++ Based on AI/ML API docs: https://api.aimlapi.com/v1/images/generations+ """+ model: str # Required: flux-pro/v1.1+ prompt: str # Required: Text prompt (max 4000 chars)+ image_size: Union[AimlImageSize, str] # Custom size or predefined: square_hd, square, portrait_4_3, portrait_16_9, landscape_4_3, landscape_16_9+ safety_tolerance: Optional[str] # 1-6, default 2 (1=strict, 6=permissive)+ output_format: Optional[str] # jpeg or png, default jpeg+ num_images: Optional[int] # 1-4, default 1+ seed: Optional[int] # Min 1, for reproducibility+ enable_safety_checker: Optional[bool] # Default truediff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 7ae92185e72..fad46a8b9f5 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -2330,6 +2330,7 @@ class LlmProviders(str, Enum):PG_VECTOR = "pg_vector"HYPERBOLIC = "hyperbolic"RECRAFT = "recraft"+ AIML = "aiml"COMETAPI = "cometapi"OCI = "oci"AUTO_ROUTER = "auto_router"diff --git a/litellm/utils.py b/litellm/utils.pyindex bf8aefb95d7..2821720e06d 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -7339,6 +7339,12 @@ class ProviderConfigManager:)return get_recraft_image_generation_config(model)+ elif LlmProviders.AIML == provider:+ from litellm.llms.aiml.image_generation import (+ get_aiml_image_generation_config,+ )++ return get_aiml_image_generation_config(model)elif LlmProviders.GEMINI == provider:from litellm.llms.gemini.image_generation import (get_gemini_image_generation_config,diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex 202e7f0759f..a29d03f2c6c 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -19633,5 +19633,118 @@"supports_function_calling": true,"supports_response_schema": false,"source": "https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/pricing"+ },+ "aiml/flux/kontext-pro/text-to-image":{+ "output_cost_per_image": 0.042,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Pro v1.1 - Enhanced version with improved capabilities and 6x faster inference speed"+ }++ },+ "aiml/flux/kontext-max/text-to-image": {+ "output_cost_per_image": 0.084,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Pro v1.1 - Enhanced version with improved capabilities and 6x faster inference speed"+ }+ },+ "aiml/flux-pro/v1.1-ultra": {+ "output_cost_per_image": 0.063,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ]+ },+ "aiml/flux-pro/v1.1": {+ "output_cost_per_image": 0.042,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ]+ },+ "aiml/flux-realism": {+ "output_cost_per_image": 0.037,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Pro - Professional-grade image generation model"+ }+ },+ "aiml/flux/schnell": {+ "output_cost_per_image": 0.003,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Schnell - Fast generation model optimized for speed"+ }+ },+ "aiml/flux/dev": {+ "output_cost_per_image": 0.026,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Dev - Development version optimized for experimentation"+ }+ },+ "aiml/flux-pro": {+ "output_cost_per_image": 0.053,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "Flux Dev - Development version optimized for experimentation"+ }+ },+ "aiml/dall-e-3": {+ "output_cost_per_image": 0.042,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "DALL-E 3 via AI/ML API - High-quality text-to-image generation"+ }+ },+ "aiml/dall-e-2": {+ "output_cost_per_image": 0.021,+ "litellm_provider": "aiml",+ "mode": "image_generation",+ "supported_endpoints": [+ "/v1/images/generations"+ ],+ "source": "https://docs.aimlapi.com/",+ "metadata": {+ "notes": "DALL-E 2 via AI/ML API - Reliable text-to-image generation"+ }}}diff --git a/tests/image_gen_tests/test_image_generation.py b/tests/image_gen_tests/test_image_generation.pyindex 0e5f1d79faf..043a0a88fd1 100644--- a/tests/image_gen_tests/test_image_generation.py+++ b/tests/image_gen_tests/test_image_generation.py@@ -169,6 +169,10 @@ class TestRecraftImageGeneration(BaseImageGenTest):def get_base_image_generation_call_args(self) -> dict:return {"model": "recraft/recraftv3"}+class TestAimlImageGeneration(BaseImageGenTest):+ def get_base_image_generation_call_args(self) -> dict:+ return {"model": "aiml/flux-pro/v1.1"}+class TestGoogleImageGen(BaseImageGenTest):def get_base_image_generation_call_args(self) -> dict:return {"model": "gemini/imagen-4.0-generate-preview-06-06"}diff --git a/ui/litellm-dashboard/out/assets/logos/aiml_api.svg b/ui/litellm-dashboard/out/assets/logos/aiml_api.svgnew file mode 100644index 00000000000..660ab920ec0--- /dev/null+++ b/ui/litellm-dashboard/out/assets/logos/aiml_api.svg@@ -0,0 +1 @@+<svg width='115' height='24' viewBox='0 0 115 24' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M54.7197 20.2415H52.5254L56.4717 5.57938H58.666L54.7197 20.2415ZM47.1865 18.3997H44.4121L43.5059 15.6077H39.083L38.1748 18.3997H35.4004L39.6279 6.15359H42.9648L47.1865 18.3997ZM51.25 18.3997H48.6611V6.15359H51.25V18.3997ZM66.5068 14.3821H66.6504L70.0234 6.15359H73.2168V18.3997H70.7051V10.429H70.6035L67.4346 18.3401H65.7236L62.5547 10.3987H62.4531V18.3997H59.9414V6.15359H63.1348L66.5068 14.3821ZM77.9395 16.2649H83.1895V18.3997H75.3496V6.15359H77.9395V16.2649ZM99.9238 18.3997H97.1494L96.2432 15.6077H91.8203L90.9121 18.3997H88.1377L92.3652 6.15359H95.7021L99.9238 18.3997ZM106.229 6.15359C107.158 6.15359 107.95 6.33102 108.604 6.68582C109.257 7.03664 109.756 7.52478 110.099 8.15067C110.445 8.77246 110.619 9.48993 110.619 10.303C110.619 11.1163 110.444 11.8344 110.093 12.4563C109.742 13.0782 109.233 13.5626 108.567 13.9095C107.906 14.2561 107.105 14.4299 106.164 14.43H103.987V18.3997H101.398V6.15359H106.229ZM114.89 18.3997H112.301V6.15359H114.89V18.3997ZM39.7412 13.5862H42.8496L41.3447 8.95242H41.249L39.7412 13.5862ZM92.4785 13.5862H95.5869L94.082 8.95242H93.9863L92.4785 13.5862ZM103.987 12.3548H105.745C106.243 12.3548 106.655 12.2684 106.978 12.097C107.304 11.9216 107.548 11.681 107.707 11.3743C107.87 11.0633 107.952 10.7056 107.952 10.303C107.952 9.89656 107.87 9.54143 107.707 9.23856C107.548 8.93183 107.304 8.695 106.978 8.52762C106.651 8.35621 106.236 8.26982 105.733 8.26981H103.987V12.3548Z' fill='#01091C'/><path d='M26.5263 10.5744C27.0371 11.4566 27.0371 12.5434 26.5263 13.4256L21.2288 22.5744C20.718 23.4566 19.774 24 18.7523 24H8.15737C7.13573 24 6.1917 23.4566 5.68088 22.5744L0.383412 13.4256C-0.127407 12.5434 -0.127404 11.4566 0.383415 10.5744L5.68088 1.42563C6.1917 0.543447 7.13574 -4.4527e-08 8.15737 0L18.7523 4.61769e-07C19.774 5.06296e-07 20.718 0.543448 21.2288 1.42563L26.5263 10.5744Z' fill='#090F1D'/><path fill-rule='evenodd' clip-rule='evenodd' d='M7.59441 15.9891C7.39517 15.9891 7.19469 15.9257 7.02533 15.7966C6.61689 15.4825 6.53968 14.8977 6.85473 14.4904L10.5818 9.6605C10.7337 9.46308 10.9591 9.33519 11.2057 9.30415C11.4572 9.27187 11.7038 9.3414 11.8993 9.49661L15.4109 12.2468L18.483 8.29471C18.7992 7.88622 19.3845 7.81048 19.793 8.12833C20.2014 8.44371 20.2761 9.02851 19.9598 9.43452L16.3112 14.1279C16.1593 14.3241 15.9352 14.4519 15.6886 14.4817C15.4395 14.5153 15.193 14.4432 14.9962 14.2905L11.4871 11.5416L8.33534 15.6253C8.15105 15.8637 7.8746 15.9891 7.59441 15.9891Z' fill='white'/></svg>\ No newline at end of filediff --git a/ui/litellm-dashboard/public/assets/logos/aiml_api.svg b/ui/litellm-dashboard/public/assets/logos/aiml_api.svgnew file mode 100644index 00000000000..660ab920ec0--- /dev/null+++ b/ui/litellm-dashboard/public/assets/logos/aiml_api.svg@@ -0,0 +1 @@+<svg width='115' height='24' viewBox='0 0 115 24' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M54.7197 20.2415H52.5254L56.4717 5.57938H58.666L54.7197 20.2415ZM47.1865 18.3997H44.4121L43.5059 15.6077H39.083L38.1748 18.3997H35.4004L39.6279 6.15359H42.9648L47.1865 18.3997ZM51.25 18.3997H48.6611V6.15359H51.25V18.3997ZM66.5068 14.3821H66.6504L70.0234 6.15359H73.2168V18.3997H70.7051V10.429H70.6035L67.4346 18.3401H65.7236L62.5547 10.3987H62.4531V18.3997H59.9414V6.15359H63.1348L66.5068 14.3821ZM77.9395 16.2649H83.1895V18.3997H75.3496V6.15359H77.9395V16.2649ZM99.9238 18.3997H97.1494L96.2432 15.6077H91.8203L90.9121 18.3997H88.1377L92.3652 6.15359H95.7021L99.9238 18.3997ZM106.229 6.15359C107.158 6.15359 107.95 6.33102 108.604 6.68582C109.257 7.03664 109.756 7.52478 110.099 8.15067C110.445 8.77246 110.619 9.48993 110.619 10.303C110.619 11.1163 110.444 11.8344 110.093 12.4563C109.742 13.0782 109.233 13.5626 108.567 13.9095C107.906 14.2561 107.105 14.4299 106.164 14.43H103.987V18.3997H101.398V6.15359H106.229ZM114.89 18.3997H112.301V6.15359H114.89V18.3997ZM39.7412 13.5862H42.8496L41.3447 8.95242H41.249L39.7412 13.5862ZM92.4785 13.5862H95.5869L94.082 8.95242H93.9863L92.4785 13.5862ZM103.987 12.3548H105.745C106.243 12.3548 106.655 12.2684 106.978 12.097C107.304 11.9216 107.548 11.681 107.707 11.3743C107.87 11.0633 107.952 10.7056 107.952 10.303C107.952 9.89656 107.87 9.54143 107.707 9.23856C107.548 8.93183 107.304 8.695 106.978 8.52762C106.651 8.35621 106.236 8.26982 105.733 8.26981H103.987V12.3548Z' fill='#01091C'/><path d='M26.5263 10.5744C27.0371 11.4566 27.0371 12.5434 26.5263 13.4256L21.2288 22.5744C20.718 23.4566 19.774 24 18.7523 24H8.15737C7.13573 24 6.1917 23.4566 5.68088 22.5744L0.383412 13.4256C-0.127407 12.5434 -0.127404 11.4566 0.383415 10.5744L5.68088 1.42563C6.1917 0.543447 7.13574 -4.4527e-08 8.15737 0L18.7523 4.61769e-07C19.774 5.06296e-07 20.718 0.543448 21.2288 1.42563L26.5263 10.5744Z' fill='#090F1D'/><path fill-rule='evenodd' clip-rule='evenodd' d='M7.59441 15.9891C7.39517 15.9891 7.19469 15.9257 7.02533 15.7966C6.61689 15.4825 6.53968 14.8977 6.85473 14.4904L10.5818 9.6605C10.7337 9.46308 10.9591 9.33519 11.2057 9.30415C11.4572 9.27187 11.7038 9.3414 11.8993 9.49661L15.4109 12.2468L18.483 8.29471C18.7992 7.88622 19.3845 7.81048 19.793 8.12833C20.2014 8.44371 20.2761 9.02851 19.9598 9.43452L16.3112 14.1279C16.1593 14.3241 15.9352 14.4519 15.6886 14.4817C15.4395 14.5153 15.193 14.4432 14.9962 14.2905L11.4871 11.5416L8.33534 15.6253C8.15105 15.8637 7.8746 15.9891 7.59441 15.9891Z' fill='white'/></svg>\ No newline at end of filediff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.tsxindex d8e03d7fe27..31f5b10043b 100644--- a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx+++ b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx@@ -3,6 +3,7 @@ import React from "react";import NotificationManager from "./molecules/notifications_manager";export enum Providers {+ AIML = "AI/ML API",Bedrock = "Amazon Bedrock",Anthropic = "Anthropic",AssemblyAI = "AssemblyAI",@@ -40,6 +41,7 @@ export enum Providers {}export const provider_map: Record<string, string> = {+ AIML: "aiml",OpenAI: "openai",OpenAI_Text: "text-completion-openai",Azure: "azure",@@ -79,6 +81,7 @@ export const provider_map: Record<string, string> = {const asset_logos_folder = '/ui/assets/logos/';export const providerLogoMap: Record<string, string> = {+ [Providers.AIML]: `${asset_logos_folder}aiml_api.svg`,[Providers.Anthropic]: `${asset_logos_folder}anthropic.svg`,[Providers.AssemblyAI]: `${asset_logos_folder}assemblyai_small.png`,[Providers.Azure]: `${asset_logos_folder}microsoft_azure.svg`,@@ -144,7 +147,9 @@ export const getProviderLogoAndName = (providerValue: string): { logo: string, d};export const getPlaceholder = (selectedProvider: string): string => {- if (selectedProvider === Providers.Vertex_AI) {+ if (selectedProvider === Providers.AIML) {+ return "aiml/flux-pro/v1.1";+ } else if (selectedProvider === Providers.Vertex_AI) {return "gemini-pro";} else if (selectedProvider == Providers.Anthropic) {return "claude-3-opus";