* docs: Corrected documentation updates from Sept 2025 This PR contains the actual intended documentation changes, properly synced with main: ✅ Real changes applied: - Added AWS authentication link to bedrock guardrails documentation - Updated Vertex AI with Gemini API alternative configuration - Added async_post_call_success_hook code snippet to custom callback docs - Added SSO free for up to 5 users information to enterprise and custom_sso docs - Added SSO free information block to security.md - Added cancel response API usage and curl example to response_api.md - Added image for modifying default user budget via admin UI - Re-ordered sidebars in documentation ❌ Sync issues resolved: - Kept all upstream changes that were added to main after branch diverged - Preserved Provider-Specific Metadata Parameters section that was added upstream - Maintained proper curl parameter formatting (-d instead of -D) This corrects the sync issues from the original PR #14769. * docs: Restore missing files from original PR Added back ~16 missing documentation files that were part of the original PR: ✅ Restored files: - docs/my-website/docs/completion/usage.md - docs/my-website/docs/fine_tuning.md - docs/my-website/docs/getting_started.md - docs/my-website/docs/image_edits.md - docs/my-website/docs/image_generation.md - docs/my-website/docs/index.md - docs/my-website/docs/moderation.md - docs/my-website/docs/observability/callbacks.md - docs/my-website/docs/providers/bedrock.md - docs/my-website/docs/proxy/caching.md - docs/my-website/docs/proxy/config_settings.md - docs/my-website/docs/proxy/db_deadlocks.md - docs/my-website/docs/proxy/load_balancing.md - docs/my-website/docs/proxy_api.md - docs/my-website/docs/rerank.md ✅ Fixed context-caching issue: - Restored provider_specific_params.md to main version (preserving Provider-Specific Metadata Parameters section) - Your original PR didn't intend to modify this file - it was just a sync issue Now includes all ~26 documentation files from the original PR #14769. * docs: Remove files that were deleted in original PR - Removed docs/my-website/docs/providers/azure_ai_img_edit.md (was deleted in original PR) - sdk/headers.md was already not present Now matches the complete intended changes from original PR #14769. * docs: Restore azure_ai_img_edit.md from main - Restored docs/my-website/docs/providers/azure_ai_img_edit.md from main branch - This file should not have been deleted as it was a newer commit - SDK headers file doesn't exist in main (was reverted) and wasn't part of your original changes Fixes the file restoration issues. * docs: Fix vertex.md - preserve context caching from newer commit - Restored vertex.md to main version to preserve context caching content (lines 817-887) - Added back only your intended change: alternative gemini config example - Context caching content from newer commit is now preserved Fixes the vertex.md sync issue where newer content was incorrectly deleted. * docs: Fix providers/bedrock.md - restore deleted content from newer commit - Restored providers/bedrock.md to main version - Preserves 'Usage - Request Metadata' section that was added in newer commit - Your actual intended change was to proxy/guardrails/bedrock.md (authentication tip) which is preserved - Now only has additions, no subtractions as intended Fixes the bedrock.md sync issue. * docs: Restore missing IAM policy section in bedrock.md Added back your intended IAM policy documentation that was lost when restoring main version: ✅ Added IAM AssumeRole Policy section: - Explains requirement for sts:AssumeRole permission - Shows error message example when permission missing - Provides complete IAM policy JSON example - Links to AWS AssumeRole documentation - Clarifies trust policy requirements Now bedrock.md has both: - All newer content preserved (Request Metadata section) - Your intended IAM policy addition restored --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
9.6 KiB
import Image from '@theme/IdealImage'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Image Generations
Quick Start
LiteLLM Python SDK
from litellm import image_generation
import os
# set api keys
os.environ["OPENAI_API_KEY"] = ""
response = image_generation(prompt="A cute baby sea otter", model="dall-e-3")
print(f"response: {response}")
LiteLLM Proxy
Setup config.yaml
model_list:
- model_name: gpt-image-1 ### RECEIVED MODEL NAME ###
litellm_params: # all params accepted by litellm.image_generation()
model: azure/gpt-image-1 ### MODEL NAME sent to `litellm.image_generation()` ###
api_base: https://my-endpoint-europe-berri-992.openai.azure.com/
api_key: "os.environ/AZURE_API_KEY_EU" # does os.getenv("AZURE_API_KEY_EU")
Start proxy
litellm --config /path/to/config.yaml
# RUNNING on http://0.0.0.0:4000
Test
curl -X POST 'http://0.0.0.0:4000/v1/images/generations' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"model": "gpt-image-1",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "1024x1024"
}'
from openai import OpenAI
client = openai.OpenAI(
api_key="sk-1234",
base_url="http://0.0.0.0:4000"
)
image = client.images.generate(
prompt="A cute baby sea otter",
model="dall-e-3",
)
print(image)
Input Params for litellm.image_generation()
:::info
Any non-openai params, will be treated as provider-specific params, and sent in the request body as kwargs to the provider.
Required Fields
prompt: string - A text description of the desired image(s).
Optional LiteLLM Fields
model: Optional[str] = None,
n: Optional[int] = None,
quality: Optional[str] = None,
response_format: Optional[str] = None,
size: Optional[str] = None,
style: Optional[str] = None,
user: Optional[str] = None,
timeout=600, # default to 10 minutes
api_key: Optional[str] = None,
api_base: Optional[str] = None,
api_version: Optional[str] = None,
litellm_logging_obj=None,
custom_llm_provider=None,
-
model: string (optional) The model to use for image generation. Defaults to openai/gpt-image-1 -
n: int (optional) The number of images to generate. Must be between 1 and 10. For dall-e-3, only n=1 is supported. -
quality: string (optional) The quality of the image that will be generated.auto(default value) will automatically select the best quality for the given model.high,mediumandloware supported forgpt-image-1.hdandstandardare supported fordall-e-3.standardis the only option fordall-e-2.
-
response_format: string (optional) The format in which the generated images are returned. Must be one of url or b64_json. -
size: string (optional) The size of the generated images. Must be one of1024x1024,1536x1024(landscape),1024x1536(portrait), orauto(default value) forgpt-image-1, one of256x256,512x512, or1024x1024fordall-e-2, and one of1024x1024,1792x1024, or1024x1792fordall-e-3. -
timeout: integer - The maximum time, in seconds, to wait for the API to respond. Defaults to 600 seconds (10 minutes). -
user: string (optional) A unique identifier representing your end-user, -
api_base: string (optional) - The api endpoint you want to call the model with -
api_version: string (optional) - (Azure-specific) the api version for the call; required for dall-e-3 on Azure -
api_key: string (optional) - The API key to authenticate and authorize requests. If not provided, the default API key is used. -
api_type: string (optional) - The type of API to use.
Output from litellm.image_generation()
{
"created": 1703658209,
"data": [{
'b64_json': None,
'revised_prompt': 'Adorable baby sea otter with a coat of thick brown fur, playfully swimming in blue ocean waters. Its curious, bright eyes gleam as it is surfaced above water, tiny paws held close to its chest, as it playfully spins in the gentle waves under the soft rays of a setting sun.',
'url': 'https://oaidalleapiprodscus.blob.core.windows.net/private/org-ikDc4ex8NB5ZzfTf8m5WYVB7/user-JpwZsbIXubBZvan3Y3GchiiB/img-dpa3g5LmkTrotY6M93dMYrdE.png?st=2023-12-27T05%3A23%3A29Z&se=2023-12-27T07%3A23%3A29Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-12-26T13%3A22%3A56Z&ske=2023-12-27T13%3A22%3A56Z&sks=b&skv=2021-08-06&sig=hUuQjYLS%2BvtsDdffEAp2gwewjC8b3ilggvkd9hgY6Uw%3D'
}],
"usage": {'prompt_tokens': 0, 'completion_tokens': 0, 'total_tokens': 0}
}
OpenAI Image Generation Models
Usage
from litellm import image_generation
import os
os.environ['OPENAI_API_KEY'] = ""
response = image_generation(model='gpt-image-1', prompt="cute baby otter")
| Model Name | Function Call | Required OS Variables |
|---|---|---|
| gpt-image-1 | image_generation(model='gpt-image-1', prompt="cute baby otter") |
os.environ['OPENAI_API_KEY'] |
| dall-e-3 | image_generation(model='dall-e-3', prompt="cute baby otter") |
os.environ['OPENAI_API_KEY'] |
| dall-e-2 | image_generation(model='dall-e-2', prompt="cute baby otter") |
os.environ['OPENAI_API_KEY'] |
Azure OpenAI Image Generation Models
API keys
This can be set as env variables or passed as params to litellm.image_generation()
import os
os.environ['AZURE_API_KEY'] =
os.environ['AZURE_API_BASE'] =
os.environ['AZURE_API_VERSION'] =
Usage
from litellm import embedding
response = embedding(
model="azure/<your deployment name>",
prompt="cute baby otter",
api_key=api_key,
api_base=api_base,
api_version=api_version,
)
print(response)
| Model Name | Function Call |
|---|---|
| gpt-image-1 | image_generation(model="azure/<your deployment name>", prompt="cute baby otter") |
| dall-e-3 | image_generation(model="azure/<your deployment name>", prompt="cute baby otter") |
| dall-e-2 | image_generation(model="azure/<your deployment name>", prompt="cute baby otter") |
Xinference Image Generation Models
Use this for Stable Diffusion models hosted on Xinference
Usage
See Xinference usage with LiteLLM here
Recraft Image Generation Models
Use this for AI-powered design and image generation with Recraft
Usage
from litellm import image_generation
import os
os.environ['RECRAFT_API_KEY'] = "your-api-key"
response = image_generation(
model="recraft/recraftv3",
prompt="A beautiful sunset over a calm ocean",
)
print(response)
See Recraft usage with LiteLLM here
OpenAI Compatible Image Generation Models
Use this for calling /image_generation endpoints on OpenAI Compatible Servers, example https://github.com/xorbitsai/inference
Note add openai/ prefix to model so litellm knows to route to OpenAI
Usage
from litellm import image_generation
response = image_generation(
model = "openai/<your-llm-name>", # add `openai/` prefix to model so litellm knows to route to OpenAI
api_base="http://0.0.0.0:8000/" # set API Base of your Custom OpenAI Endpoint
prompt="cute baby otter"
)
Bedrock - Stable Diffusion
Use this for stable diffusion on bedrock
Usage
import os
from litellm import image_generation
os.environ["AWS_ACCESS_KEY_ID"] = ""
os.environ["AWS_SECRET_ACCESS_KEY"] = ""
os.environ["AWS_REGION_NAME"] = ""
response = image_generation(
prompt="A cute baby sea otter",
model="bedrock/stability.stable-diffusion-xl-v0",
)
print(f"response: {response}")
VertexAI - Image Generation Models
Usage
Use this for image generation models on VertexAI
response = litellm.image_generation(
prompt="An olympic size swimming pool",
model="vertex_ai/imagegeneration@006",
vertex_ai_project="adroit-crow-413218",
vertex_ai_location="us-central1",
)
print(f"response: {response}")
Supported Providers
⚡️See all supported models and providers at models.litellm.ai
| Provider | Documentation Link |
|---|---|
| OpenAI | OpenAI Image Generation → |
| Azure OpenAI | Azure OpenAI Image Generation → |
| Google AI Studio | Google AI Studio Image Generation → |
| Vertex AI | Vertex AI Image Generation → |
| AWS Bedrock | Bedrock Image Generation → |
| Recraft | Recraft Image Generation → |
| Xinference | Xinference Image Generation → |
| Nscale | Nscale Image Generation → |