Files
openclaw/extensions/litellm/index.ts
Chris Zhang c3bfd328ad feat(litellm): add image generation provider (#70246)
* feat(litellm): add image generation provider

Registers litellm as an image-generation provider so model refs like
litellm/gpt-image-2 route through the LiteLLM proxy, and
agents.defaults.imageGenerationModel.fallbacks entries of the form
litellm/... resolve without "No image-generation provider registered
for litellm" errors.

Implementation uses the OpenAI-compatible /images/generations and
/images/edits endpoints that LiteLLM proxies for. BaseUrl resolves from
models.providers.litellm.baseUrl (default http://localhost:4000). Private
network is auto-allowed when baseUrl is a loopback/RFC1918 address, which
covers the common self-hosted LiteLLM proxy case without needing
OPENCLAW_PROVIDER_ALLOW_PRIVATE_NETWORK. Public baseUrls keep normal SSRF
defaults.

Default model is gpt-image-2 (matching upstream 4.21+ OpenAI default).
Advertises the same 2K/4K sizes OpenAI now exposes, plus legacy
256/512/1024 for dall-e-3. Supports both generate and edit.

Local patch. LiteLLM has no upstream image-generation support yet; revisit
if upstream adds one.

* ci: rerun after upstream main hot-fix

* fix(litellm): harden image generation provider

---------

Co-authored-by: Chris Zhang <chris@ChrisdeMac-mini.local>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-04-25 19:06:51 +01:00

46 lines
1.5 KiB
TypeScript

import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
import { buildLitellmImageGenerationProvider } from "./image-generation-provider.js";
import { applyLitellmConfig, LITELLM_DEFAULT_MODEL_REF } from "./onboard.js";
import { buildLitellmProvider } from "./provider-catalog.js";
const PROVIDER_ID = "litellm";
export default defineSingleProviderPluginEntry({
id: PROVIDER_ID,
name: "LiteLLM Provider",
description: "Bundled LiteLLM provider plugin",
provider: {
label: "LiteLLM",
docsPath: "/providers/litellm",
auth: [
{
methodId: "api-key",
label: "LiteLLM API key",
hint: "Unified gateway for 100+ LLM providers",
optionKey: "litellmApiKey",
flagName: "--litellm-api-key",
envVar: "LITELLM_API_KEY",
promptMessage: "Enter LiteLLM API key",
defaultModel: LITELLM_DEFAULT_MODEL_REF,
applyConfig: (cfg) => applyLitellmConfig(cfg),
noteTitle: "LiteLLM",
noteMessage: [
"LiteLLM provides a unified API to 100+ LLM providers.",
"Get your API key from your LiteLLM proxy or https://litellm.ai",
"Default proxy runs on http://localhost:4000",
].join("\n"),
wizard: {
groupHint: "Unified LLM gateway (100+ providers)",
},
},
],
catalog: {
buildProvider: buildLitellmProvider,
allowExplicitBaseUrl: true,
},
},
register(api) {
api.registerImageGenerationProvider(buildLitellmImageGenerationProvider());
},
});