diff --git a/docs/image_edits.md b/docs/image_edits.md index 21912df3e..dca02f96d 100644 --- a/docs/image_edits.md +++ b/docs/image_edits.md @@ -16,7 +16,7 @@ LiteLLM provides image editing functionality that maps to OpenAI's `/images/edit | Supported operations | Create image edits | Single and multiple images supported | | Supported LiteLLM SDK Versions | 1.63.8+ | Gemini support requires 1.79.3+ | | Supported LiteLLM Proxy Versions | 1.71.1+ | Gemini support requires 1.79.3+ | -| Supported LLM providers | **OpenAI**, **Gemini (Google AI Studio)**, **Vertex AI**, **OpenRouter**, **Stability AI**, **AWS Bedrock (Stability)**, **Black Forest Labs**, **Hosted vLLM (vLLM-Omni)** | Gemini supports the new `gemini-2.5-flash-image` family. Vertex AI supports both Gemini and Imagen models. OpenRouter routes image edits through chat completions. Stability AI and Bedrock Stability support various image editing operations. Black Forest Labs supports FLUX Kontext models. Hosted vLLM routes to a vLLM-Omni server's OpenAI-compatible `/v1/images/edits`. | +| Supported LLM providers | **OpenAI**, **Gemini (Google AI Studio)**, **Vertex AI**, **OpenRouter**, **Stability AI**, **AWS Bedrock (Stability)**, **Black Forest Labs**, **Azure AI (FLUX)**, **Hosted vLLM (vLLM-Omni)** | Gemini supports the new `gemini-2.5-flash-image` family. Vertex AI supports both Gemini and Imagen models. OpenRouter routes image edits through chat completions. Stability AI and Bedrock Stability support various image editing operations. Black Forest Labs supports FLUX Kontext models. Hosted vLLM routes to a vLLM-Omni server's OpenAI-compatible `/v1/images/edits`. | #### ⚡️See all supported models and providers at [models.litellm.ai](https://models.litellm.ai/) diff --git a/docs/providers/azure_ai_img.md b/docs/providers/azure_ai_img.md index d7a6d93d2..684a5bb11 100644 --- a/docs/providers/azure_ai_img.md +++ b/docs/providers/azure_ai_img.md @@ -34,6 +34,9 @@ Get your API key and endpoint from [Azure AI Studio](https://ai.azure.com/). | `azure_ai/FLUX-1.1-pro` | Latest FLUX 1.1 Pro model for high-quality image generation | $0.04 | | `azure_ai/FLUX.1-Kontext-pro` | FLUX 1 Kontext Pro model with enhanced context understanding | $0.04 | | `azure_ai/flux.2-pro` | FLUX 2 Pro model for next-generation image generation | $0.04 | +| `azure_ai/FLUX.2-flex` | FLUX 2 Flex model with adjustable `guidance` and `steps` | $0.05 per megapixel ($0.052 at 1024x1024) | + +FLUX 2 models are served from Azure's Black Forest Labs route rather than the Azure OpenAI deployment route: `flux.2-pro` requests go to `/providers/blackforestlabs/v1/flux-2-pro` and `FLUX.2-flex` requests go to `/providers/blackforestlabs/v1/flux-2-flex`, both under your `api_base`. The model name is matched case-insensitively, so `azure_ai/flux.2-flex` works too. FLUX 2 Flex is billed per pixel of the generated image, so the cost LiteLLM records follows the `size` (or `width` and `height`) you request; without explicit dimensions it is recorded at 1024x1024, which is what Azure generates by default ## Image Generation @@ -112,6 +115,34 @@ print(response.data[0].b64_json) # FLUX 2 returns base64 encoded images + + +```python showLineNumbers title="FLUX 2 Flex Image Generation" +import litellm +import os + +# Set your API credentials +os.environ["AZURE_AI_API_KEY"] = "your-api-key-here" +os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint" # e.g., https://your-resource.services.ai.azure.com + +# Generate image with FLUX 2 Flex, tuning guidance and steps +response = litellm.image_generation( + model="azure_ai/FLUX.2-flex", + prompt="A photograph of a red fox in an autumn forest", + api_base=os.environ["AZURE_AI_API_BASE"], + api_key=os.environ["AZURE_AI_API_KEY"], + api_version="preview", + size="1536x1024", + n=1, + guidance=4.5, + steps=32, +) + +print(response.data[0].b64_json) # FLUX 2 returns base64 encoded images +``` + + + ```python showLineNumbers title="Async Image Generation" @@ -201,6 +232,15 @@ model_list: model_info: mode: image_generation + - model_name: azure-flux-2-flex + litellm_params: + model: azure_ai/FLUX.2-flex + api_key: os.environ/AZURE_AI_API_KEY + api_base: os.environ/AZURE_AI_API_BASE + api_version: preview + model_info: + mode: image_generation + general_settings: master_key: os.environ/LITELLM_MASTER_KEY ``` @@ -385,6 +425,21 @@ Azure AI Image Generation supports the following OpenAI-compatible parameters: | `api_base` | string | Your Azure AI endpoint URL | Required | `"https://your-endpoint.eastus2.inference.ai.azure.com/"` | | `api_key` | string | Your Azure AI API key | Required | Environment variable or direct value | +### FLUX 2 parameters + +FLUX 2 Pro and FLUX 2 Flex take `n`, `size`, `output_format`, `seed`, `safety_tolerance`, and `aspect_ratio`, plus the Black Forest Labs names `width`, `height`, `num_images`, `guidance`, and `steps`. `size` is sent as `width` and `height` (`"1536x1024"` becomes `width: 1536, height: 1024`), `n` is sent as `num_images`, and `size: "auto"` sends no dimensions so Azure picks its default. A `size` that is not `WxH`, such as `"large"`, is rejected with a 400 naming the expected format. The OpenAI-only fields `user`, `quality`, `background`, `moderation`, and `output_compression` are accepted and dropped, so clients built for `gpt-image-1` keep working without `drop_params`. Any other unsupported field is rejected unless `drop_params` is set. Azure returns one image per request for FLUX 2 models regardless of `n` + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `size` | string | `WxH` dimensions, or `"auto"` for Azure's default | `"1536x1024"` | +| `width`, `height` | integer | Dimensions in pixels, an alternative to `size` | `1536`, `1024` | +| `output_format` | string | Image encoding | `"jpeg"`, `"png"` | +| `seed` | integer | Seed for reproducible output | `42` | +| `safety_tolerance` | integer | Content moderation strictness | `2` | +| `aspect_ratio` | string | Aspect ratio of the generated image | `"16:9"` | +| `guidance` | float | Prompt adherence (FLUX 2 Flex) | `4.5` | +| `steps` | integer | Diffusion steps (FLUX 2 Flex) | `32` | + ## Getting Started 1. Create an account at [Azure AI Studio](https://ai.azure.com/) diff --git a/docs/providers/azure_ai_img_edit.md b/docs/providers/azure_ai_img_edit.md index 80d729de7..bd4b99e27 100644 --- a/docs/providers/azure_ai_img_edit.md +++ b/docs/providers/azure_ai_img_edit.md @@ -33,6 +33,10 @@ Get your API key and endpoint from [Azure AI Studio](https://ai.azure.com/). | Model Name | Description | Cost per Image | |------------|-------------|----------------| | `azure_ai/FLUX.1-Kontext-pro` | FLUX 1 Kontext Pro model with enhanced context understanding for editing | $0.04 | +| `azure_ai/flux.2-pro` | FLUX 2 Pro, up to 8 reference images per edit | $0.04 | +| `azure_ai/FLUX.2-flex` | FLUX 2 Flex, up to 10 reference images per edit, adjustable `guidance` and `steps` | $0.05 per megapixel ($0.052 at 1024x1024) | + +FLUX 2 edits go to the same model-specific Black Forest Labs route as FLUX 2 generation (`/providers/blackforestlabs/v1/flux-2-pro` or `/providers/blackforestlabs/v1/flux-2-flex`), with the reference images sent as base64 in the JSON body instead of multipart form data. Pass a list of files as `image` to edit against several references at once. The model name is matched case-insensitively, so `azure_ai/flux.2-flex` works too ## Image Editing @@ -137,6 +141,36 @@ path = Path("advanced_edited_image.png") path.write_bytes(img_bytes) ``` + + + + +```python showLineNumbers title="FLUX 2 Flex Edit with Several Reference Images" +import os +import base64 +from pathlib import Path + +import litellm + +os.environ["AZURE_AI_API_KEY"] = "your-api-key-here" +os.environ["AZURE_AI_API_BASE"] = "your-azure-ai-endpoint" # e.g., https://your-resource.services.ai.azure.com + +# FLUX 2 Flex accepts up to 10 reference images, FLUX 2 Pro up to 8 +response = litellm.image_edit( + model="azure_ai/FLUX.2-flex", + image=[open("subject.png", "rb"), open("style.png", "rb")], + prompt="Render the subject from the first image in the style of the second", + api_base=os.environ["AZURE_AI_API_BASE"], + api_key=os.environ["AZURE_AI_API_KEY"], + api_version="preview", + size="1024x1024", + guidance=4.5, + steps=32, +) +img_bytes = base64.b64decode(response.data[0].get("b64_json")) +Path("flux2_edited_image.png").write_bytes(img_bytes) +``` + @@ -155,6 +189,15 @@ model_list: model_info: mode: image_edit + - model_name: azure-flux-2-flex-edit + litellm_params: + model: azure_ai/FLUX.2-flex + api_key: os.environ/AZURE_AI_API_KEY + api_base: os.environ/AZURE_AI_API_BASE + api_version: preview + model_info: + mode: image_edit + general_settings: master_key: os.environ/LITELLM_MASTER_KEY ``` @@ -245,6 +288,8 @@ Azure AI Image Editing supports the following OpenAI-compatible parameters: | `api_key` | string | Your Azure AI API key | Required | Environment variable or direct value | | `api_version` | string | API version for Azure AI | Required | `"2025-04-01-preview"` | +FLUX 2 Pro and FLUX 2 Flex edits take the same parameters as [FLUX 2 generation](./azure_ai_img#flux-2-parameters): `size` (or `width` and `height`), `output_format`, `seed`, `safety_tolerance`, `aspect_ratio`, and for Flex `guidance` and `steps`. The OpenAI-only fields `user`, `quality`, `background`, `moderation`, and `output_compression` are accepted and dropped, so an OpenAI SDK client that sets them keeps working + ## Getting Started 1. Create an account at [Azure AI Studio](https://ai.azure.com/)